diff --git a/dist/jssip.js b/dist/jssip.js index e437f2e67..84d23e1f4 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -298,7 +298,7 @@ exports.load = function (dst, src) { } } }; -},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":22,"./URI":27,"./Utils":28}],2:[function(require,module,exports){ +},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":23,"./URI":29,"./Utils":30}],2:[function(require,module,exports){ "use strict"; var pkg = require('../package.json'); @@ -464,7 +464,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, @@ -472,7 +472,7 @@ module.exports = { CONNECTION_RECOVERY_MAX_INTERVAL: 30, CONNECTION_RECOVERY_MIN_INTERVAL: 2 }; -},{"../package.json":40}],3:[function(require,module,exports){ +},{"../package.json":42}],3:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } @@ -736,7 +736,7 @@ module.exports = /*#__PURE__*/function () { } }]); }(); -},{"./Constants":2,"./Dialog/RequestSender":4,"./Logger":9,"./SIPMessage":21,"./Transactions":24,"./Utils":28}],4:[function(require,module,exports){ +},{"./Constants":2,"./Dialog/RequestSender":4,"./Logger":9,"./SIPMessage":22,"./Transactions":26,"./Utils":30}],4:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } @@ -847,7 +847,7 @@ module.exports = /*#__PURE__*/function () { } }]); }(); -},{"../Constants":2,"../RequestSender":20,"../Transactions":24}],5:[function(require,module,exports){ +},{"../Constants":2,"../RequestSender":21,"../Transactions":26}],5:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } @@ -1040,7 +1040,7 @@ module.exports = /*#__PURE__*/function () { } }]); }(); -},{"./Logger":9,"./Utils":28}],6:[function(require,module,exports){ +},{"./Logger":9,"./Utils":30}],6:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } @@ -13528,7 +13528,7 @@ module.exports = function () { result.SyntaxError.prototype = Error.prototype; return result; }(); -},{"./NameAddrHeader":11,"./URI":27}],8:[function(require,module,exports){ +},{"./NameAddrHeader":11,"./URI":29}],8:[function(require,module,exports){ "use strict"; var pkg = require('../package.json'); @@ -13566,7 +13566,7 @@ module.exports = { return pkg.version; } }; -},{"../package.json":40,"./Constants":2,"./Exceptions":6,"./Grammar":7,"./NameAddrHeader":11,"./RTCSession":14,"./UA":26,"./URI":27,"./Utils":28,"./WebSocketInterface":29,"debug":32}],9:[function(require,module,exports){ +},{"../package.json":42,"./Constants":2,"./Exceptions":6,"./Grammar":7,"./NameAddrHeader":11,"./RTCSession":15,"./UA":28,"./URI":29,"./Utils":30,"./WebSocketInterface":31,"debug":34}],9:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } @@ -13612,7 +13612,7 @@ module.exports = /*#__PURE__*/function () { } }]); }(); -},{"debug":32}],10:[function(require,module,exports){ +},{"debug":34}],10:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } @@ -13874,7 +13874,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } }]); }(EventEmitter); -},{"./Constants":2,"./Exceptions":6,"./Logger":9,"./RequestSender":20,"./SIPMessage":21,"./URI":27,"./Utils":28,"events":31}],11:[function(require,module,exports){ +},{"./Constants":2,"./Exceptions":6,"./Logger":9,"./RequestSender":21,"./SIPMessage":22,"./URI":29,"./Utils":30,"events":33}],11:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } @@ -13994,7 +13994,373 @@ module.exports = /*#__PURE__*/function () { } }]); }(); -},{"./Grammar":7,"./URI":27}],12:[function(require,module,exports){ +},{"./Grammar":7,"./URI":29}],12:[function(require,module,exports){ +"use strict"; + +function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } +function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, 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 o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; } +function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } +function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } +function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } +function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } +function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } +function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } +function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } +function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } +function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); } +function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; } +function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } +function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); } +function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); } +function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); } +var EventEmitter = require('events').EventEmitter; +var Logger = require('./Logger'); +var JsSIP_C = require('./Constants'); +var Utils = require('./Utils'); +var Dialog = require('./Dialog'); +var logger = new Logger('Notifier'); + +/** + * 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) { + /** + * @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); + logger.debug('new'); + _this = _callSuper(this, Notifier); + if (!subscribe) { + 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'); + } + _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; + + // 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: ".concat(_this._ua._contact.toString()); + _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(_this, subscribe, 'UAS'); + _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). + */ + _inherits(Notifier, _EventEmitter); + return _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; + } + 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: ".concat(this._expires)); + } + 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(); + } + logger.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() { + logger.debug('start()'); + this.receiveRequest(this._initial_subscribe); + } + + /** + * Switch pending dialog state to active. + */ + }, { + key: "setActiveState", + value: function setActiveState() { + logger.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 body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; + logger.debug('notify()'); + if (this._state === C.STATE_TERMINATED) { + throw new Error('Cannot send notify in terminated state.'); + } + var expires = Math.floor((this._expires_timestamp - new Date().getTime()) / 1000); + if (expires < 0) { + expires = 0; + } + this._notify([";expires=".concat(expires)], body); + } + + /** + * @param {Array} subsStateParams subscription state parameters. + * @param {String} body Notify body + * @param {Array} extraHeaders + */ + }, { + key: "_notify", + value: function _notify(subsStateParameters) { + var _this2 = this; + var body = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + var extraHeaders = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; + // Prevent send notify after final notify. + if (!this._dialog) { + logger.warn('final notify has sent'); + return; + } + + // Build Subscription-State header with parameters. + var subsState = "Subscription-State: ".concat(this._stateToString()); + var _iterator = _createForOfIteratorHelper(subsStateParameters), + _step; + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var param = _step.value; + subsState += param; + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + var headers = this._headers.slice(); + headers.push(subsState); + if (extraHeaders) { + headers = headers.concat(extraHeaders); + } + 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; + logger.debug('terminate()'); + this._state = C.STATE_TERMINATED; + var subsStateParameters = []; + if (reason) { + subsStateParameters.push(";reason=".concat(reason)); + } + if (retryAfter !== null) { + subsStateParameters.push(";retry-after=".concat(retryAfter)); + } + this._notify(subsStateParameters, body); + this._dialogTerminated(reason === 'timeout' ? C.SUBSCRIPTION_EXPIRED : 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; + } + + // For SUBSCRIPTION_EXPIRED the 'terminated' event was fired in expiration timer + if (termination_code !== C.SUBSCRIPTION_EXPIRED) { + logger.debug("emit \"terminated\" code=".concat(termination_code, ", send final notify=false")); + this.emit('terminated', termination_code, false); + } + } + }, { + 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; + } + logger.debug("emit \"terminated\" code=".concat(C.SUBSCRIPTION_EXPIRED, ", send final notify=true")); + _this3.emit('terminated', C.SUBSCRIPTION_EXPIRED, true); + }, this._expires * 1000); + } + }, { + key: "_stateToString", + value: function _stateToString() { + switch (this._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; + } + }]); +}(EventEmitter); +},{"./Constants":2,"./Dialog":3,"./Logger":9,"./Utils":30,"events":33}],13:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } @@ -14247,7 +14613,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } }]); }(EventEmitter); -},{"./Constants":2,"./Exceptions":6,"./Logger":9,"./RequestSender":20,"./SIPMessage":21,"./Utils":28,"events":31}],13:[function(require,module,exports){ +},{"./Constants":2,"./Exceptions":6,"./Logger":9,"./RequestSender":21,"./SIPMessage":22,"./Utils":30,"events":33}],14:[function(require,module,exports){ "use strict"; function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, 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 o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; } @@ -14522,7 +14888,7 @@ function parseHeader(message, data, headerStart, headerEnd) { return true; } } -},{"./Grammar":7,"./Logger":9,"./SIPMessage":21}],14:[function(require,module,exports){ +},{"./Grammar":7,"./Logger":9,"./SIPMessage":22}],15:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } @@ -17502,7 +17868,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } }]); }(EventEmitter); -},{"./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){ +},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./Logger":9,"./RTCSession/DTMF":16,"./RTCSession/Info":17,"./RTCSession/ReferNotifier":18,"./RTCSession/ReferSubscriber":19,"./RequestSender":21,"./SIPMessage":22,"./Timers":25,"./Transactions":26,"./URI":29,"./Utils":30,"events":33,"sdp-transform":39}],16:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } @@ -17669,7 +18035,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { * Expose C object. */ module.exports.C = C; -},{"../Constants":2,"../Exceptions":6,"../Logger":9,"../Utils":28,"events":31}],16:[function(require,module,exports){ +},{"../Constants":2,"../Exceptions":6,"../Logger":9,"../Utils":30,"events":33}],17:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } @@ -17778,7 +18144,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } }]); }(EventEmitter); -},{"../Constants":2,"../Exceptions":6,"../Utils":28,"events":31}],17:[function(require,module,exports){ +},{"../Constants":2,"../Exceptions":6,"../Utils":30,"events":33}],18:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } @@ -17835,7 +18201,7 @@ module.exports = /*#__PURE__*/function () { } }]); }(); -},{"../Constants":2,"../Logger":9}],18:[function(require,module,exports){ +},{"../Constants":2,"../Logger":9}],19:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } @@ -17991,7 +18357,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } }]); }(EventEmitter); -},{"../Constants":2,"../Grammar":7,"../Logger":9,"../Utils":28,"events":31}],19:[function(require,module,exports){ +},{"../Constants":2,"../Grammar":7,"../Logger":9,"../Utils":30,"events":33}],20:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } @@ -18335,7 +18701,7 @@ module.exports = /*#__PURE__*/function () { } }]); }(); -},{"./Constants":2,"./Logger":9,"./RequestSender":20,"./SIPMessage":21,"./Utils":28}],20:[function(require,module,exports){ +},{"./Constants":2,"./Logger":9,"./RequestSender":21,"./SIPMessage":22,"./Utils":30}],21:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } @@ -18487,7 +18853,7 @@ module.exports = /*#__PURE__*/function () { } }]); }(); -},{"./Constants":2,"./DigestAuthentication":5,"./Logger":9,"./Transactions":24}],21:[function(require,module,exports){ +},{"./Constants":2,"./DigestAuthentication":5,"./Logger":9,"./Transactions":26}],22:[function(require,module,exports){ "use strict"; function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } @@ -19250,7 +19616,7 @@ module.exports = { IncomingRequest: IncomingRequest, IncomingResponse: IncomingResponse }; -},{"./Constants":2,"./Grammar":7,"./Logger":9,"./NameAddrHeader":11,"./Utils":28,"sdp-transform":37}],22:[function(require,module,exports){ +},{"./Constants":2,"./Grammar":7,"./Logger":9,"./NameAddrHeader":11,"./Utils":30,"sdp-transform":39}],23:[function(require,module,exports){ "use strict"; var Logger = require('./Logger'); @@ -19318,7 +19684,537 @@ exports.isSocket = function (socket) { } return true; }; -},{"./Grammar":7,"./Logger":9,"./Utils":28}],23:[function(require,module,exports){ +},{"./Grammar":7,"./Logger":9,"./Utils":30}],24:[function(require,module,exports){ +"use strict"; + +function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } +function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, 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 o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; } +function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } +function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } +function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } +function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } +function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } +function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } +function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } +function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } +function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); } +function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; } +function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } +function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); } +function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); } +function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); } +var EventEmitter = require('events').EventEmitter; +var Logger = require('./Logger'); +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 logger = new Logger('Subscriber'); + +/** + * 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) { + /** + * @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); + logger.debug('new'); + _this = _callSuper(this, Subscriber); + + // 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 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. + _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: ".concat(_this._ua._contact.toString()); + _this._headers.push(contact); + } + if (allowEvents) { + _this._headers.push("Allow-Events: ".concat(allowEvents)); + } + + // To enqueue subscribes created before receive initial subscribe OK. + _this._queue = []; + return _this; + } + _inherits(Subscriber, _EventEmitter); + return _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) { + logger.warn('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) { + logger.warn('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) { + logger.warn('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) { + logger.warn('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) { + logger.debug('update sending re-SUBSCRIBE time'); + this._scheduleSubscribe(expires); + } + } + } + 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) { + logger.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'); + logger.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; + logger.debug('subscribe()'); + if (this._state === C.STATE_INIT) { + 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; + logger.debug('terminate()'); + + // Prevent duplication un-subscribe sending. + if (this._terminated) { + return; + } + this._terminated = true; + + // Set header Expires: 0. + var headers = this._headers.map(function (header) { + return header.startsWith('Expires') ? 'Expires: 0' : header; + }); + if (this._state === C.STATE_INIT) { + // 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; + } + + /** + * 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)); + } + this._state = C.STATE_NOTIFY_WAIT; + 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'); + if (dialog.error) { + // OK response without Contact + logger.warn(dialog.error); + this._dialogTerminated(C.SUBSCRIBE_BAD_OK_RESPONSE); + return; + } + this._dialog = dialog; + logger.debug('emit "accepted"'); + this.emit('accepted'); + + // Subsequent subscribes saved in the queue until dialog created. + var _iterator = _createForOfIteratorHelper(this._queue), + _step; + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var subscribe = _step.value; + logger.debug('dequeue subscribe'); + this._sendSubsequentSubscribe(subscribe.body, subscribe.headers); + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + } + + // Check expires value. + var expires_value = response.getHeader('expires'); + if (expires_value !== 0 && !expires_value) { + logger.warn('response without Expires header'); + + // RFC 6665 3.1.1 subscribe OK response 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) { + var _this4 = this; + if (this._state === C.STATE_TERMINATED) { + return; + } + if (!this._dialog) { + logger.debug('enqueue subscribe'); + this._queue.push({ + body: body, + headers: headers.slice() + }); + return; + } + 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, + 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._state === C.STATE_TERMINATED) { + return; + } + this._state = C.STATE_TERMINATED; + + // Clear timers. + clearTimeout(this._expires_timer); + clearTimeout(this._unsubscribe_timeout_timer); + if (this._dialog) { + this._dialog.terminate(); + this._dialog = null; + } + logger.debug("emit \"terminated\" code=".concat(terminationCode)); + this.emit('terminated', terminationCode, reason, retryAfter); + } + }, { + key: "_scheduleSubscribe", + value: function _scheduleSubscribe(expires) { + var _this5 = this; + /* + 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, + 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. + */ + + 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; + logger.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); + } + }, { + 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: + /** + * Expose C object. + */ + function get() { + return C; + } + }]); +}(EventEmitter); +},{"./Constants":2,"./Dialog":3,"./Grammar":7,"./Logger":9,"./RequestSender":21,"./SIPMessage":22,"./Utils":30,"events":33}],25:[function(require,module,exports){ "use strict"; var T1 = 500, @@ -19339,7 +20235,7 @@ module.exports = { TIMER_M: 64 * T1, PROVISIONAL_RESPONSE_INTERVAL: 60000 // See RFC 3261 Section 13.3.1.1 }; -},{}],24:[function(require,module,exports){ +},{}],26:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } @@ -20039,7 +20935,7 @@ module.exports = { InviteServerTransaction: InviteServerTransaction, checkTransaction: checkTransaction }; -},{"./Constants":2,"./Logger":9,"./SIPMessage":21,"./Timers":23,"events":31}],25:[function(require,module,exports){ +},{"./Constants":2,"./Logger":9,"./SIPMessage":22,"./Timers":25,"events":33}],27:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } @@ -20361,7 +21257,7 @@ module.exports = /*#__PURE__*/function () { } }]); }(); -},{"./Constants":2,"./Logger":9,"./Socket":22}],26:[function(require,module,exports){ +},{"./Constants":2,"./Logger":9,"./Socket":23}],28:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } @@ -20382,6 +21278,8 @@ 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'); @@ -20611,6 +21509,26 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return message; } + /** + * Create subscriber instance + */ + }, { + key: "subscribe", + value: function subscribe(target, eventName, accept, options) { + logger.debug('subscribe()'); + return new Subscriber(this, target, eventName, accept, options); + } + + /** + * Create notifier instance + */ + }, { + key: "notify", + value: function notify(subscribe, contentType, options) { + logger.debug('notify()'); + return new Notifier(this, subscribe, contentType, options); + } + /** * Send a SIP OPTIONS. * @@ -20962,6 +21880,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) { @@ -21026,6 +21949,12 @@ 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; @@ -21342,7 +22271,7 @@ function onTransportData(data) { } } } -},{"./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){ +},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Logger":9,"./Message":10,"./Notifier":12,"./Options":13,"./Parser":14,"./RTCSession":15,"./Registrator":20,"./SIPMessage":22,"./Subscriber":24,"./Transactions":26,"./Transport":27,"./URI":29,"./Utils":30,"./sanityCheck":32,"events":33}],29:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } @@ -21573,7 +22502,7 @@ module.exports = /*#__PURE__*/function () { } }]); }(); -},{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[function(require,module,exports){ +},{"./Constants":2,"./Grammar":7,"./Utils":30}],30:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } @@ -22038,7 +22967,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":29}],31:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } @@ -22186,7 +23115,7 @@ module.exports = /*#__PURE__*/function () { } }]); }(); -},{"./Grammar":7,"./Logger":9}],30:[function(require,module,exports){ +},{"./Grammar":7,"./Logger":9}],32:[function(require,module,exports){ "use strict"; function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, 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 o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; } @@ -22395,7 +23324,7 @@ function reply(status_code) { response += '\r\n'; transport.send(response); } -},{"./Constants":2,"./Logger":9,"./SIPMessage":21,"./Utils":28}],31:[function(require,module,exports){ +},{"./Constants":2,"./Logger":9,"./SIPMessage":22,"./Utils":30}],33:[function(require,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -22920,7 +23849,7 @@ function functionBindPolyfill(context) { }; } -},{}],32:[function(require,module,exports){ +},{}],34:[function(require,module,exports){ (function (process){(function (){ /* eslint-env browser */ @@ -23196,7 +24125,7 @@ formatters.j = function (v) { }; }).call(this)}).call(this,require('_process')) -},{"./common":33,"_process":35}],33:[function(require,module,exports){ +},{"./common":35,"_process":37}],35:[function(require,module,exports){ /** * This is the common logic for both the Node.js and web browser @@ -23490,7 +24419,7 @@ function setup(env) { module.exports = setup; -},{"ms":34}],34:[function(require,module,exports){ +},{"ms":36}],36:[function(require,module,exports){ /** * Helpers. */ @@ -23654,7 +24583,7 @@ function plural(ms, msAbs, n, name) { return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : ''); } -},{}],35:[function(require,module,exports){ +},{}],37:[function(require,module,exports){ // shim for using process in browser var process = module.exports = {}; @@ -23840,7 +24769,7 @@ process.chdir = function (dir) { }; process.umask = function() { return 0; }; -},{}],36:[function(require,module,exports){ +},{}],38:[function(require,module,exports){ var grammar = module.exports = { v: [{ name: 'version', @@ -24336,7 +25265,7 @@ Object.keys(grammar).forEach(function (key) { }); }); -},{}],37:[function(require,module,exports){ +},{}],39:[function(require,module,exports){ var parser = require('./parser'); var writer = require('./writer'); var grammar = require('./grammar'); @@ -24351,7 +25280,7 @@ exports.parseRemoteCandidates = parser.parseRemoteCandidates; exports.parseImageAttributes = parser.parseImageAttributes; exports.parseSimulcastStreamList = parser.parseSimulcastStreamList; -},{"./grammar":36,"./parser":38,"./writer":39}],38:[function(require,module,exports){ +},{"./grammar":38,"./parser":40,"./writer":41}],40:[function(require,module,exports){ var toIntIfInt = function (v) { return String(Number(v)) === v ? Number(v) : v; }; @@ -24477,7 +25406,7 @@ exports.parseSimulcastStreamList = function (str) { }); }; -},{"./grammar":36}],39:[function(require,module,exports){ +},{"./grammar":38}],41:[function(require,module,exports){ var grammar = require('./grammar'); // customized util.format - discards excess arguments and can void middle ones @@ -24593,7 +25522,7 @@ module.exports = function (session, opts) { return sdp.join('\r\n') + '\r\n'; }; -},{"./grammar":36}],40:[function(require,module,exports){ +},{"./grammar":38}],42:[function(require,module,exports){ module.exports={ "name": "jssip", "title": "JsSIP", diff --git a/dist/jssip.min.js b/dist/jssip.min.js index 17bdd95ff..8720bb627 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 o(s,l){if(!n[s]){if(!t[s]){var u="function"==typeof require&&require;if(!l&&u)return u(s,!0);if(i)return i(s,!0);var a=new Error("Cannot find module '"+s+"'");throw a.code="MODULE_NOT_FOUND",a}var c=n[s]={exports:{}};t[s][0].call(c.exports,function(e){return o(t[s][1][e]||e)},c,c.exports,e,t,n,r)}return n[s].exports}for(var i="function"==typeof require&&require,s=0;s=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,l=!0,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,s=e},f:function(){try{l||null==n.return||n.return()}finally{if(u)throw s}}}}function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=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())===s.INVITE||e===s.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}},register_from_tag_trail:function(e){return"function"==typeof e?e:String(e)},registrar_server:function(e){/^sip:/i.test(e)||(e="".concat(s.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,o=r(e);try{for(o.s();!(n=o.n()).done;){var i=n.value;"string"==typeof i&&t.push(i)}}catch(e){o.e(e)}finally{o.f()}return t}}}};n.load=function(e,t){for(var n in f.mandatory){if(!t.hasOwnProperty(n))throw new c.ConfigurationError(n);var r=t[n],o=f.mandatory[n](r);if(void 0===o)throw new c.ConfigurationError(n,r);e[n]=o}for(var s in f.optional)if(t.hasOwnProperty(s)){var l=t[s];if(i.isEmpty(l))continue;var u=f.optional[s](l);if(void 0===u)throw new c.ConfigurationError(s,l);e[s]=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){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function o(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 l.IncomingResponse&&(o=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=o,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=o,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"))},n=[{key:"C",get:function(){return d}}],(t=[{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:"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=f.cloneArray(n.extraHeaders),o=f.cloneObject(n.eventHandlers),i=n.body||null,s=this._createRequest(e,r,i);return o.onAuthenticated=function(){t._local_seqnum+=1},new c(this,s,o).send(),s}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===u.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===u.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=f.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===u.CANCEL||e===u.ACK?this._local_seqnum:this._local_seqnum+=1;return new l.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===u.INVITE||e.method===u.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;var r=function(){e.server_transaction.state!==a.C.STATUS_ACCEPTED&&e.server_transaction.state!==a.C.STATUS_COMPLETED&&e.server_transaction.state!==a.C.STATUS_TERMINATED||(e.server_transaction.removeListener("stateChanged",r),t._uas_pending_reply=!1)};e.server_transaction.on("stateChanged",r)}e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===a.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===u.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===a.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&o(e.prototype,t),n&&o(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n}()},{"./Constants":2,"./Dialog/RequestSender":4,"./Logger":9,"./SIPMessage":21,"./Transactions":24,"./Utils":28}],4:[function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function o(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)}}])&&o(e.prototype,t),n&&o(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n}()},{"../Constants":2,"../RequestSender":20,"../Transactions":24}],5:[function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function o(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 u.warn('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'),!1}else this._algorithm="MD5";if(!this._nonce)return u.warn("authenticate() | challenge without Digest nonce, authentication aborted"),!1;if(!this._realm)return u.warn("authenticate() | challenge without Digest realm, authentication aborted"),!1;if(!this._credentials.password){if(!this._credentials.ha1)return u.warn("authenticate() | no plain SIP password nor ha1 provided, authentication aborted"),!1;if(this._credentials.realm!==this._realm)return u.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 u.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=i||l.createRandomToken(12),this._nc+=1;var s,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=l.calculateMD5("".concat(this._credentials.username,":").concat(this._realm,":").concat(this._credentials.password)):this._ha1=this._credentials.ha1,"auth"===this._qop?(s="".concat(this._method,":").concat(this._uri),a=l.calculateMD5(s),u.debug('authenticate() | using qop=auth [a2:"%s"]',s),this._response=l.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(a))):"auth-int"===this._qop?(s="".concat(this._method,":").concat(this._uri,":").concat(l.calculateMD5(o||"")),a=l.calculateMD5(s),u.debug('authenticate() | using qop=auth-int [a2:"%s"]',s),this._response=l.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(a))):null===this._qop&&(s="".concat(this._method,":").concat(this._uri),a=l.calculateMD5(s),u.debug('authenticate() | using qop=null [a2:"%s"]',s),this._response=l.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(a))),u.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(", "))}}])&&o(e.prototype,t),n&&o(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n}()},{"./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 o(e,t){for(var n=0;n",i++):(e=null,0===s&&a('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===s&&a('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===s&&a('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===s&&a('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===s&&a('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===s&&a('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===s&&a('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===s&&a('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===s&&a('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===s&&a('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===s&&a('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===s&&a('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===s&&a('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:U,STAR:D,SLASH:x,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:j,COMMA:F,SEMI:G,COLON:B,LDQUOT:W,RDQUOT:V,comment:function e(){var t,n,r;var o;o=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=o)}else t=null,i=o;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:oe,password:ie,hostport:se,host:le,hostname:ue,domainlabel:ae,toplabel:ce,IPv6reference:fe,IPv6address:he,h16:de,ls32:_e,IPv4address:pe,dec_octet:me,port:ve,uri_parameters:ge,uri_parameter:ye,transport_param:Te,user_param:be,method_param:Se,ttl_param:Ce,maddr_param:Ee,lr_param:Ae,other_param:we,pname:Re,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Pe,hname:Ue,hvalue:De,hnv_unreserved:xe,Request_Response:function(){var e;null===(e=ft())&&(e=Me());return e},Request_Line:Me,Request_URI:qe,absoluteURI:Le,hier_part:He,net_path:je,abs_path:Fe,opaque_part:Ge,uric:Be,uric_no_slash:We,path_segments:Ve,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:ot,CANCELm:it,REGISTERm:st,SUBSCRIBEm:lt,NOTIFYm:ut,REFERm:at,Method:ct,Status_Line:ft,Status_Code:ht,extension_code:dt,Reason_Phrase:_t,Allow_Events:function(){var e,t,n,r,o,s;if(o=i,null!==(e=Lt())){for(t=[],s=i,null!==(n=F())&&null!==(r=Lt())?n=[n,r]:(n=null,i=s);null!==n;)t.push(n),s=i,null!==(n=F())&&null!==(r=Lt())?n=[n,r]:(n=null,i=s);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;return e},Call_ID:function(){var e,t,r,o,l,u;o=i,l=i,null!==(e=U())?(u=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===s&&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=o,e=void(Fn=n.substring(i,c)));var c;null===e&&(i=o);return e},Contact:function(){var e,t,n,r,o,s,l;if(o=i,null===(e=D()))if(s=i,null!==(e=pt())){for(t=[],l=i,null!==(n=F())&&null!==(r=pt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=F())&&null!==(r=pt())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;null!==e&&(e=function(e){var t,n;for(n=Fn.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===s&&a('"\\r\\n"')),e}function f(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===s&&a("[0-9]")),e}function h(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===s&&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===s&&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===s&&a("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===s&&a('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===s&&a('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===s&&a('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===s&&a("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===s&&a('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===s&&a('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===s&&a('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===s&&a('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===s&&a('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===s&&a('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===s&&a('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===s&&a('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===s&&a('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===s&&a('","'))))))))))),e}function b(){var e;return null===(e=y())&&(e=S()),e}function S(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===s&&a('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===s&&a('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===s&&a('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===s&&a('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===s&&a('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===s&&a('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===s&&a('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===s&&a('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===s&&a('")"')))))))))),e}function C(){var e,t,r,o,l;return o=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===s&&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=o),e}function E(){var e,t,n,r,o,s;for(r=i,o=i,s=i,e=[],t=_();null!==t;)e.push(t),t=_();if(null!==e&&null!==(t=c())?e=[e,t]:(e=null,i=s),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=o)}else e=null,i=o;return null!==e&&(e=" "),null===e&&(i=r),e}function A(){var e;return e=null!==(e=E())?e:""}function w(){var e,t,r,o,l;for(o=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===s&&a('":"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=":"),null===e&&(i=o),e}function R(){var e,t,r,o,s,l,u,a;if(s=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=[],o=E();null!==o;)r.push(o),o=E();for(null!==r&&null!==(o=I())?r=[r,o]:(r=null,i=u);null!==r;){for(t.push(r),u=i,r=[],o=E();null!==o;)r.push(o),o=E();null!==r&&null!==(o=I())?r=[r,o]:(r=null,i=u)}null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=s,e=n.substring(i,a)),null===e&&(i=s),e}function I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===s&&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===s&&a("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===s&&a("[\\x80-\\xBF]")),e}function k(){var e,t,r,o;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===s&&a('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===s&&a('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===s&&a('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===s&&a('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===s&&a('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===s&&a('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===s&&a('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===s&&a('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===s&&a('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===s&&a('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===s&&a('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===s&&a('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===s&&a('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===s&&a('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===s&&a('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===s&&a('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===s&&a('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===s&&a('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===s&&a('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===s&&a('"~"'))))))))))));else e=null;return null!==e&&(o=r,e=n.substring(i,o)),null===e&&(i=r),e}function P(){var e,t,r,o;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===s&&a('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===s&&a('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===s&&a('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===s&&a('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===s&&a('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===s&&a('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===s&&a('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===s&&a('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===s&&a('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===s&&a('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===s&&a('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===s&&a('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===s&&a('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===s&&a('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===s&&a('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===s&&a('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===s&&a('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===s&&a('"~"')))))))))));else e=null;return null!==e&&(o=r,e=n.substring(i,o)),null===e&&(i=r),e}function U(){var e,t,r,o;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===s&&a('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===s&&a('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===s&&a('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===s&&a('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===s&&a('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===s&&a('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===s&&a('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===s&&a('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===s&&a('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===s&&a('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===s&&a('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===s&&a('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===s&&a('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===s&&a('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===s&&a('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===s&&a('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===s&&a('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===s&&a('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===s&&a('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===s&&a('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===s&&a('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===s&&a('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===s&&a('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===s&&a('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===s&&a('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===s&&a('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===s&&a('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===s&&a('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===s&&a('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===s&&a('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===s&&a('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===s&&a('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===s&&a('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===s&&a('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===s&&a('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===s&&a('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===s&&a('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===s&&a('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===s&&a('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===s&&a('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===s&&a('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===s&&a('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===s&&a('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===s&&a('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(o=r,e=n.substring(i,o)),null===e&&(i=r),e}function D(){var e,t,r,o,l;return o=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===s&&a('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=o),e}function x(){var e,t,r,o,l;return o=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===s&&a('"/"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="/"),null===e&&(i=o),e}function M(){var e,t,r,o,l;return o=i,l=i,null!==(e=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===s&&a('"="')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="="),null===e&&(i=o),e}function q(){var e,t,r,o,l;return o=i,l=i,null!==(e=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===s&&a('"("')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="("),null===e&&(i=o),e}function L(){var e,t,r,o,l;return o=i,l=i,null!==(e=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===s&&a('")"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=")"),null===e&&(i=o),e}function H(){var e,t,r,o;return r=i,o=i,62===n.charCodeAt(i)?(e=">",i++):(e=null,0===s&&a('">"')),null!==e&&null!==(t=A())?e=[e,t]:(e=null,i=o),null!==e&&(e=">"),null===e&&(i=r),e}function j(){var e,t,r,o;return r=i,o=i,null!==(e=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===s&&a('"<"')),null!==t?e=[e,t]:(e=null,i=o)):(e=null,i=o),null!==e&&(e="<"),null===e&&(i=r),e}function F(){var e,t,r,o,l;return o=i,l=i,null!==(e=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===s&&a('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=o),e}function G(){var e,t,r,o,l;return o=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===s&&a('";"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=";"),null===e&&(i=o),e}function B(){var e,t,r,o,l;return o=i,l=i,null!==(e=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===s&&a('":"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=":"),null===e&&(i=o),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===s&&a("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===s&&a("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===s&&a("[\\]-~]")),null===e&&null===(e=O())&&(e=E()))),e}function z(){var e,t,r,o,s,l,u;if(s=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(o=$())&&(o=X());null!==o;)r.push(o),null===(o=$())&&(o=X());null!==r&&null!==(o=m())?e=[e,t,r,o]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;return null!==e&&(u=s,e=n.substring(i,u)),null===e&&(i=s),e}function Y(){var e,t,r,o,s,l,u,a;if(s=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(o=$())&&(o=X());null!==o;)r.push(o),null===(o=$())&&(o=X());null!==r&&null!==(o=m())?e=[e,t,r,o]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;return null!==e&&(u=s,e=(a=n.substring(i,u).trim()).substring(1,a.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=s),e}function $(){var e;return null===(e=E())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===s&&a('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===s&&a("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===s&&a("[\\]-~]")),null===e&&(e=O())))),e}function X(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===s&&a('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===s&&a("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===s&&a("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===s&&a("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function J(){var e,t,r,o,l,u;return l=i,u=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===s&&a('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(o=se())?e=[e,t,r,o]:(e=null,i=u)):(e=null,i=u),null!==e&&(e=function(e){try{Fn.uri=new Hn(Fn.scheme,Fn.user,Fn.host,Fn.port),delete Fn.scheme,delete Fn.user,delete Fn.host,delete Fn.host_type,delete Fn.port}catch(e){Fn=-1}}()),null===e&&(i=l),e}function Q(){var e,t,o,l,u,c,f,h;return f=i,h=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===s&&a('":"')),null!==t&&null!==(o=null!==(o=ne())?o:"")&&null!==(l=se())&&null!==(u=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,o,l,u,c]:(e=null,i=h)):(e=null,i=h),null!==e&&(e=function(e){try{Fn.uri=new Hn(Fn.scheme,Fn.user,Fn.host,Fn.port,Fn.uri_params,Fn.uri_headers),delete Fn.scheme,delete Fn.user,delete Fn.host,delete Fn.host_type,delete Fn.port,delete Fn.uri_params,"SIP_URI"===r&&(Fn=Fn.uri)}catch(e){Fn=-1}}()),null===e&&(i=f),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===s&&a('"sips"')),null!==e&&(r=e,e=void(Fn.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===s&&a('"sip"')),null!==e&&(r=e,e=void(Fn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,o,l,u,c;return o=i,l=i,null!==(e=re())?(u=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===s&&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===s&&a('"@"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l)):(e=null,i=l),null!==e&&(c=o,e=void(Fn.user=decodeURIComponent(n.substring(i-1,c)))),null===e&&(i=o),e}function re(){var e,t;if(null===(t=b())&&null===(t=C())&&(t=oe()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=b())&&null===(t=C())&&(t=oe());else e=null;return e}function oe(){var e;return 38===n.charCodeAt(i)?(e="&",i++):(e=null,0===s&&a('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===s&&a('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===s&&a('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===s&&a('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===s&&a('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===s&&a('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===s&&a('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===s&&a('"/"'))))))))),e}function ie(){var e,t,r,o;for(r=i,e=[],null===(t=b())&&null===(t=C())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===s&&a('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===s&&a('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===s&&a('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===s&&a('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===s&&a('","')))))));null!==t;)e.push(t),null===(t=b())&&null===(t=C())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===s&&a('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===s&&a('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===s&&a('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===s&&a('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===s&&a('","')))))));return null!==e&&(o=r,e=void(Fn.password=n.substring(i,o))),null===e&&(i=r),e}function se(){var e,t,r,o,l;return o=i,null!==(e=le())?(l=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===s&&a('":"')),null!==t&&null!==(r=ve())?t=[t,r]:(t=null,i=l),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=o)):(e=null,i=o),e}function le(){var e,t,r;return t=i,null===(e=ue())&&null===(e=pe())&&(e=fe()),null!==e&&(r=t,Fn.host=n.substring(i,r).toLowerCase(),e=Fn.host),null===e&&(i=t),e}function ue(){var e,t,r,o,l,u,c;for(o=i,l=i,e=[],u=i,null!==(t=ae())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===s&&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===s&&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===s&&a('"."')),null!==(r=null!==r?r:"")?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(c=o,Fn.host_type="domain",e=n.substring(i,c)),null===e&&(i=o),e}function ae(){var e,t,r,o;if(o=i,null!==(e=y())){for(t=[],null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===s&&a('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===s&&a('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===s&&a('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===s&&a('"_"'))));null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;return e}function ce(){var e,t,r,o;if(o=i,null!==(e=h())){for(t=[],null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===s&&a('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===s&&a('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===s&&a('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===s&&a('"_"'))));null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;return e}function fe(){var e,t,r,o,l,u;return o=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===s&&a('"["')),null!==e&&null!==(t=he())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===s&&a('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(u=o,Fn.host_type="IPv6",e=n.substring(i,u)),null===e&&(i=o),e}function he(){var e,t,r,o,l,u,c,f,h,d,_,p,m,v,g,y,T;return v=i,g=i,null!==(e=de())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===s&&a('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(o=":",i++):(o=null,0===s&&a('":"')),null!==o&&null!==(l=de())?(58===n.charCodeAt(i)?(u=":",i++):(u=null,0===s&&a('":"')),null!==u&&null!==(c=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===s&&a('":"')),null!==f&&null!==(h=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===s&&a('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===s&&a('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,o,l,u,c,f,h,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===s&&a('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===s&&a('":"')),null!==r&&null!==(o=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===s&&a('":"')),null!==l&&null!==(u=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===s&&a('":"')),null!==c&&null!==(f=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===s&&a('":"')),null!==h&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===s&&a('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,o,l,u,c,f,h,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===s&&a('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===s&&a('":"')),null!==r&&null!==(o=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===s&&a('":"')),null!==l&&null!==(u=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===s&&a('":"')),null!==c&&null!==(f=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===s&&a('":"')),null!==h&&null!==(d=_e())?e=[e,t,r,o,l,u,c,f,h,d]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===n.substr(i,2)?(e="::",i+=2):(e=null,0===s&&a('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===s&&a('":"')),null!==r&&null!==(o=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===s&&a('":"')),null!==l&&null!==(u=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===s&&a('":"')),null!==c&&null!==(f=_e())?e=[e,t,r,o,l,u,c,f]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===n.substr(i,2)?(e="::",i+=2):(e=null,0===s&&a('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===s&&a('":"')),null!==r&&null!==(o=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===s&&a('":"')),null!==l&&null!==(u=_e())?e=[e,t,r,o,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===s&&a('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===s&&a('":"')),null!==r&&null!==(o=_e())?e=[e,t,r,o]:(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===n.substr(i,2)?(e="::",i+=2):(e=null,0===s&&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===s&&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===s&&a('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(o=":",i++):(o=null,0===s&&a('":"')),null!==o&&null!==(l=de())?(58===n.charCodeAt(i)?(u=":",i++):(u=null,0===s&&a('":"')),null!==u&&null!==(c=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===s&&a('":"')),null!==f&&null!==(h=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===s&&a('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,o,l,u,c,f,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=de())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===s&&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===s&&a('"::"')),null!==r&&null!==(o=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===s&&a('":"')),null!==l&&null!==(u=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===s&&a('":"')),null!==c&&null!==(f=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===s&&a('":"')),null!==h&&null!==(d=_e())?e=[e,t,r,o,l,u,c,f,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=de())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===s&&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===s&&a('":"')),null!==r&&null!==(o=de())?r=[r,o]:(r=null,i=y),null!==(r=null!==r?r:"")?("::"===n.substr(i,2)?(o="::",i+=2):(o=null,0===s&&a('"::"')),null!==o&&null!==(l=de())?(58===n.charCodeAt(i)?(u=":",i++):(u=null,0===s&&a('":"')),null!==u&&null!==(c=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===s&&a('":"')),null!==f&&null!==(h=_e())?e=[e,t,r,o,l,u,c,f,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===s&&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===s&&a('":"')),null!==r&&null!==(o=de())?r=[r,o]:(r=null,i=y),null!==(r=null!==r?r:"")?(y=i,58===n.charCodeAt(i)?(o=":",i++):(o=null,0===s&&a('":"')),null!==o&&null!==(l=de())?o=[o,l]:(o=null,i=y),null!==(o=null!==o?o:"")?("::"===n.substr(i,2)?(l="::",i+=2):(l=null,0===s&&a('"::"')),null!==l&&null!==(u=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===s&&a('":"')),null!==c&&null!==(f=_e())?e=[e,t,r,o,l,u,c,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===s&&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===s&&a('":"')),null!==r&&null!==(o=de())?r=[r,o]:(r=null,i=y),null!==(r=null!==r?r:"")?(y=i,58===n.charCodeAt(i)?(o=":",i++):(o=null,0===s&&a('":"')),null!==o&&null!==(l=de())?o=[o,l]:(o=null,i=y),null!==(o=null!==o?o:"")?(y=i,58===n.charCodeAt(i)?(l=":",i++):(l=null,0===s&&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===s&&a('"::"')),null!==u&&null!==(c=_e())?e=[e,t,r,o,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===s&&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===s&&a('":"')),null!==r&&null!==(o=de())?r=[r,o]:(r=null,i=y),null!==(r=null!==r?r:"")?(y=i,58===n.charCodeAt(i)?(o=":",i++):(o=null,0===s&&a('":"')),null!==o&&null!==(l=de())?o=[o,l]:(o=null,i=y),null!==(o=null!==o?o:"")?(y=i,58===n.charCodeAt(i)?(l=":",i++):(l=null,0===s&&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===s&&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===s&&a('"::"')),null!==c&&null!==(f=de())?e=[e,t,r,o,l,u,c,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)):(e=null,i=g),null===e&&(g=i,null!==(e=de())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===s&&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===s&&a('":"')),null!==r&&null!==(o=de())?r=[r,o]:(r=null,i=y),null!==(r=null!==r?r:"")?(y=i,58===n.charCodeAt(i)?(o=":",i++):(o=null,0===s&&a('":"')),null!==o&&null!==(l=de())?o=[o,l]:(o=null,i=y),null!==(o=null!==o?o:"")?(y=i,58===n.charCodeAt(i)?(l=":",i++):(l=null,0===s&&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===s&&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===s&&a('":"')),null!==c&&null!==(f=de())?c=[c,f]:(c=null,i=y),null!==(c=null!==c?c:"")?("::"===n.substr(i,2)?(f="::",i+=2):(f=null,0===s&&a('"::"')),null!==f?e=[e,t,r,o,l,u,c,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)):(e=null,i=g)):(e=null,i=g))))))))))))))),null!==e&&(T=v,Fn.host_type="IPv6",e=n.substring(i,T)),null===e&&(i=v),e}function de(){var e,t,n,r,o;return o=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=o),e}function _e(){var e,t,r,o;return o=i,null!==(e=de())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===s&&a('":"')),null!==t&&null!==(r=de())?e=[e,t,r]:(e=null,i=o)):(e=null,i=o),null===e&&(e=pe()),e}function pe(){var e,t,r,o,l,u,c,f,h,d;return f=i,h=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===s&&a('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(o=".",i++):(o=null,0===s&&a('"."')),null!==o&&null!==(l=me())?(46===n.charCodeAt(i)?(u=".",i++):(u=null,0===s&&a('"."')),null!==u&&null!==(c=me())?e=[e,t,r,o,l,u,c]:(e=null,i=h)):(e=null,i=h)):(e=null,i=h)):(e=null,i=h),null!==e&&(d=f,Fn.host_type="IPv4",e=n.substring(i,d)),null===e&&(i=f),e}function me(){var e,t,r,o;return o=i,"25"===n.substr(i,2)?(e="25",i+=2):(e=null,0===s&&a('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===s&&a("[0-5]")),null!==t?e=[e,t]:(e=null,i=o)):(e=null,i=o),null===e&&(o=i,50===n.charCodeAt(i)?(e="2",i++):(e=null,0===s&&a('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===s&&a("[0-4]")),null!==t&&null!==(r=f())?e=[e,t,r]:(e=null,i=o)):(e=null,i=o),null===e&&(o=i,49===n.charCodeAt(i)?(e="1",i++):(e=null,0===s&&a('"1"')),null!==e&&null!==(t=f())&&null!==(r=f())?e=[e,t,r]:(e=null,i=o),null===e&&(o=i,/^[1-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===s&&a("[1-9]")),null!==e&&null!==(t=f())?e=[e,t]:(e=null,i=o),null===e&&(e=f())))),e}function ve(){var e,t,n,r,o,s,l,u;return s=i,l=i,null!==(e=null!==(e=f())?e:"")&&null!==(t=null!==(t=f())?t:"")&&null!==(n=null!==(n=f())?n:"")&&null!==(r=null!==(r=f())?r:"")&&null!==(o=null!==(o=f())?o:"")?e=[e,t,n,r,o]:(e=null,i=l),null!==e&&(u=e,u=parseInt(u.join("")),Fn.port=u,e=u),null===e&&(i=s),e}function ge(){var e,t,r,o;for(e=[],o=i,59===n.charCodeAt(i)?(t=";",i++):(t=null,0===s&&a('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=o);null!==t;)e.push(t),o=i,59===n.charCodeAt(i)?(t=";",i++):(t=null,0===s&&a('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=o);return e}function ye(){var e;return null===(e=Te())&&null===(e=be())&&null===(e=Se())&&null===(e=Ce())&&null===(e=Ee())&&null===(e=Ae())&&(e=we()),e}function Te(){var e,t,r,o,l;return r=i,o=i,"transport="===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===s&&a('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===s&&a('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===s&&a('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===s&&a('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===s&&a('"tls"')),null===t&&(t=k())))),null!==t?e=[e,t]:(e=null,i=o)):(e=null,i=o),null!==e&&(l=e[1],Fn.uri_params||(Fn.uri_params={}),e=void(Fn.uri_params.transport=l.toLowerCase())),null===e&&(i=r),e}function be(){var e,t,r,o,l;return r=i,o=i,"user="===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===s&&a('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===s&&a('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===s&&a('"ip"')),null===t&&(t=k())),null!==t?e=[e,t]:(e=null,i=o)):(e=null,i=o),null!==e&&(l=e[1],Fn.uri_params||(Fn.uri_params={}),e=void(Fn.uri_params.user=l.toLowerCase())),null===e&&(i=r),e}function Se(){var e,t,r,o,l;return r=i,o=i,"method="===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===s&&a('"method="')),null!==e&&null!==(t=ct())?e=[e,t]:(e=null,i=o),null!==e&&(l=e[1],Fn.uri_params||(Fn.uri_params={}),e=void(Fn.uri_params.method=l)),null===e&&(i=r),e}function Ce(){var e,t,r,o,l;return r=i,o=i,"ttl="===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===s&&a('"ttl="')),null!==e&&null!==(t=An())?e=[e,t]:(e=null,i=o),null!==e&&(l=e[1],Fn.params||(Fn.params={}),e=void(Fn.params.ttl=l)),null===e&&(i=r),e}function Ee(){var e,t,r,o,l;return r=i,o=i,"maddr="===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===s&&a('"maddr="')),null!==e&&null!==(t=le())?e=[e,t]:(e=null,i=o),null!==e&&(l=e[1],Fn.uri_params||(Fn.uri_params={}),e=void(Fn.uri_params.maddr=l)),null===e&&(i=r),e}function Ae(){var e,t,r,o,l,u;return o=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===s&&a('"lr"')),null!==e?(u=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===s&&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&&(Fn.uri_params||(Fn.uri_params={}),e=void(Fn.uri_params.lr=void 0)),null===e&&(i=o),e}function we(){var e,t,r,o,l,u,c,f;return o=i,l=i,null!==(e=Re())?(u=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===s&&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],f=e[1],Fn.uri_params||(Fn.uri_params={}),f=void 0===f?void 0:f[1],e=void(Fn.uri_params[c.toLowerCase()]=f)),null===e&&(i=o),e}function Re(){var e,t,n;if(n=i,null!==(t=Oe()))for(e=[];null!==t;)e.push(t),t=Oe();else e=null;return null!==e&&(e=e.join("")),null===e&&(i=n),e}function Ie(){var e,t,n;if(n=i,null!==(t=Oe()))for(e=[];null!==t;)e.push(t),t=Oe();else e=null;return null!==e&&(e=e.join("")),null===e&&(i=n),e}function Oe(){var e;return null===(e=Ne())&&null===(e=b())&&(e=C()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===s&&a('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===s&&a('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===s&&a('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===s&&a('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===s&&a('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===s&&a('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===s&&a('"$"')))))))),e}function ke(){var e,t,r,o,l,u,c;if(u=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===s&&a('"?"')),null!==e)if(null!==(t=Pe())){for(r=[],c=i,38===n.charCodeAt(i)?(o="&",i++):(o=null,0===s&&a('"&"')),null!==o&&null!==(l=Pe())?o=[o,l]:(o=null,i=c);null!==o;)r.push(o),c=i,38===n.charCodeAt(i)?(o="&",i++):(o=null,0===s&&a('"&"')),null!==o&&null!==(l=Pe())?o=[o,l]:(o=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 Pe(){var e,t,r,o,l,u,c;return o=i,l=i,null!==(e=Ue())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===s&&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(""),Fn.uri_headers||(Fn.uri_headers={}),e=void(Fn.uri_headers[u]?Fn.uri_headers[u].push(c):Fn.uri_headers[u]=[c])),null===e&&(i=o),e}function Ue(){var e,t;if(null===(t=xe())&&null===(t=b())&&(t=C()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=xe())&&null===(t=b())&&(t=C());else e=null;return e}function De(){var e,t;for(e=[],null===(t=xe())&&null===(t=b())&&(t=C());null!==t;)e.push(t),null===(t=xe())&&null===(t=b())&&(t=C());return e}function xe(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===s&&a('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===s&&a('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===s&&a('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===s&&a('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===s&&a('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===s&&a('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===s&&a('"$"')))))))),e}function Me(){var e,t,n,r,o,s;return s=i,null!==(e=ct())&&null!==(t=v())&&null!==(n=qe())&&null!==(r=v())&&null!==(o=et())?e=[e,t,n,r,o]:(e=null,i=s),e}function qe(){var e;return null===(e=Q())&&(e=Le()),e}function Le(){var e,t,r,o;return o=i,null!==(e=$e())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===s&&a('":"')),null!==t?(null===(r=He())&&(r=Ge()),null!==r?e=[e,t,r]:(e=null,i=o)):(e=null,i=o)):(e=null,i=o),e}function He(){var e,t,r,o,l;return o=i,null===(e=je())&&(e=Fe()),null!==e?(l=i,63===n.charCodeAt(i)?(t="?",i++):(t=null,0===s&&a('"?"')),null!==t&&null!==(r=Ze())?t=[t,r]:(t=null,i=l),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=o)):(e=null,i=o),e}function je(){var e,t,r,o;return o=i,"//"===n.substr(i,2)?(e="//",i+=2):(e=null,0===s&&a('"//"')),null!==e&&null!==(t=Xe())&&null!==(r=null!==(r=Fe())?r:"")?e=[e,t,r]:(e=null,i=o),e}function Fe(){var e,t,r;return r=i,47===n.charCodeAt(i)?(e="/",i++):(e=null,0===s&&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=b())&&(e=C()),e}function We(){var e;return null===(e=b())&&null===(e=C())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===s&&a('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===s&&a('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===s&&a('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===s&&a('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===s&&a('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===s&&a('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===s&&a('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===s&&a('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===s&&a('","'))))))))))),e}function Ve(){var e,t,r,o,l,u;if(l=i,null!==(e=Ke())){for(t=[],u=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===s&&a('"/"')),null!==r&&null!==(o=Ke())?r=[r,o]:(r=null,i=u);null!==r;)t.push(r),u=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===s&&a('"/"')),null!==r&&null!==(o=Ke())?r=[r,o]:(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,o,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===s&&a('";"')),null!==r&&null!==(o=ze())?r=[r,o]:(r=null,i=u);null!==r;)t.push(r),u=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===s&&a('";"')),null!==r&&null!==(o=ze())?r=[r,o]:(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=b())&&null===(e=C())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===s&&a('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===s&&a('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===s&&a('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===s&&a('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===s&&a('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===s&&a('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===s&&a('","'))))))))),e}function $e(){var e,t,r,o,l,u;if(o=i,l=i,null!==(e=h())){for(t=[],null===(r=h())&&null===(r=f())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===s&&a('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===s&&a('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===s&&a('"."')))));null!==r;)t.push(r),null===(r=h())&&null===(r=f())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===s&&a('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===s&&a('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===s&&a('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(u=o,e=void(Fn.scheme=n.substring(i,u))),null===e&&(i=o),e}function Xe(){var e;return null===(e=Je())&&(e=Qe()),e}function Je(){var e,t,r,o;return r=i,o=i,null!==(e=ne())?(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===s&&a('"@"')),null!==t?e=[e,t]:(e=null,i=o)):(e=null,i=o),null!==(e=null!==e?e:"")&&null!==(t=se())?e=[e,t]:(e=null,i=r),e=null!==e?e:""}function Qe(){var e,t;if(null===(t=b())&&null===(t=C())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===s&&a('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===s&&a('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===s&&a('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===s&&a('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===s&&a('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===s&&a('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===s&&a('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===s&&a('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=b())&&null===(t=C())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===s&&a('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===s&&a('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===s&&a('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===s&&a('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===s&&a('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===s&&a('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===s&&a('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===s&&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,o,l,u,c,h,d;if(c=i,h=i,"sip"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===s&&a('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===s&&a('"/"')),null!==t){if(null!==(o=f()))for(r=[];null!==o;)r.push(o),o=f();else r=null;if(null!==r)if(46===n.charCodeAt(i)?(o=".",i++):(o=null,0===s&&a('"."')),null!==o){if(null!==(u=f()))for(l=[];null!==u;)l.push(u),u=f();else l=null;null!==l?e=[e,t,r,o,l]:(e=null,i=h)}else e=null,i=h;else e=null,i=h}else e=null,i=h;else e=null,i=h;return null!==e&&(d=c,e=void(Fn.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===s&&a('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===s&&a('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===s&&a('"OPTIONS"')),e}function ot(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===s&&a('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===s&&a('"CANCEL"')),e}function st(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===s&&a('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===s&&a('"SUBSCRIBE"')),e}function ut(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===s&&a('"NOTIFY"')),e}function at(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===s&&a('"REFER"')),e}function ct(){var e,t,r;return t=i,null===(e=tt())&&null===(e=nt())&&null===(e=rt())&&null===(e=ot())&&null===(e=it())&&null===(e=st())&&null===(e=lt())&&null===(e=ut())&&null===(e=at())&&(e=k()),null!==e&&(r=t,Fn.method=n.substring(i,r),e=Fn.method),null===e&&(i=t),e}function ft(){var e,t,n,r,o,s;return s=i,null!==(e=et())&&null!==(t=v())&&null!==(n=ht())&&null!==(r=v())&&null!==(o=_t())?e=[e,t,n,r,o]:(e=null,i=s),e}function ht(){var e,t,n;return t=i,null!==(e=dt())&&(n=e,e=void(Fn.status_code=parseInt(n.join("")))),null===e&&(i=t),e}function dt(){var e,t,n,r;return r=i,null!==(e=f())&&null!==(t=f())&&null!==(n=f())?e=[e,t,n]:(e=null,i=r),e}function _t(){var e,t,r,o;for(r=i,e=[],null===(t=T())&&null===(t=b())&&null===(t=C())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=b())&&null===(t=C())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());return null!==e&&(o=r,e=void(Fn.reason_phrase=n.substring(i,o))),null===e&&(i=r),e}function pt(){var e,t,n,r,o,s,l;if(o=i,s=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=s)}else e=null,i=s;return null!==e&&(e=function(e){var t;Fn.multi_header||(Fn.multi_header=[]);try{t=new jn(Fn.uri,Fn.display_name,Fn.params),delete Fn.uri,delete Fn.display_name,delete Fn.params}catch(e){t=null}Fn.multi_header.push({possition:i,offset:e,parsed:t})}(o)),null===e&&(i=o),e}function mt(){var e,t,n,r,o;return o=i,null!==(e=null!==(e=vt())?e:"")&&null!==(t=j())&&null!==(n=Q())&&null!==(r=H())?e=[e,t,n,r]:(e=null,i=o),e}function vt(){var e,t,n,r,o,s,l,u;if(o=i,s=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=s)}else e=null,i=s;return null===e&&(e=Y()),null!==e&&(u=e,e=void(Fn.display_name="string"==typeof u?u:u[1].reduce(function(e,t){return e+t[0]+t[1]},u[0]))),null===e&&(i=o),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Ct()),e}function yt(){var e,t,r,o,l,u;return o=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===s&&a('"q"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(u=e[2],Fn.params||(Fn.params={}),e=void(Fn.params.q=u)),null===e&&(i=o),e}function Tt(){var e,t,r,o,l,u;return o=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===s&&a('"expires"')),null!==e&&null!==(t=M())&&null!==(r=bt())?e=[e,t,r]:(e=null,i=l),null!==e&&(u=e[2],Fn.params||(Fn.params={}),e=void(Fn.params.expires=u)),null===e&&(i=o),e}function bt(){var e,t,n;if(n=i,null!==(t=f()))for(e=[];null!==t;)e.push(t),t=f();else e=null;return null!==e&&(e=parseInt(e.join(""))),null===e&&(i=n),e}function St(){var e,t,r,o,l,u,c,h,d;return u=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===s&&a('"0"')),null!==e?(h=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===s&&a('"."')),null!==t&&null!==(r=null!==(r=f())?r:"")&&null!==(o=null!==(o=f())?o:"")&&null!==(l=null!==(l=f())?l:"")?t=[t,r,o,l]:(t=null,i=h),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 Ct(){var e,t,n,r,o,s,l,u;return r=i,o=i,null!==(e=k())?(s=i,null!==(t=M())&&null!==(n=Et())?t=[t,n]:(t=null,i=s),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=o)):(e=null,i=o),null!==e&&(l=e[0],u=e[1],Fn.params||(Fn.params={}),u=void 0===u?void 0:u[1],e=void(Fn.params[l.toLowerCase()]=u)),null===e&&(i=r),e}function Et(){var e;return null===(e=k())&&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===s&&a('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===s&&a('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===s&&a('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===s&&a('"alert"')),null===e&&(e=k())))),e}function wt(){var e;return null===(e=Rt())&&(e=Ct()),e}function Rt(){var e,t,r,o;return o=i,"handling"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===s&&a('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===s&&a('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===s&&a('"required"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=o)):(e=null,i=o),e}function It(){var e,t,n,r,o,s,l,u;if(l=i,null!==(e=Ot()))if(null!==(t=x()))if(null!==(n=Dt())){for(r=[],u=i,null!==(o=G())&&null!==(s=xt())?o=[o,s]:(o=null,i=u);null!==o;)r.push(o),u=i,null!==(o=G())&&null!==(s=xt())?o=[o,s]:(o=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===s&&a('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===s&&a('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===s&&a('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===s&&a('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===s&&a('"application"')),null===e&&(e=Pt()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===s&&a('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===s&&a('"multipart"')),null===e&&(e=Pt())),e}function Pt(){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===s&&a('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function Dt(){var e;return null===(e=Pt())&&(e=k()),e}function xt(){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=z()),e}function qt(){var e,t,n,r;if(n=i,null!==(t=f()))for(e=[];null!==t;)e.push(t),t=f();else e=null;return null!==e&&(r=e,e=void(Fn.value=parseInt(r.join("")))),null===e&&(i=n),e}function Lt(){var e,t,r,o,l,u;if(l=i,null!==(e=P())){for(t=[],u=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===s&&a('"."')),null!==r&&null!==(o=P())?r=[r,o]:(r=null,i=u);null!==r;)t.push(r),u=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===s&&a('"."')),null!==r&&null!==(o=P())?r=[r,o]:(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=jt())&&(e=Ct()),e}function jt(){var e,t,r,o,l,u;return o=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===s&&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(Fn.tag=u)),null===e&&(i=o),e}function Ft(){var e,t,r,o,l,u,c,f;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===s&&a('"Digest"')),null!==e)if(null!==(t=E()))if(null!==(r=Wt())){for(o=[],f=i,null!==(l=F())&&null!==(u=Wt())?l=[l,u]:(l=null,i=f);null!==l;)o.push(l),f=i,null!==(l=F())&&null!==(u=Wt())?l=[l,u]:(l=null,i=f);null!==o?e=[e,t,r,o]:(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,o,s,l,u;if(l=i,null!==(e=k()))if(null!==(t=E()))if(null!==(n=Bt())){for(r=[],u=i,null!==(o=F())&&null!==(s=Bt())?o=[o,s]:(o=null,i=u);null!==o;)r.push(o),u=i,null!==(o=F())&&null!==(s=Bt())?o=[o,s]:(o=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=z()),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=zt())&&null===(e=$t())&&null===(e=Jt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Bt()),e}function Vt(){var e,t,r,o;return o=i,"realm"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===s&&a('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Kt())?e=[e,t,r]:(e=null,i=o),e}function Kt(){var e,t,n;return t=i,null!==(e=Y())&&(n=e,e=void(Fn.realm=n)),null===e&&(i=t),e}function zt(){var e,t,r,o,l,u,c,f,h;if(f=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===s&&a('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=W()))if(null!==(o=Yt())){if(l=[],h=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=h);null!==u;){if(l.push(u),h=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=h)}null!==l&&null!==(u=V())?e=[e,t,r,o,l,u]:(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 e}function Yt(){var e;return null===(e=Le())&&(e=Fe()),e}function $t(){var e,t,r,o;return o=i,"nonce"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===s&&a('"nonce"')),null!==e&&null!==(t=M())&&null!==(r=Xt())?e=[e,t,r]:(e=null,i=o),e}function Xt(){var e,t,n;return t=i,null!==(e=Y())&&(n=e,e=void(Fn.nonce=n)),null===e&&(i=t),e}function Jt(){var e,t,r,o,l,u;return o=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===s&&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(Fn.opaque=u)),null===e&&(i=o),e}function Qt(){var e,t,r,o,l;return o=i,"stale"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===s&&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===s&&a('"true"')),null!==r&&(r=void(Fn.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===s&&a('"false"')),null!==r&&(r=void(Fn.stale=!1)),null===r&&(i=l)),null!==r?e=[e,t,r]:(e=null,i=o)):(e=null,i=o),e}function Zt(){var e,t,r,o,l,u;return o=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===s&&a('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===s&&a('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===s&&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(Fn.algorithm=u.toUpperCase())),null===e&&(i=o),e}function en(){var e,t,r,o,l,u,c,f,h,d;if(f=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===s&&a('"qop"')),null!==e)if(null!==(t=M()))if(null!==(r=W())){if(h=i,null!==(o=tn())){for(l=[],d=i,44===n.charCodeAt(i)?(u=",",i++):(u=null,0===s&&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===s&&a('","')),null!==u&&null!==(c=tn())?u=[u,c]:(u=null,i=d);null!==l?o=[o,l]:(o=null,i=h)}else o=null,i=h;null!==o&&null!==(l=V())?e=[e,t,r,o,l]:(e=null,i=f)}else e=null,i=f;else e=null,i=f;else e=null,i=f;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===s&&a('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===s&&a('"auth"')),null===e&&(e=k())),null!==e&&(r=e,Fn.qop||(Fn.qop=[]),e=void Fn.qop.push(r.toLowerCase())),null===e&&(i=t),e}function nn(){var e,t,n,r,o,s,l;if(o=i,s=i,null!==(e=mt())){for(t=[],l=i,null!==(n=G())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=G())&&null!==(r=Ct())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return null!==e&&(e=function(e){var t;Fn.multi_header||(Fn.multi_header=[]);try{t=new jn(Fn.uri,Fn.display_name,Fn.params),delete Fn.uri,delete Fn.display_name,delete Fn.params}catch(e){t=null}Fn.multi_header.push({possition:i,offset:e,parsed:t})}(o)),null===e&&(i=o),e}function rn(){var e;return null===(e=on())&&(e=Ct()),e}function on(){var e,t,r,o,l,u,c;if(l=i,u=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===s&&a('"cause"')),null!==e)if(null!==(t=M())){if(null!==(o=f()))for(r=[];null!==o;)r.push(o),o=f();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(Fn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function sn(){var e,t,n,r,o,s;if(o=i,null!==(e=mt())){for(t=[],s=i,null!==(n=G())&&null!==(r=Ct())?n=[n,r]:(n=null,i=s);null!==n;)t.push(n),s=i,null!==(n=G())&&null!==(r=Ct())?n=[n,r]:(n=null,i=s);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;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===s&&a('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===s&&a('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===s&&a('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(Fn.state=n.substring(i,r))),null===e&&(i=t),e}function un(){var e,t,r,o,l,u,c,f;return o=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===s&&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])&&(Fn.reason=u))),null===e&&(i=o),null===e&&(o=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===s&&a('"expires"')),null!==e&&null!==(t=M())&&null!==(r=bt())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(f=e[2])&&(Fn.expires=f))),null===e&&(i=o),null===e&&(o=i,l=i,"retry_after"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===s&&a('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=bt())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(c=e[2])&&(Fn.retry_after=c))),null===e&&(i=o),null===e&&(e=Ct()))),e}function an(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===s&&a('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===s&&a('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===s&&a('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===s&&a('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===s&&a('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===s&&a('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===s&&a('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=jt())&&(e=Ct()),e}function fn(){var e,t,n,r,o,s,l,u;if(l=i,null!==(e=yn()))if(null!==(t=E()))if(null!==(n=Sn())){for(r=[],u=i,null!==(o=G())&&null!==(s=hn())?o=[o,s]:(o=null,i=u);null!==o;)r.push(o),u=i,null!==(o=G())&&null!==(s=hn())?o=[o,s]:(o=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 hn(){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,o,l,u;return o=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===s&&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(Fn.ttl=u)),null===e&&(i=o),e}function _n(){var e,t,r,o,l,u;return o=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===s&&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(Fn.maddr=u)),null===e&&(i=o),e}function pn(){var e,t,r,o,l,u;return o=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===s&&a('"received"')),null!==e&&null!==(t=M())?(null===(r=pe())&&(r=he()),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(u=e[2],e=void(Fn.received=u)),null===e&&(i=o),e}function mn(){var e,t,r,o,l,u;return o=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===s&&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(Fn.branch=u)),null===e&&(i=o),e}function vn(){var e,t,r,o,l;return o=i,"rport"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===s&&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=o)):(e=null,i=o),e}function gn(){var e,t,n,r,o,s,l,u;return s=i,l=i,null!==(e=null!==(e=f())?e:"")&&null!==(t=null!==(t=f())?t:"")&&null!==(n=null!==(n=f())?n:"")&&null!==(r=null!==(r=f())?r:"")&&null!==(o=null!==(o=f())?o:"")?e=[e,t,n,r,o]:(e=null,i=l),null!==e&&(u=e,e=void(Fn.rport=parseInt(u.join("")))),null===e&&(i=s),e}function yn(){var e,t,n,r,o,s;return s=i,null!==(e=Tn())&&null!==(t=x())&&null!==(n=k())&&null!==(r=x())&&null!==(o=bn())?e=[e,t,n,r,o]:(e=null,i=s),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===s&&a('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(Fn.protocol=r)),null===e&&(i=t),e}function bn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===s&&a('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===s&&a('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===s&&a('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===s&&a('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(Fn.transport=r)),null===e&&(i=t),e}function Sn(){var e,t,n,r,o;return r=i,null!==(e=Cn())?(o=i,null!==(t=B())&&null!==(n=En())?t=[t,n]:(t=null,i=o),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=fe())&&(e=ue()),null!==e&&(r=t,e=void(Fn.host=n.substring(i,r))),null===e&&(i=t),e}function En(){var e,t,n,r,o,s,l,u;return s=i,l=i,null!==(e=null!==(e=f())?e:"")&&null!==(t=null!==(t=f())?t:"")&&null!==(n=null!==(n=f())?n:"")&&null!==(r=null!==(r=f())?r:"")&&null!==(o=null!==(o=f())?o:"")?e=[e,t,n,r,o]:(e=null,i=l),null!==e&&(u=e,e=void(Fn.port=parseInt(u.join("")))),null===e&&(i=s),e}function An(){var e,t,n,r,o;return r=i,o=i,null!==(e=f())&&null!==(t=null!==(t=f())?t:"")&&null!==(n=null!==(n=f())?n:"")?e=[e,t,n]:(e=null,i=o),null!==e&&(e=parseInt(e.join(""))),null===e&&(i=r),e}function wn(){var e,t,n;return t=i,null!==(e=bt())&&(n=e,e=void(Fn.expires=n)),null===e&&(i=t),e}function Rn(){var e;return null===(e=In())&&(e=Ct()),e}function In(){var e,t,r,o,l,u;return o=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===s&&a('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===s&&a('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===s&&a('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(u=e[2],e=void(Fn.refresher=u.toLowerCase())),null===e&&(i=o),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,o,l,u,c,f,h,d,_,p;return d=i,_=i,null!==(e=Pn())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===s&&a('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(o="-",i++):(o=null,0===s&&a('"-"')),null!==o&&null!==(l=kn())?(45===n.charCodeAt(i)?(u="-",i++):(u=null,0===s&&a('"-"')),null!==u&&null!==(c=kn())?(45===n.charCodeAt(i)?(f="-",i++):(f=null,0===s&&a('"-"')),null!==f&&null!==(h=Un())?e=[e,t,r,o,l,u,c,f,h]:(e=null,i=_)):(e=null,i=_)):(e=null,i=_)):(e=null,i=_)):(e=null,i=_),null!==e&&(p=d,e[0],e=void(Fn=n.substring(i+5,p))),null===e&&(i=d),e}function kn(){var e,t,n,r,o;return o=i,null!==(e=d())&&null!==(t=d())&&null!==(n=d())&&null!==(r=d())?e=[e,t,n,r]:(e=null,i=o),e}function Pn(){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,o,l,u,c;return o=i,l=i,null!==(e=U())?(u=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===s&&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=o,e=void(Fn.call_id=n.substring(i,c))),null===e&&(i=o),e}function xn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Ct()),e}function Mn(){var e,t,r,o,l,u;return o=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===s&&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(Fn.to_tag=u)),null===e&&(i=o),e}function qn(){var e,t,r,o,l,u;return o=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===s&&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(Fn.from_tag=u)),null===e&&(i=o),e}function Ln(){var e,t;return t=i,"early-only"===n.substr(i,10)?(e="early-only",i+=10):(e=null,0===s&&a('"early-only"')),null!==e&&(e=void(Fn.early_only=!0)),null===e&&(i=t),e}var Hn=e("./URI"),jn=e("./NameAddrHeader"),Fn={};if(null===o[r]()||i!==n.length){var Gn=Math.max(i,l),Bn=Gn2&&void 0!==arguments[2]?arguments[2]:{},o=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(o));var i=d.cloneArray(r.extraHeaders),s=d.cloneObject(r.eventHandlers),l=r.contentType||"text/plain",u={};for(var a in r.fromUserName&&(u.from_uri=new m("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),s)Object.prototype.hasOwnProperty.call(s,a)&&this.on(a,s[a]);i.push("Content-Type: ".concat(l)),this._request=new h.OutgoingRequest(f.MESSAGE,e,this._ua,u,i),t&&(this._request.body=t);var c=new _(this._ua,this._request,{onRequestTimeout:function(){n._onRequestTimeout()},onTransportError:function(){n._onTransportError()},onReceiveResponse:function(e){n._receiveResponse(e)}});this._newMessage("local",this._request),c.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 p.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),o=e.body;if("incoming"!==this._direction)throw new p.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,o)}},{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,f.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,f.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){v.debug("MESSAGE failed"),this._close(),v.debug('emit "failed"'),this.emit("failed",{originator:e,response:t||null,cause:n})}},{key:"_succeeded",value:function(e,t){v.debug("MESSAGE succeeded"),this._close(),v.debug('emit "succeeded"'),this.emit("succeeded",{originator:e,response:t})}}])&&o(n.prototype,r),i&&o(n,i),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,r,i}()},{"./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){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function o(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}}])&&o(t.prototype,n),r&&o(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,n,r}()},{"./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 o(e,t){for(var n=0;n2&&void 0!==arguments[2]?arguments[2]:{},o=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(o));var i=d.cloneArray(r.extraHeaders),s=d.cloneObject(r.eventHandlers),l=r.contentType||"application/sdp";for(var u in s)Object.prototype.hasOwnProperty.call(s,u)&&this.on(u,s[u]);i.push("Content-Type: ".concat(l)),this._request=new h.OutgoingRequest(f.OPTIONS,e,this._ua,null,i),t&&(this._request.body=t);var a=new _(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 p.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),o=e.body;if("incoming"!==this._direction)throw new p.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,o)}},{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,f.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,f.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){m.debug("OPTIONS 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("OPTIONS succeeded"),this._close(),m.debug('emit "succeeded"'),this.emit("succeeded",{originator:e,response:t})}}])&&o(n.prototype,r),i&&o(n,i),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,r,i}()},{"./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="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return o(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?o(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,l=!0,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,s=e},f:function(){try{l||null==n.return||n.return()}finally{if(u)throw s}}}}function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,l=!0,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,s=e},f:function(){try{l||null==n.return||n.return()}finally{if(u)throw s}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;R.debug("connect()");var r=e,o=v.cloneObject(t.eventHandlers),i=v.cloneArray(t.extraHeaders),s=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 f in this._sessionTimers.enabled&&v.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=_.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=_.SESSION_EXPIRES),o)Object.prototype.hasOwnProperty.call(o,f)&&this.on(f,o[f]);this._from_tag=v.newTag();var h=t.anonymous||!1,d={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:h,outbound:!0}),h?(d.from_display_name="Anonymous",d.from_uri=new w("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(d.from_uri=new w("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(d.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,d,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(s,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;R.debug("init_incoming()");var o=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==o?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]:{};R.debug("answer()");var n=this._request,r=v.cloneArray(t.extraHeaders),i=v.cloneObject(t.mediaConstraints),s=t.mediaStream||null,l=v.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,a=t.rtcAnswerConstraints||null,c=v.cloneObject(t.rtcOfferConstraints),f=!1,h=!1,d=!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=o(g.media);try{for(T.s();!(y=T.n()).done;){var b=y.value;"audio"===b.type&&(f=!0,b.direction&&"sendrecv"!==b.direction||(d=!0)),"video"===b.type&&(h=!0,b.direction&&"sendrecv"!==b.direction||(m=!0))}}catch(e){T.e(e)}finally{T.f()}if(s&&!1===i.audio){var S,C=o(s.getAudioTracks());try{for(C.s();!(S=C.n()).done;){var E=S.value;s.removeTrack(E)}}catch(e){C.e(e)}finally{C.f()}}if(s&&!1===i.video){var A,w=o(s.getVideoTracks());try{for(w.s();!(A=w.n()).done;){var O=A.value;s.removeTrack(O)}}catch(e){w.e(e)}finally{w.f()}}s||void 0!==i.audio||(i.audio=d),s||void 0!==i.video||(i.video=m),s||f||c.offerToReceiveAudio||(i.audio=!1),s||h||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,u),Promise.resolve().then(function(){return s||(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),R.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};R.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),R.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&&R.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]:{};R.debug("terminate()");var n,r=t.cause||_.causes.BYE,o=v.cloneArray(t.extraHeaders),i=t.body,s=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(R.debug("canceling session"),s&&(s<200||s>=700))throw new TypeError("Invalid status_code: ".concat(s));s&&(l=l||_.REASON_PHRASE[s]||"",n="SIP ;cause=".concat(s,' ;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(R.debug("rejecting session"),(s=s||480)<300||s>=700)throw new TypeError("Invalid status_code: ".concat(s));this._request.reply(s,l,o,i),this._failed("local",null,_.causes.REJECTED);break;case I.STATUS_WAITING_FOR_ACK:case I.STATUS_CONFIRMED:if(R.debug("terminating session"),l=t.reason_phrase||_.REASON_PHRASE[s]||"",s&&(s<200||s>=700))throw new TypeError("Invalid status_code: ".concat(s));if(s&&o.push("Reason: SIP ;cause=".concat(s,'; 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:o,body:i}),u.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===m.C.STATUS_TERMINATED&&(e.sendRequest(_.BYE,{extraHeaders:o,body:i}),u.terminate())}),this._ended("local",null,r),this._dialog=u,this._ua.newDialog(u)}else this.sendRequest(_.BYE,{extraHeaders:o,body:i}),this._ended("local",null,r)}}},{key:"sendDTMF",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};R.debug("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,o=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?rS.C.MAX_DURATION?(R.debug('"duration" value is greater than the maximum allowed, setting it to '.concat(S.C.MAX_DURATION," milliseconds")),r=S.C.MAX_DURATION):r=Math.abs(r):r=S.C.DEFAULT_DURATION,t.duration=r,o&&!v.isDecimal(o))throw new TypeError("Invalid interToneGap: ".concat(o));if(o?o=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)s=2e3;else{var u=new S(this);t.eventHandlers={onFailed:function(){i._tones=null}},u.send(l,t),s=r+o}setTimeout(e.bind(this),s)}.call(this));else{var s=this._getDTMFRTPSender();s&&(e=s.toneBuffer+e,s.insertDTMF(e,r,o))}}},{key:"sendInfo",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(R.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 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};R.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};R.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(R.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(R.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;R.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 o={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:o,rtcOfferConstraints:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:o,rtcOfferConstraints:r,extraHeaders:t.extraHeaders}),!0}},{key:"refer",value:function(e,t){var n=this;R.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 o=new A(this);o.sendRefer(e,t);var i=o.id;return this._referSubscribers[i]=o,o.on("requestFailed",function(){delete n._referSubscribers[i]}),o.on("accepted",function(){delete n._referSubscribers[i]}),o.on("failed",function(){delete n._referSubscribers[i]}),o}},{key:"sendRequest",value:function(e,t){return R.debug("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(R.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};R.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}),R.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 o=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;o&&o.match(/^application\/dtmf-relay/i)?new S(this).init_incoming(e):void 0!==o?new C(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(){R.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(){R.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(){R.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){R.debug("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){R.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||(R.debug("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(R.debug("_isReadyToReOffer() | session not established yet"),!1):(R.debug("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(R.debug("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(R.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){R.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&&(R.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})}),R.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(R.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 R.warn('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R.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,R.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',e),n.emit("peerconnection:setlocaldescriptionfailed",e),Promise.reject(e)})}).then(function(){var o=t&&t.iceRestart;if("complete"===r.iceGatheringState&&!o||"gathering"===r.iceGatheringState&&n._iceReady){n._rtcReady=!0;var i={originator:"local",type:e,sdp:r.localDescription.sdp};return R.debug('emit "sdp"'),n.emit("sdp",i),Promise.resolve(i.sdp)}return new Promise(function(t){var o,i,s=!1;n._iceReady=!1;var l=function(){if(!s){r.removeEventListener("icecandidate",o),r.removeEventListener("icegatheringstatechange",i),s=!0,n._rtcReady=!0,n._iceReady=!0;var l={originator:"local",type:e,sdp:r.localDescription.sdp};R.debug('emit "sdp"'),n.emit("sdp",l),t(l.sdp)}};r.addEventListener("icecandidate",o=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,o="UAS"===t?e.from_tag:e.to_tag,i=e.call_id+r+o,s=this._earlyDialogs[i];if(n)return!!s||((s=new T(this,e,t,T.C.STATUS_EARLY)).error?(R.debug(s.error),this._failed("remote",e,_.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[i]=s,!0));if(this._from_tag=e.from_tag,this._to_tag=e.to_tag,s)return s.update(e,t),this._dialog=s,delete this._earlyDialogs[i],!0;var l=new T(this,e,t);return l.error?(R.debug(l.error),this._failed("remote",e,_.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;R.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]:{};o=!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)},o=!1;if(this.emit("reinvite",r),!o){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.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){R.warn(e)})}function i(t){var n=this,o=["Contact: ".concat(this._contact)];this._handleSessionTimersInIncomingRequest(e,o),this._late_sdp&&(t=this._mangleOffer(t)),e.reply(200,null,o,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.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]:{};o=!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)},o=!1;if(this.emit("update",r),!o)if(e.body){if("application/sdp"!==n)return R.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){R.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;R.debug("_processInDialogSdpOffer()");var n,r=e.parseSDP(),i=!1,s=o(r.media);try{for(s.s();!(n=s.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){s.e(e)}finally{s.f()}var a={originator:"remote",type:"offer",sdp:e.body};R.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),R.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),R.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R.warn("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var n=this;if(R.debug("receiveRefer()"),!e.refer_to)return R.debug("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==_.SIP)return R.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);R.debug('emit "refer"'),this.emit("refer",{request:e,accept:function(o,i){(function(n){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(n="function"==typeof n?n:null,this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;var i=new t(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 s=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));o.extraHeaders=v.cloneArray(o.extraHeaders),o.extraHeaders.push("Replaces: ".concat(s))}i.connect(e.refer_to.uri.toAor(),o,n)}).call(n,o,i)},reject:function(){(function(){r.notify(603)}).call(n)}})}},{key:"_receiveNotify",value:function(e){switch(R.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 n=this;R.debug("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(r){(function(n){var r=this;if(this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;var o=new t(this._ua);o.on("confirmed",function(){r.terminate()}),o.init_incoming(e,n)}).call(n,r)},reject:function(){(function(){R.debug("Replaced INVITE rejected by the user"),e.reply(486)}).call(n)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,o=new b(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),R.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,R.debug('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),o.send()}).catch(function(e){r._status!==I.STATUS_TERMINATED&&R.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;R.warn("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(R.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 R.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){R.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};R.debug('emit "sdp"'),this.emit("sdp",r);var o=new RTCSessionDescription({type:"answer",sdp:r.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._connection.setRemoteDescription(o)}).then(function(){return t._progress("remote",e)}).catch(function(e){R.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};R.debug('emit "sdp"'),this.emit("sdp",i);var s=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(s).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),R.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]:{};R.debug("sendReinvite()");var n=v.cloneArray(t.extraHeaders),r=v.cloneObject(t.eventHandlers),o=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=!1;function s(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",o)}).then(function(t){var o={originator:"local",type:"offer",sdp:t=e._mangleOffer(t)};R.debug('emit "sdp"'),e.emit("sdp",o),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 s.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void s.call(this);var n={originator:"remote",type:"answer",sdp:e.body};R.debug('emit "sdp"'),this.emit("sdp",n);var o=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._connection.setRemoteDescription(o)}).then(function(){r.succeeded&&r.succeeded(e)}).catch(function(e){s.call(t),R.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}).call(e,t),i=!0},onErrorResponse:function(t){s.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){s()})}},{key:"_sendUpdate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};R.debug("sendUpdate()");var n=v.cloneArray(t.extraHeaders),r=v.cloneObject(t.eventHandlers),o=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,s=!1;function l(e){var t=this;if(this._status!==I.STATUS_TERMINATED&&!s)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.debug('emit "sdp"'),this.emit("sdp",n);var o=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._connection.setRemoteDescription(o)}).then(function(){r.succeeded&&r.succeeded(e)}).catch(function(e){u.call(t),R.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",o)}).then(function(t){var r={originator:"local",type:"offer",sdp:t=e._mangleOffer(t)};R.debug('emit "sdp"'),e.emit("sdp",r),e.sendRequest(_.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),s=!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){R.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=h.parse(e),this._localHold&&!this._remoteHold){R.debug("mangleOffer() | me on hold, mangling offer");var t,n=o(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.debug("mangleOffer() | both on hold, mangling offer");var i,s=o(e.media);try{for(s.s();!(i=s.n()).done;){var l=i.value;-1!==O.indexOf(l.type)&&(l.direction="inactive")}}catch(e){s.e(e)}finally{s.f()}}else if(this._remoteHold){R.debug("mangleOffer() | remote on hold, mangling offer");var u,a=o(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 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>=_.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()&&(R.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&&(R.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=o(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=o(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.debug("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){R.debug("session connecting"),R.debug('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){R.debug("session progress"),R.debug('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){R.debug("session accepted"),this._start_time=new Date,R.debug('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){R.debug("session confirmed"),this._is_confirmed=!0,R.debug('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){R.debug("session ended"),this._end_time=new Date,this._close(),R.debug('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){R.debug("session failed"),R.debug('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),R.debug('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){R.debug("session onhold"),this._setLocalMediaStatus(),R.debug('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){R.debug("session onunhold"),this._setLocalMediaStatus(),R.debug('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;R.debug("session onmute"),this._setLocalMediaStatus(),R.debug('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;R.debug("session onunmute"),this._setLocalMediaStatus(),R.debug('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&s(n.prototype,r),i&&s(n,i),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,r,i}()},{"./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 o(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 o="Signal=".concat(this._tone,"\r\n");o+="Duration=".concat(this._duration),this._session.newDTMF({originator:"local",dtmf:this,request:this._request}),this._session.sendRequest(f.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:o})}},{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=p.DEFAULT_DURATION),this._tone?this._session.newDTMF({originator:"remote",dtmf:this,request:e}):_.debug("invalid INFO DTMF received, discarded")}}])&&o(n.prototype,r),i&&o(n,i),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,r,i}(),t.exports.C=p},{"../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 o(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 f.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var o=h.cloneArray(r.extraHeaders);o.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(c.INFO,{extraHeaders:o,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})}}])&&o(n.prototype,r),i&&o(n,i),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,r,i}()},{"../Constants":2,"../Exceptions":6,"../Utils":28,events:31}],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 o(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),this._session.sendRequest(l.NOTIFY,{extraHeaders:["Event: ".concat(a.event_type,";id=").concat(this._id),"Subscription-State: ".concat(n),"Content-Type: ".concat(a.body_type)],body:"SIP/2.0 ".concat(e," ").concat(t),eventHandlers:{onErrorResponse:function(){this._active=!1}}}))}}])&&o(e.prototype,t),n&&o(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n}()},{"../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 o(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:{};_.debug("sendRefer()");var r=d.cloneArray(n.extraHeaders),o=d.cloneObject(n.eventHandlers);for(var i in o)Object.prototype.hasOwnProperty.call(o,i)&&this.on(i,o[i]);var s=null;n.replaces&&(s=n.replaces._request.call_id,s+=";to-tag=".concat(n.replaces._to_tag),s+=";from-tag=".concat(n.replaces._from_tag),s=encodeURIComponent(s));var l="Refer-To: <".concat(e).concat(s?"?Replaces=".concat(s):"",">");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(f.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,f.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,f.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,f.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,f.causes.DIALOG_ERROR)}}});this._id=a.cseq}},{key:"receiveNotify",value:function(e){if(_.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 _.debug('receiveNotify() | error parsing NOTIFY body: "'.concat(e.body,'"'))}}},{key:"_requestSucceeded",value:function(e){_.debug("REFER succeeded"),_.debug('emit "requestSucceeded"'),this.emit("requestSucceeded",{response:e})}},{key:"_requestFailed",value:function(e,t){_.debug("REFER failed"),_.debug('emit "requestFailed"'),this.emit("requestFailed",{response:e||null,cause:t})}}])&&o(n.prototype,r),i&&o(n,i),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,r,i}()},{"../Constants":2,"../Grammar":7,"../Logger":9,"../Utils":28,events:31}],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 o(e,t){for(var n=0;n"'),this._contact+=";reg-id=".concat(this._reg_id),this._contact+=";+sip.instance=".concat(this._sipInstance)},(t=[{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)f.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=l.newTag();this._ua.configuration.register_from_tag_trail&&("function"==typeof this._ua.configuration.register_from_tag_trail?n+=this._ua.configuration.register_from_tag_trail():n+=this._ua.configuration.register_from_tag_trail);var r=new a.OutgoingRequest(u.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1,from_tag:n},t),o=new c(this._ua,r,{onRequestTimeout:function(){e._registrationFailure(null,u.causes.REQUEST_TIMEOUT)},onTransportError:function(){e._registrationFailure(null,u.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")){f.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){f.debug("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 i=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")},i),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._registering=!1,e.register()):(f.debug("423 response received for REGISTER without Min-Expires"),e._registrationFailure(t,u.causes.SIP_FAILURE_CODE));break;default:var s=l.sipErrorCause(t.status_code);e._registrationFailure(t,s)}}});this._registering=!0,o.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 a.OutgoingRequest(u.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},n);new c(this._ua,r,{onRequestTimeout:function(){e._unregistered(null,u.causes.REQUEST_TIMEOUT)},onTransportError:function(){e._unregistered(null,u.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=l.sipErrorCause(t.status_code);e._unregistered(t,n)}}}).send()}else f.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})}}])&&o(e.prototype,t),n&&o(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n}()},{"./Constants":2,"./Logger":9,"./RequestSender":20,"./SIPMessage":21,"./Utils":28}],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 o(e,t){for(var n=0;n=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:o}}throw 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,s=!0,l=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){l=!0,i=e},f:function(){try{s||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=Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",m.MAX_FORWARDS);var l=o.to_uri||n,u=o.to_tag?{tag:o.to_tag}:null,a=void 0!==o.to_display_name?o.to_display_name:null;this.to=new g(l,a,u),this.setHeader("to",this.to.toString());var f,h=o.from_uri||r.configuration.uri,d={tag:o.from_tag||v.newTag()};f=void 0!==o.from_display_name?o.from_display_name:r.configuration.display_name?r.configuration.display_name:null,this.from=new g(h,f,d),this.setHeader("from",this.from.toString());var _=o.call_id||r.configuration.jssip_id+v.createRandomToken(15);this.call_id=_,this.setHeader("call-id",_);var p=o.cseq||Math.floor(1e4*Math.random());this.cseq=p,this.setHeader("cseq","".concat(p," ").concat(t))}return h(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=v.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 o=y.parse(r,e.replace(/-/g,"_"));return-1===o?(this.headers[e].splice(t,1),void T.debug('error parsing "'.concat(e,'" header field with value "').concat(r,'"'))):(n.parsed=o,o)}T.debug('not so many "'.concat(e,'" headers present'))}else T.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[v.headerize(e)]=[n]}},{key:"parseSDP",value:function(e){return!e&&this.sdp?this.sdp:(this.sdp=_.parse(this.body||""),this.sdp)}},{key:"toString",value:function(){return this.data}}])}(),E=function(e){function t(e){var n;return c(this,t),(n=r(this,t)).ua=e,n.headers={},n.ruri=null,n.transport=null,n.server_transaction=null,n}return i(t,C),h(t,[{key:"reply",value:function(e,t,n,r,o,i){var s=[],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||m.REASON_PHRASE[e]||"",n=v.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===m.INVITE&&e>100&&e<=200){var c,f=u(this.getHeaders("record-route"));try{for(f.s();!(c=f.n()).done;){var h=c.value;a+="Record-Route: ".concat(h,"\r\n")}}catch(e){f.e(e)}finally{f.f()}}var d,_=u(this.getHeaders("via"));try{for(_.s();!(d=_.n()).done;){var p=d.value;a+="Via: ".concat(p,"\r\n")}}catch(e){_.e(e)}finally{_.f()}!this.to_tag&&e>100?l+=";tag=".concat(v.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 m.INVITE:this.ua.configuration.session_timers&&s.push("timer"),(this.ua.contact.pub_gruu||this.ua.contact.temp_gruu)&&s.push("gruu"),s.push("ice","replaces");break;case m.UPDATE:this.ua.configuration.session_timers&&s.push("timer"),r&&s.push("ice"),s.push("replaces")}if(s.push("outbound"),this.method===m.OPTIONS?(a+="Allow: ".concat(m.ALLOWED_METHODS,"\r\n"),a+="Accept: ".concat(m.ACCEPTED_BODY_TYPES,"\r\n")):405===e?a+="Allow: ".concat(m.ALLOWED_METHODS,"\r\n"):415===e&&(a+="Accept: ".concat(m.ACCEPTED_BODY_TYPES,"\r\n")),a+="Supported: ".concat(s,"\r\n"),r){var b=v.str_utf8_length(r);a+="Content-Type: application/sdp\r\n",a+="Content-Length: ".concat(b,"\r\n\r\n"),a+=r}else a+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,a,o,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||m.REASON_PHRASE[e]||"";var r,o="SIP/2.0 ".concat(e," ").concat(t,"\r\n"),i=u(n);try{for(i.s();!(r=i.n()).done;){var s=r.value;o+="Via: ".concat(s,"\r\n")}}catch(e){i.e(e)}finally{i.f()}var l=this.getHeader("To");if(!this.to_tag&&e>100?l+=";tag=".concat(v.newTag()):this.to_tag&&!this.s("to").hasParam("tag")&&(l+=";tag=".concat(this.to_tag)),o+="To: ".concat(l,"\r\n"),o+="From: ".concat(this.getHeader("From"),"\r\n"),o+="Call-ID: ".concat(this.call_id,"\r\n"),o+="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 f=a.value;o+="".concat(f.trim(),"\r\n")}}catch(e){c.e(e)}finally{c.f()}}o+="Content-Length: ".concat(0,"\r\n\r\n"),this.transport.send(o)}}])}(),A=function(e){function t(){var e;return c(this,t),(e=r(this,t)).headers={},e.status_code=null,e.reason_phrase=null,e}return i(t,C),h(t)}();t.exports={OutgoingRequest:b,InitialOutgoingInviteRequest:S,IncomingRequest:E,IncomingResponse:A}},{"./Constants":2,"./Grammar":7,"./Logger":9,"./NameAddrHeader":11,"./Utils":28,"sdp-transform":37}],22:[function(e,t,n){"use strict";var r=e("./Logger"),o=e("./Utils"),i=e("./Grammar"),s=new r("Socket");n.isSocket=function(e){if(Array.isArray(e))return!1;if(void 0===e)return s.warn("undefined JsSIP.Socket instance"),!1;try{if(!o.isString(e.url))throw s.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!o.isString(e.via_transport))throw s.warn("missing or invalid JsSIP.Socket via_transport property"),new Error("Missing or invalid JsSIP.Socket via_transport property");if(-1===i.parse(e.sip_uri,"SIP_URI"))throw s.warn("missing or invalid JsSIP.Socket sip_uri property"),new Error("missing or invalid JsSIP.Socket sip_uri property")}catch(e){return!1}try{["connect","disconnect","send"].forEach(function(t){if(!o.isFunction(e[t]))throw s.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 o(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()},m.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)}}}])}(),A=function(e){function t(e,n,r,i){var s;o(this,t),(s=u(this,t)).id="z9hG4bK".concat(Math.floor(1e7*Math.random())),s.transport=n,s.request=r,s.eventHandlers=i;var l="SIP/2.0/".concat(n.via_transport);return l+=" ".concat(e.configuration.via_host,";branch=").concat(s.id),s.request.setHeader("via",l),s}return c(t,h),s(t,[{key:"C",get:function(){return S}},{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()}}])}(),w=function(e){function t(e,n,r){var i;return o(this,t),(i=u(this,t)).type=S.NON_INVITE_SERVER,i.id=r.via_branch,i.ua=e,i.transport=n,i.request=r,i.last_response="",r.server_transaction=i,i.state=S.STATUS_TRYING,e.newTransaction(i),i}return c(t,h),s(t,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var o=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(){o.timer_J()},m.TIMER_J),this.transport.send(t)?n&&n():(this.onTransportError(),r&&r());break;case S.STATUS_COMPLETED:}}}])}(),R=function(e){function t(e,n,r){var i;return o(this,t),(i=u(this,t)).type=S.INVITE_SERVER,i.id=r.via_branch,i.ua=e,i.transport=n,i.request=r,i.last_response="",r.server_transaction=i,i.state=S.STATUS_PROCEEDING,e.newTransaction(i),i.resendProvisionalTimer=null,r.reply(100),i}return c(t,h),s(t,[{key:"C",get:function(){return S}},{key:"stateChanged",value:function(e){this.state=e,this.emit("stateChanged")}},{key:"timer_H",value:function(){b.debug("Timer H expired for transaction ".concat(this.id)),this.state===S.STATUS_COMPLETED&&b.debug("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(){b.debug("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,b.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(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 o=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(){o.resend_provisional()},m.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(){o.timer_L()},m.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(){o.timer_H()},m.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}])}();t.exports={C:S,NonInviteClientTransaction:C,InviteClientTransaction:E,AckClientTransaction:A,NonInviteServerTransaction:w,InviteServerTransaction:R,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case _.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()},m.TIMER_I),!0;break;case _.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,"./Logger":9,"./SIPMessage":21,"./Timers":23,events:31}],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 o(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:c.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),a.debug("new()"),this.status=c.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){a.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(!l.isSocket(e.socket))throw new TypeError("Invalid argument. invalid 'JsSIP.Socket' instance");if(e.weight&&!Number(e.weight))throw new TypeError("Invalid argument. 'weight' attribute is not a number");this.sockets.push({socket:e.socket,weight:e.weight||0,status:c.SOCKET_STATUS_READY})},this),this._getSocket()},(t=[{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(){a.debug("connect()"),this.isConnected()?a.debug("Transport is already connected"):this.isConnecting()?a.debug("Transport is connecting"):(this.close_requested=!1,this.status=c.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){a.debug("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=c.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(a.debug("send()"),!this.isConnected())return a.warn("unable to send message, transport is not connected"),!1;var t=e.toString();return a.debug("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===c.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===c.STATUS_CONNECTING}},{key:"_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),a.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!==c.SOCKET_STATUS_ERROR&&(0===e.length?e.push(t):t.weight>e[0].weight?e=[t]:t.weight===e[0].weight&&e.push(t))}),0===e.length)return this.sockets.forEach(function(e){e.status=c.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=c.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=c.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=c.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 a.debug("received binary message failed to be converted into string, message discarded")}a.debug("received binary message:\n\n".concat(e,"\n"))}else a.debug("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else a.debug("received message with CRLF Keep Alive response");else{a.debug("received message with double-CRLF Keep Alive request");try{this.socket.send("\r\n")}catch(e){a.warn("error sending Keep Alive response: ".concat(e))}}}}])&&o(e.prototype,t),n&&o(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n}()},{"./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 o(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 o in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,o)&&(-1!==r.indexOf(o)?Object.defineProperty(this._configuration,o,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,o,{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])))}}}])&&o(n.prototype,r),i&&o(n,i),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,r,i}()},{"./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){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function o(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return i(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?i(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,o=function(){};return{s:o,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,l=!0,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,s=e},f:function(){try{l||null==n.return||n.return()}finally{if(u)throw s}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},s=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 l in this._parameters={},this._headers={},this._scheme=t||u.SIP,this._user=n,this._host=r,this._port=o,i)Object.prototype.hasOwnProperty.call(i,l)&&this.setParam(l,i[l]);for(var a in s)Object.prototype.hasOwnProperty.call(s,a)&&this.setHeader(a,s[a])}return t=e,r=[{key:"parse",value:function(e){return-1!==(e=c.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[a.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[a.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(a.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=a.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(a.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 r in this._headers)if(Object.prototype.hasOwnProperty.call(this._headers,r)){var i,s=o(this._headers[r]);try{for(s.s();!(i=s.n()).done;){var l=i.value;e.push("".concat(r,"=").concat(l))}}catch(e){s.e(e)}finally{s.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(a.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&s(t.prototype,n),r&&s(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,n,r}()},{"./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 o(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return i(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?i(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,o=function(){};return{s:o,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,l=!0,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,s=e},f:function(){try{l||null==n.return||n.return()}finally{if(u)throw s}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=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,o=1073741824&e,i=1073741824&t,s=(1073741823&e)+(1073741823&t);return o&i?2147483648^s^n^r:o|i?1073741824&s?3221225472^s^n^r:1073741824^s^n^r:s^n^r}function r(e,r,o,i,s,l,u){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,o,i),s),u)),n(t(e,l),r)}function o(e,r,o,i,s,l,u){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,o,i),s),u)),n(t(e,l),r)}function i(e,r,o,i,s,l,u){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,o,i),s),u)),n(t(e,l),r)}function s(e,r,o,i,s,l,u){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,o,i),s),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,f,h,d,_,p,m,v;for(u=function(e){for(var t,n=e.length,r=n+8,o=16*((r-r%64)/64+1),i=new Array(o-1),s=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){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function o(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 s,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,s=e},f:function(){try{l||null==n.return||n.return()}finally{if(u)throw s}}}}function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n1)return h.debug("more than one Via header field present in the response, dropping the response"),!1},function(){var e=f.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=s[t]=n,++e._eventsCount;return e}function h(){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=s[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,o=m(e,r),i=0;i=0;s--)if(n[s]===t||n[s].listener===t){l=n[s].listener,i=s;break}if(i<0)return this;0===i?n.shift():function(e,t){for(var n=t,r=n+1,o=e.length;r=0;i--)this.removeListener(e,t[i]);return this},s.prototype.listeners=function(e){return _(this,e,!0)},s.prototype.rawListeners=function(e){return _(this,e,!1)},s.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):p.call(e,t)},s.prototype.listenerCount=p,s.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,o=0;e[0].replace(/%[a-zA-Z%]/g,e=>{"%%"!==e&&(r++,"%c"===e&&(o=r))}),e.splice(o,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")||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;let e;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&(e=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(e[1],10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},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:o}=t.exports;o.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,o,i,s=null;function l(...e){if(!l.enabled)return;const r=l,o=Number(new Date),i=o-(t||o);r.diff=i,r.prev=t,r.curr=o,t=o,e[0]=n.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let s=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,(t,o)=>{if("%%"===t)return"%";s++;const i=n.formatters[o];if("function"==typeof i){const n=e[s];t=i.call(r,n),e.splice(s,1),s--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return l.namespace=e,l.useColors=n.useColors(),l.color=n.selectColor(e),l.extend=r,l.destroy=n.destroy,Object.defineProperty(l,"enabled",{enumerable:!0,configurable:!1,get:()=>null!==s?s:(o!==n.namespaces&&(o=n.namespaces,i=n.enabled(e)),i),set:e=>{s=e}}),"function"==typeof n.init&&n.init(l),l}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function o(e,t){let n=0,r=0,o=-1,i=0;for(;n"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){n.save(e),n.namespaces=e,n.names=[],n.skips=[];const t=("string"==typeof e?e:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(const e of t)"-"===e[0]?n.skips.push(e.slice(1)):n.names.push(e)},n.enabled=function(e){for(const t of n.skips)if(o(e,t))return!1;for(const t of n.names)if(o(e,t))return!0;return!1},n.humanize=e("ms"),n.destroy=function(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")},Object.keys(t).forEach(e=>{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+(o?"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*s;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*o;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>=s)return a(e,t,s,"day");if(t>=i)return a(e,t,i,"hour");if(t>=o)return a(e,t,o,"minute");if(t>=r)return a(e,t,r,"second");return e+" ms"}(e):function(e){var t=Math.abs(e);if(t>=s)return Math.round(e/s)+"d";if(t>=i)return Math.round(e/i)+"h";if(t>=o)return Math.round(e/o)+"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,o,i=t.exports={};function s(){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===s||!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:s}catch(e){r=s}try{o="function"==typeof clearTimeout?clearTimeout:l}catch(e){o=l}}();var a,c=[],f=!1,h=-1;function d(){f&&a&&(f=!1,a.length?c=a.concat(c):h=-1,c.length&&_())}function _(){if(!f){var e=u(d);f=!0;for(var t=c.length;t;){for(a=c,c=[];++h1)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),o=0;o=r)return e;var o=n[t];switch(t+=1,e){case"%%":return"%";case"%s":return String(o);case"%d":return Number(o);case"%v":return""}})}.apply(null,r)},s=["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||s,o=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)),o.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 +!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 i(s,l){if(!n[s]){if(!t[s]){var u="function"==typeof require&&require;if(!l&&u)return u(s,!0);if(o)return o(s,!0);var a=new Error("Cannot find module '"+s+"'");throw a.code="MODULE_NOT_FOUND",a}var c=n[s]={exports:{}};t[s][0].call(c.exports,function(e){return i(t[s][1][e]||e)},c,c.exports,e,t,n,r)}return n[s].exports}for(var o="function"==typeof require&&require,s=0;s=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,l=!0,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,s=e},f:function(){try{l||null==n.return||n.return()}finally{if(u)throw s}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n0)return t}},connection_recovery_min_interval:function(e){if(o.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(o.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())===s.INVITE||e===s.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(o.isDecimal(e)){var t=Number(e);if(t>0)return t}},register_from_tag_trail:function(e){return"function"==typeof e?e:String(e)},registrar_server:function(e){/^sip:/i.test(e)||(e="".concat(s.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,i=r(e);try{for(i.s();!(n=i.n()).done;){var o=n.value;"string"==typeof o&&t.push(o)}}catch(e){i.e(e)}finally{i.f()}return t}}}};n.load=function(e,t){for(var n in f.mandatory){if(!t.hasOwnProperty(n))throw new c.ConfigurationError(n);var r=t[n],i=f.mandatory[n](r);if(void 0===i)throw new c.ConfigurationError(n,r);e[n]=i}for(var s in f.optional)if(t.hasOwnProperty(s)){var l=t[s];if(o.isEmpty(l))continue;var u=f.optional[s](l);if(void 0===u)throw new c.ConfigurationError(s,l);e[s]=u}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":23,"./URI":29,"./Utils":30}],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":42}],3:[function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function i(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 l.IncomingResponse&&(i=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=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),d.debug("new ".concat(r," dialog created with status ").concat(this._state===h.STATUS_EARLY?"EARLY":"CONFIRMED"))},n=[{key:"C",get:function(){return h}}],(t=[{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:"isTerminated",value:function(){return this._status===h.STATUS_TERMINATED}},{key:"update",value:function(e,t){this._state=h.STATUS_CONFIRMED,d.debug("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){d.debug("dialog ".concat(this._id.toString()," deleted")),this._ua.destroyDialog(this),this._state=h.STATUS_TERMINATED}},{key:"sendRequest",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=f.cloneArray(n.extraHeaders),i=f.cloneObject(n.eventHandlers),o=n.body||null,s=this._createRequest(e,r,o);return i.onAuthenticated=function(){t._local_seqnum+=1},new c(this,s,i).send(),s}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===u.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===u.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=f.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===u.CANCEL||e===u.ACK?this._local_seqnum:this._local_seqnum+=1;return new l.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===u.INVITE||e.method===u.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;var r=function(){e.server_transaction.state!==a.C.STATUS_ACCEPTED&&e.server_transaction.state!==a.C.STATUS_COMPLETED&&e.server_transaction.state!==a.C.STATUS_TERMINATED||(e.server_transaction.removeListener("stateChanged",r),t._uas_pending_reply=!1)};e.server_transaction.on("stateChanged",r)}e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===a.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===u.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===a.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}}])&&i(e.prototype,t),n&&i(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n}()},{"./Constants":2,"./Dialog/RequestSender":4,"./Logger":9,"./SIPMessage":22,"./Transactions":26,"./Utils":30}],4:[function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function i(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)}}])&&i(e.prototype,t),n&&i(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n}()},{"../Constants":2,"../RequestSender":21,"../Transactions":26}],5:[function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function i(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 u.warn('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'),!1}else this._algorithm="MD5";if(!this._nonce)return u.warn("authenticate() | challenge without Digest nonce, authentication aborted"),!1;if(!this._realm)return u.warn("authenticate() | challenge without Digest realm, authentication aborted"),!1;if(!this._credentials.password){if(!this._credentials.ha1)return u.warn("authenticate() | no plain SIP password nor ha1 provided, authentication aborted"),!1;if(this._credentials.realm!==this._realm)return u.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 u.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=o||l.createRandomToken(12),this._nc+=1;var s,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=l.calculateMD5("".concat(this._credentials.username,":").concat(this._realm,":").concat(this._credentials.password)):this._ha1=this._credentials.ha1,"auth"===this._qop?(s="".concat(this._method,":").concat(this._uri),a=l.calculateMD5(s),u.debug('authenticate() | using qop=auth [a2:"%s"]',s),this._response=l.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(a))):"auth-int"===this._qop?(s="".concat(this._method,":").concat(this._uri,":").concat(l.calculateMD5(i||"")),a=l.calculateMD5(s),u.debug('authenticate() | using qop=auth-int [a2:"%s"]',s),this._response=l.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(a))):null===this._qop&&(s="".concat(this._method,":").concat(this._uri),a=l.calculateMD5(s),u.debug('authenticate() | using qop=null [a2:"%s"]',s),this._response=l.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(a))),u.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(", "))}}])&&i(e.prototype,t),n&&i(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n}()},{"./Logger":9,"./Utils":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 i(e,t){for(var n=0;n",o++):(e=null,0===s&&a('">"')),null===e&&(64===n.charCodeAt(o)?(e="@",o++):(e=null,0===s&&a('"@"')),null===e&&(44===n.charCodeAt(o)?(e=",",o++):(e=null,0===s&&a('","')),null===e&&(59===n.charCodeAt(o)?(e=";",o++):(e=null,0===s&&a('";"')),null===e&&(58===n.charCodeAt(o)?(e=":",o++):(e=null,0===s&&a('":"')),null===e&&(92===n.charCodeAt(o)?(e="\\",o++):(e=null,0===s&&a('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(o)?(e="/",o++):(e=null,0===s&&a('"/"')),null===e&&(91===n.charCodeAt(o)?(e="[",o++):(e=null,0===s&&a('"["')),null===e&&(93===n.charCodeAt(o)?(e="]",o++):(e=null,0===s&&a('"]"')),null===e&&(63===n.charCodeAt(o)?(e="?",o++):(e=null,0===s&&a('"?"')),null===e&&(61===n.charCodeAt(o)?(e="=",o++):(e=null,0===s&&a('"="')),null===e&&(123===n.charCodeAt(o)?(e="{",o++):(e=null,0===s&&a('"{"')),null===e&&(125===n.charCodeAt(o)?(e="}",o++):(e=null,0===s&&a('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:U,STAR:x,SLASH:D,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:j,COMMA:F,SEMI:B,COLON:G,LDQUOT:V,RDQUOT:W,comment:function e(){var t,n,r;var i;i=o;t=q();if(null!==t){for(n=[],null===(r=Y())&&null===(r=X())&&(r=e());null!==r;)n.push(r),null===(r=Y())&&null===(r=X())&&(r=e());null!==n&&null!==(r=L())?t=[t,n,r]:(t=null,o=i)}else t=null,o=i;return t},ctext:Y,quoted_string:K,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:ie,password:oe,hostport:se,host:le,hostname:ue,domainlabel:ae,toplabel:ce,IPv6reference:fe,IPv6address:de,h16:he,ls32:_e,IPv4address:pe,dec_octet:me,port:ve,uri_parameters:ge,uri_parameter:ye,transport_param:Te,user_param:be,method_param:Se,ttl_param:Ee,maddr_param:Ce,lr_param:Ae,other_param:we,pname:Re,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:Pe,hname:Ue,hvalue:xe,hnv_unreserved:De,Request_Response:function(){var e;null===(e=ft())&&(e=Me());return e},Request_Line:Me,Request_URI:qe,absoluteURI:Le,hier_part:He,net_path:je,abs_path:Fe,opaque_part:Be,uric:Ge,uric_no_slash:Ve,path_segments:We,segment:Ye,param:Ke,pchar:ze,scheme:$e,authority:Xe,srvr:Je,reg_name:Qe,query:Ze,SIP_Version:et,INVITEm:tt,ACKm:nt,OPTIONSm:rt,BYEm:it,CANCELm:ot,REGISTERm:st,SUBSCRIBEm:lt,NOTIFYm:ut,REFERm:at,Method:ct,Status_Line:ft,Status_Code:dt,extension_code:ht,Reason_Phrase:_t,Allow_Events:function(){var e,t,n,r,i,s;if(i=o,null!==(e=Lt())){for(t=[],s=o,null!==(n=F())&&null!==(r=Lt())?n=[n,r]:(n=null,o=s);null!==n;)t.push(n),s=o,null!==(n=F())&&null!==(r=Lt())?n=[n,r]:(n=null,o=s);null!==t?e=[e,t]:(e=null,o=i)}else e=null,o=i;return e},Call_ID:function(){var e,t,r,i,l,u;i=o,l=o,null!==(e=U())?(u=o,64===n.charCodeAt(o)?(t="@",o++):(t=null,0===s&&a('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,o=u),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,o=l)):(e=null,o=l);null!==e&&(c=i,e=void(Fn=n.substring(o,c)));var c;null===e&&(o=i);return e},Contact:function(){var e,t,n,r,i,s,l;if(i=o,null===(e=x()))if(s=o,null!==(e=pt())){for(t=[],l=o,null!==(n=F())&&null!==(r=pt())?n=[n,r]:(n=null,o=l);null!==n;)t.push(n),l=o,null!==(n=F())&&null!==(r=pt())?n=[n,r]:(n=null,o=l);null!==t?e=[e,t]:(e=null,o=s)}else e=null,o=s;null!==e&&(e=function(e){var t,n;for(n=Fn.multi_header.length,t=0;tl&&(l=o,u=[]),u.push(e))}function c(){var e;return"\r\n"===n.substr(o,2)?(e="\r\n",o+=2):(e=null,0===s&&a('"\\r\\n"')),e}function f(){var e;return/^[0-9]/.test(n.charAt(o))?(e=n.charAt(o),o++):(e=null,0===s&&a("[0-9]")),e}function d(){var e;return/^[a-zA-Z]/.test(n.charAt(o))?(e=n.charAt(o),o++):(e=null,0===s&&a("[a-zA-Z]")),e}function h(){var e;return/^[0-9a-fA-F]/.test(n.charAt(o))?(e=n.charAt(o),o++):(e=null,0===s&&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(o))?(e=n.charAt(o),o++):(e=null,0===s&&a("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(o))?(e=n.charAt(o),o++):(e=null,0===s&&a('["]')),e}function v(){var e;return 32===n.charCodeAt(o)?(e=" ",o++):(e=null,0===s&&a('" "')),e}function g(){var e;return 9===n.charCodeAt(o)?(e="\t",o++):(e=null,0===s&&a('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(o))?(e=n.charAt(o),o++):(e=null,0===s&&a("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(o)?(e=";",o++):(e=null,0===s&&a('";"')),null===e&&(47===n.charCodeAt(o)?(e="/",o++):(e=null,0===s&&a('"/"')),null===e&&(63===n.charCodeAt(o)?(e="?",o++):(e=null,0===s&&a('"?"')),null===e&&(58===n.charCodeAt(o)?(e=":",o++):(e=null,0===s&&a('":"')),null===e&&(64===n.charCodeAt(o)?(e="@",o++):(e=null,0===s&&a('"@"')),null===e&&(38===n.charCodeAt(o)?(e="&",o++):(e=null,0===s&&a('"&"')),null===e&&(61===n.charCodeAt(o)?(e="=",o++):(e=null,0===s&&a('"="')),null===e&&(43===n.charCodeAt(o)?(e="+",o++):(e=null,0===s&&a('"+"')),null===e&&(36===n.charCodeAt(o)?(e="$",o++):(e=null,0===s&&a('"$"')),null===e&&(44===n.charCodeAt(o)?(e=",",o++):(e=null,0===s&&a('","'))))))))))),e}function b(){var e;return null===(e=y())&&(e=S()),e}function S(){var e;return 45===n.charCodeAt(o)?(e="-",o++):(e=null,0===s&&a('"-"')),null===e&&(95===n.charCodeAt(o)?(e="_",o++):(e=null,0===s&&a('"_"')),null===e&&(46===n.charCodeAt(o)?(e=".",o++):(e=null,0===s&&a('"."')),null===e&&(33===n.charCodeAt(o)?(e="!",o++):(e=null,0===s&&a('"!"')),null===e&&(126===n.charCodeAt(o)?(e="~",o++):(e=null,0===s&&a('"~"')),null===e&&(42===n.charCodeAt(o)?(e="*",o++):(e=null,0===s&&a('"*"')),null===e&&(39===n.charCodeAt(o)?(e="'",o++):(e=null,0===s&&a('"\'"')),null===e&&(40===n.charCodeAt(o)?(e="(",o++):(e=null,0===s&&a('"("')),null===e&&(41===n.charCodeAt(o)?(e=")",o++):(e=null,0===s&&a('")"')))))))))),e}function E(){var e,t,r,i,l;return i=o,l=o,37===n.charCodeAt(o)?(e="%",o++):(e=null,0===s&&a('"%"')),null!==e&&null!==(t=h())&&null!==(r=h())?e=[e,t,r]:(e=null,o=l),null!==e&&(e=e.join("")),null===e&&(o=i),e}function C(){var e,t,n,r,i,s;for(r=o,i=o,s=o,e=[],t=_();null!==t;)e.push(t),t=_();if(null!==e&&null!==(t=c())?e=[e,t]:(e=null,o=s),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,o=i)}else e=null,o=i;return null!==e&&(e=" "),null===e&&(o=r),e}function A(){var e;return e=null!==(e=C())?e:""}function w(){var e,t,r,i,l;for(i=o,l=o,e=[],null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=v())&&(t=g());return null!==e?(58===n.charCodeAt(o)?(t=":",o++):(t=null,0===s&&a('":"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,o=l)):(e=null,o=l),null!==e&&(e=":"),null===e&&(o=i),e}function R(){var e,t,r,i,s,l,u,a;if(s=o,l=o,null!==(t=I()))for(e=[];null!==t;)e.push(t),t=I();else e=null;if(null!==e){for(t=[],u=o,r=[],i=C();null!==i;)r.push(i),i=C();for(null!==r&&null!==(i=I())?r=[r,i]:(r=null,o=u);null!==r;){for(t.push(r),u=o,r=[],i=C();null!==i;)r.push(i),i=C();null!==r&&null!==(i=I())?r=[r,i]:(r=null,o=u)}null!==t?e=[e,t]:(e=null,o=l)}else e=null,o=l;return null!==e&&(a=s,e=n.substring(o,a)),null===e&&(o=s),e}function I(){var e;return/^[!-~]/.test(n.charAt(o))?(e=n.charAt(o),o++):(e=null,0===s&&a("[!-~]")),null===e&&(e=O()),e}function O(){var e;return/^[\x80-\uFFFF]/.test(n.charAt(o))?(e=n.charAt(o),o++):(e=null,0===s&&a("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(o))?(e=n.charAt(o),o++):(e=null,0===s&&a("[\\x80-\\xBF]")),e}function k(){var e,t,r,i;if(r=o,null===(t=y())&&(45===n.charCodeAt(o)?(t="-",o++):(t=null,0===s&&a('"-"')),null===t&&(46===n.charCodeAt(o)?(t=".",o++):(t=null,0===s&&a('"."')),null===t&&(33===n.charCodeAt(o)?(t="!",o++):(t=null,0===s&&a('"!"')),null===t&&(37===n.charCodeAt(o)?(t="%",o++):(t=null,0===s&&a('"%"')),null===t&&(42===n.charCodeAt(o)?(t="*",o++):(t=null,0===s&&a('"*"')),null===t&&(95===n.charCodeAt(o)?(t="_",o++):(t=null,0===s&&a('"_"')),null===t&&(43===n.charCodeAt(o)?(t="+",o++):(t=null,0===s&&a('"+"')),null===t&&(96===n.charCodeAt(o)?(t="`",o++):(t=null,0===s&&a('"`"')),null===t&&(39===n.charCodeAt(o)?(t="'",o++):(t=null,0===s&&a('"\'"')),null===t&&(126===n.charCodeAt(o)?(t="~",o++):(t=null,0===s&&a('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(o)?(t="-",o++):(t=null,0===s&&a('"-"')),null===t&&(46===n.charCodeAt(o)?(t=".",o++):(t=null,0===s&&a('"."')),null===t&&(33===n.charCodeAt(o)?(t="!",o++):(t=null,0===s&&a('"!"')),null===t&&(37===n.charCodeAt(o)?(t="%",o++):(t=null,0===s&&a('"%"')),null===t&&(42===n.charCodeAt(o)?(t="*",o++):(t=null,0===s&&a('"*"')),null===t&&(95===n.charCodeAt(o)?(t="_",o++):(t=null,0===s&&a('"_"')),null===t&&(43===n.charCodeAt(o)?(t="+",o++):(t=null,0===s&&a('"+"')),null===t&&(96===n.charCodeAt(o)?(t="`",o++):(t=null,0===s&&a('"`"')),null===t&&(39===n.charCodeAt(o)?(t="'",o++):(t=null,0===s&&a('"\'"')),null===t&&(126===n.charCodeAt(o)?(t="~",o++):(t=null,0===s&&a('"~"'))))))))))));else e=null;return null!==e&&(i=r,e=n.substring(o,i)),null===e&&(o=r),e}function P(){var e,t,r,i;if(r=o,null===(t=y())&&(45===n.charCodeAt(o)?(t="-",o++):(t=null,0===s&&a('"-"')),null===t&&(33===n.charCodeAt(o)?(t="!",o++):(t=null,0===s&&a('"!"')),null===t&&(37===n.charCodeAt(o)?(t="%",o++):(t=null,0===s&&a('"%"')),null===t&&(42===n.charCodeAt(o)?(t="*",o++):(t=null,0===s&&a('"*"')),null===t&&(95===n.charCodeAt(o)?(t="_",o++):(t=null,0===s&&a('"_"')),null===t&&(43===n.charCodeAt(o)?(t="+",o++):(t=null,0===s&&a('"+"')),null===t&&(96===n.charCodeAt(o)?(t="`",o++):(t=null,0===s&&a('"`"')),null===t&&(39===n.charCodeAt(o)?(t="'",o++):(t=null,0===s&&a('"\'"')),null===t&&(126===n.charCodeAt(o)?(t="~",o++):(t=null,0===s&&a('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(o)?(t="-",o++):(t=null,0===s&&a('"-"')),null===t&&(33===n.charCodeAt(o)?(t="!",o++):(t=null,0===s&&a('"!"')),null===t&&(37===n.charCodeAt(o)?(t="%",o++):(t=null,0===s&&a('"%"')),null===t&&(42===n.charCodeAt(o)?(t="*",o++):(t=null,0===s&&a('"*"')),null===t&&(95===n.charCodeAt(o)?(t="_",o++):(t=null,0===s&&a('"_"')),null===t&&(43===n.charCodeAt(o)?(t="+",o++):(t=null,0===s&&a('"+"')),null===t&&(96===n.charCodeAt(o)?(t="`",o++):(t=null,0===s&&a('"`"')),null===t&&(39===n.charCodeAt(o)?(t="'",o++):(t=null,0===s&&a('"\'"')),null===t&&(126===n.charCodeAt(o)?(t="~",o++):(t=null,0===s&&a('"~"')))))))))));else e=null;return null!==e&&(i=r,e=n.substring(o,i)),null===e&&(o=r),e}function U(){var e,t,r,i;if(r=o,null===(t=y())&&(45===n.charCodeAt(o)?(t="-",o++):(t=null,0===s&&a('"-"')),null===t&&(46===n.charCodeAt(o)?(t=".",o++):(t=null,0===s&&a('"."')),null===t&&(33===n.charCodeAt(o)?(t="!",o++):(t=null,0===s&&a('"!"')),null===t&&(37===n.charCodeAt(o)?(t="%",o++):(t=null,0===s&&a('"%"')),null===t&&(42===n.charCodeAt(o)?(t="*",o++):(t=null,0===s&&a('"*"')),null===t&&(95===n.charCodeAt(o)?(t="_",o++):(t=null,0===s&&a('"_"')),null===t&&(43===n.charCodeAt(o)?(t="+",o++):(t=null,0===s&&a('"+"')),null===t&&(96===n.charCodeAt(o)?(t="`",o++):(t=null,0===s&&a('"`"')),null===t&&(39===n.charCodeAt(o)?(t="'",o++):(t=null,0===s&&a('"\'"')),null===t&&(126===n.charCodeAt(o)?(t="~",o++):(t=null,0===s&&a('"~"')),null===t&&(40===n.charCodeAt(o)?(t="(",o++):(t=null,0===s&&a('"("')),null===t&&(41===n.charCodeAt(o)?(t=")",o++):(t=null,0===s&&a('")"')),null===t&&(60===n.charCodeAt(o)?(t="<",o++):(t=null,0===s&&a('"<"')),null===t&&(62===n.charCodeAt(o)?(t=">",o++):(t=null,0===s&&a('">"')),null===t&&(58===n.charCodeAt(o)?(t=":",o++):(t=null,0===s&&a('":"')),null===t&&(92===n.charCodeAt(o)?(t="\\",o++):(t=null,0===s&&a('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(o)?(t="/",o++):(t=null,0===s&&a('"/"')),null===t&&(91===n.charCodeAt(o)?(t="[",o++):(t=null,0===s&&a('"["')),null===t&&(93===n.charCodeAt(o)?(t="]",o++):(t=null,0===s&&a('"]"')),null===t&&(63===n.charCodeAt(o)?(t="?",o++):(t=null,0===s&&a('"?"')),null===t&&(123===n.charCodeAt(o)?(t="{",o++):(t=null,0===s&&a('"{"')),null===t&&(125===n.charCodeAt(o)?(t="}",o++):(t=null,0===s&&a('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(o)?(t="-",o++):(t=null,0===s&&a('"-"')),null===t&&(46===n.charCodeAt(o)?(t=".",o++):(t=null,0===s&&a('"."')),null===t&&(33===n.charCodeAt(o)?(t="!",o++):(t=null,0===s&&a('"!"')),null===t&&(37===n.charCodeAt(o)?(t="%",o++):(t=null,0===s&&a('"%"')),null===t&&(42===n.charCodeAt(o)?(t="*",o++):(t=null,0===s&&a('"*"')),null===t&&(95===n.charCodeAt(o)?(t="_",o++):(t=null,0===s&&a('"_"')),null===t&&(43===n.charCodeAt(o)?(t="+",o++):(t=null,0===s&&a('"+"')),null===t&&(96===n.charCodeAt(o)?(t="`",o++):(t=null,0===s&&a('"`"')),null===t&&(39===n.charCodeAt(o)?(t="'",o++):(t=null,0===s&&a('"\'"')),null===t&&(126===n.charCodeAt(o)?(t="~",o++):(t=null,0===s&&a('"~"')),null===t&&(40===n.charCodeAt(o)?(t="(",o++):(t=null,0===s&&a('"("')),null===t&&(41===n.charCodeAt(o)?(t=")",o++):(t=null,0===s&&a('")"')),null===t&&(60===n.charCodeAt(o)?(t="<",o++):(t=null,0===s&&a('"<"')),null===t&&(62===n.charCodeAt(o)?(t=">",o++):(t=null,0===s&&a('">"')),null===t&&(58===n.charCodeAt(o)?(t=":",o++):(t=null,0===s&&a('":"')),null===t&&(92===n.charCodeAt(o)?(t="\\",o++):(t=null,0===s&&a('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(o)?(t="/",o++):(t=null,0===s&&a('"/"')),null===t&&(91===n.charCodeAt(o)?(t="[",o++):(t=null,0===s&&a('"["')),null===t&&(93===n.charCodeAt(o)?(t="]",o++):(t=null,0===s&&a('"]"')),null===t&&(63===n.charCodeAt(o)?(t="?",o++):(t=null,0===s&&a('"?"')),null===t&&(123===n.charCodeAt(o)?(t="{",o++):(t=null,0===s&&a('"{"')),null===t&&(125===n.charCodeAt(o)?(t="}",o++):(t=null,0===s&&a('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(i=r,e=n.substring(o,i)),null===e&&(o=r),e}function x(){var e,t,r,i,l;return i=o,l=o,null!==(e=A())?(42===n.charCodeAt(o)?(t="*",o++):(t=null,0===s&&a('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,o=l)):(e=null,o=l),null!==e&&(e="*"),null===e&&(o=i),e}function D(){var e,t,r,i,l;return i=o,l=o,null!==(e=A())?(47===n.charCodeAt(o)?(t="/",o++):(t=null,0===s&&a('"/"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,o=l)):(e=null,o=l),null!==e&&(e="/"),null===e&&(o=i),e}function M(){var e,t,r,i,l;return i=o,l=o,null!==(e=A())?(61===n.charCodeAt(o)?(t="=",o++):(t=null,0===s&&a('"="')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,o=l)):(e=null,o=l),null!==e&&(e="="),null===e&&(o=i),e}function q(){var e,t,r,i,l;return i=o,l=o,null!==(e=A())?(40===n.charCodeAt(o)?(t="(",o++):(t=null,0===s&&a('"("')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,o=l)):(e=null,o=l),null!==e&&(e="("),null===e&&(o=i),e}function L(){var e,t,r,i,l;return i=o,l=o,null!==(e=A())?(41===n.charCodeAt(o)?(t=")",o++):(t=null,0===s&&a('")"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,o=l)):(e=null,o=l),null!==e&&(e=")"),null===e&&(o=i),e}function H(){var e,t,r,i;return r=o,i=o,62===n.charCodeAt(o)?(e=">",o++):(e=null,0===s&&a('">"')),null!==e&&null!==(t=A())?e=[e,t]:(e=null,o=i),null!==e&&(e=">"),null===e&&(o=r),e}function j(){var e,t,r,i;return r=o,i=o,null!==(e=A())?(60===n.charCodeAt(o)?(t="<",o++):(t=null,0===s&&a('"<"')),null!==t?e=[e,t]:(e=null,o=i)):(e=null,o=i),null!==e&&(e="<"),null===e&&(o=r),e}function F(){var e,t,r,i,l;return i=o,l=o,null!==(e=A())?(44===n.charCodeAt(o)?(t=",",o++):(t=null,0===s&&a('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,o=l)):(e=null,o=l),null!==e&&(e=","),null===e&&(o=i),e}function B(){var e,t,r,i,l;return i=o,l=o,null!==(e=A())?(59===n.charCodeAt(o)?(t=";",o++):(t=null,0===s&&a('";"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,o=l)):(e=null,o=l),null!==e&&(e=";"),null===e&&(o=i),e}function G(){var e,t,r,i,l;return i=o,l=o,null!==(e=A())?(58===n.charCodeAt(o)?(t=":",o++):(t=null,0===s&&a('":"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,o=l)):(e=null,o=l),null!==e&&(e=":"),null===e&&(o=i),e}function V(){var e,t,n,r;return n=o,r=o,null!==(e=A())&&null!==(t=m())?e=[e,t]:(e=null,o=r),null!==e&&(e='"'),null===e&&(o=n),e}function W(){var e,t,n,r;return n=o,r=o,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,o=r),null!==e&&(e='"'),null===e&&(o=n),e}function Y(){var e;return/^[!-']/.test(n.charAt(o))?(e=n.charAt(o),o++):(e=null,0===s&&a("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(o))?(e=n.charAt(o),o++):(e=null,0===s&&a("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(o))?(e=n.charAt(o),o++):(e=null,0===s&&a("[\\]-~]")),null===e&&null===(e=O())&&(e=C()))),e}function K(){var e,t,r,i,s,l,u;if(s=o,l=o,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(i=$())&&(i=X());null!==i;)r.push(i),null===(i=$())&&(i=X());null!==r&&null!==(i=m())?e=[e,t,r,i]:(e=null,o=l)}else e=null,o=l;else e=null,o=l;return null!==e&&(u=s,e=n.substring(o,u)),null===e&&(o=s),e}function z(){var e,t,r,i,s,l,u,a;if(s=o,l=o,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(i=$())&&(i=X());null!==i;)r.push(i),null===(i=$())&&(i=X());null!==r&&null!==(i=m())?e=[e,t,r,i]:(e=null,o=l)}else e=null,o=l;else e=null,o=l;return null!==e&&(u=s,e=(a=n.substring(o,u).trim()).substring(1,a.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(o=s),e}function $(){var e;return null===(e=C())&&(33===n.charCodeAt(o)?(e="!",o++):(e=null,0===s&&a('"!"')),null===e&&(/^[#-[]/.test(n.charAt(o))?(e=n.charAt(o),o++):(e=null,0===s&&a("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(o))?(e=n.charAt(o),o++):(e=null,0===s&&a("[\\]-~]")),null===e&&(e=O())))),e}function X(){var e,t,r;return r=o,92===n.charCodeAt(o)?(e="\\",o++):(e=null,0===s&&a('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(o))?(t=n.charAt(o),o++):(t=null,0===s&&a("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(o))?(t=n.charAt(o),o++):(t=null,0===s&&a("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(o))?(t=n.charAt(o),o++):(t=null,0===s&&a("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,o=r)):(e=null,o=r),e}function J(){var e,t,r,i,l,u;return l=o,u=o,null!==(e=Z())?(58===n.charCodeAt(o)?(t=":",o++):(t=null,0===s&&a('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(i=se())?e=[e,t,r,i]:(e=null,o=u)):(e=null,o=u),null!==e&&(e=function(e){try{Fn.uri=new Hn(Fn.scheme,Fn.user,Fn.host,Fn.port),delete Fn.scheme,delete Fn.user,delete Fn.host,delete Fn.host_type,delete Fn.port}catch(e){Fn=-1}}()),null===e&&(o=l),e}function Q(){var e,t,i,l,u,c,f,d;return f=o,d=o,null!==(e=Z())?(58===n.charCodeAt(o)?(t=":",o++):(t=null,0===s&&a('":"')),null!==t&&null!==(i=null!==(i=ne())?i:"")&&null!==(l=se())&&null!==(u=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,i,l,u,c]:(e=null,o=d)):(e=null,o=d),null!==e&&(e=function(e){try{Fn.uri=new Hn(Fn.scheme,Fn.user,Fn.host,Fn.port,Fn.uri_params,Fn.uri_headers),delete Fn.scheme,delete Fn.user,delete Fn.host,delete Fn.host_type,delete Fn.port,delete Fn.uri_params,"SIP_URI"===r&&(Fn=Fn.uri)}catch(e){Fn=-1}}()),null===e&&(o=f),e}function Z(){var e;return null===(e=ee())&&(e=te()),e}function ee(){var e,t,r;return t=o,"sips"===n.substr(o,4).toLowerCase()?(e=n.substr(o,4),o+=4):(e=null,0===s&&a('"sips"')),null!==e&&(r=e,e=void(Fn.scheme=r.toLowerCase())),null===e&&(o=t),e}function te(){var e,t,r;return t=o,"sip"===n.substr(o,3).toLowerCase()?(e=n.substr(o,3),o+=3):(e=null,0===s&&a('"sip"')),null!==e&&(r=e,e=void(Fn.scheme=r.toLowerCase())),null===e&&(o=t),e}function ne(){var e,t,r,i,l,u,c;return i=o,l=o,null!==(e=re())?(u=o,58===n.charCodeAt(o)?(t=":",o++):(t=null,0===s&&a('":"')),null!==t&&null!==(r=oe())?t=[t,r]:(t=null,o=u),null!==(t=null!==t?t:"")?(64===n.charCodeAt(o)?(r="@",o++):(r=null,0===s&&a('"@"')),null!==r?e=[e,t,r]:(e=null,o=l)):(e=null,o=l)):(e=null,o=l),null!==e&&(c=i,e=void(Fn.user=decodeURIComponent(n.substring(o-1,c)))),null===e&&(o=i),e}function re(){var e,t;if(null===(t=b())&&null===(t=E())&&(t=ie()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=b())&&null===(t=E())&&(t=ie());else e=null;return e}function ie(){var e;return 38===n.charCodeAt(o)?(e="&",o++):(e=null,0===s&&a('"&"')),null===e&&(61===n.charCodeAt(o)?(e="=",o++):(e=null,0===s&&a('"="')),null===e&&(43===n.charCodeAt(o)?(e="+",o++):(e=null,0===s&&a('"+"')),null===e&&(36===n.charCodeAt(o)?(e="$",o++):(e=null,0===s&&a('"$"')),null===e&&(44===n.charCodeAt(o)?(e=",",o++):(e=null,0===s&&a('","')),null===e&&(59===n.charCodeAt(o)?(e=";",o++):(e=null,0===s&&a('";"')),null===e&&(63===n.charCodeAt(o)?(e="?",o++):(e=null,0===s&&a('"?"')),null===e&&(47===n.charCodeAt(o)?(e="/",o++):(e=null,0===s&&a('"/"'))))))))),e}function oe(){var e,t,r,i;for(r=o,e=[],null===(t=b())&&null===(t=E())&&(38===n.charCodeAt(o)?(t="&",o++):(t=null,0===s&&a('"&"')),null===t&&(61===n.charCodeAt(o)?(t="=",o++):(t=null,0===s&&a('"="')),null===t&&(43===n.charCodeAt(o)?(t="+",o++):(t=null,0===s&&a('"+"')),null===t&&(36===n.charCodeAt(o)?(t="$",o++):(t=null,0===s&&a('"$"')),null===t&&(44===n.charCodeAt(o)?(t=",",o++):(t=null,0===s&&a('","')))))));null!==t;)e.push(t),null===(t=b())&&null===(t=E())&&(38===n.charCodeAt(o)?(t="&",o++):(t=null,0===s&&a('"&"')),null===t&&(61===n.charCodeAt(o)?(t="=",o++):(t=null,0===s&&a('"="')),null===t&&(43===n.charCodeAt(o)?(t="+",o++):(t=null,0===s&&a('"+"')),null===t&&(36===n.charCodeAt(o)?(t="$",o++):(t=null,0===s&&a('"$"')),null===t&&(44===n.charCodeAt(o)?(t=",",o++):(t=null,0===s&&a('","')))))));return null!==e&&(i=r,e=void(Fn.password=n.substring(o,i))),null===e&&(o=r),e}function se(){var e,t,r,i,l;return i=o,null!==(e=le())?(l=o,58===n.charCodeAt(o)?(t=":",o++):(t=null,0===s&&a('":"')),null!==t&&null!==(r=ve())?t=[t,r]:(t=null,o=l),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,o=i)):(e=null,o=i),e}function le(){var e,t,r;return t=o,null===(e=ue())&&null===(e=pe())&&(e=fe()),null!==e&&(r=t,Fn.host=n.substring(o,r).toLowerCase(),e=Fn.host),null===e&&(o=t),e}function ue(){var e,t,r,i,l,u,c;for(i=o,l=o,e=[],u=o,null!==(t=ae())?(46===n.charCodeAt(o)?(r=".",o++):(r=null,0===s&&a('"."')),null!==r?t=[t,r]:(t=null,o=u)):(t=null,o=u);null!==t;)e.push(t),u=o,null!==(t=ae())?(46===n.charCodeAt(o)?(r=".",o++):(r=null,0===s&&a('"."')),null!==r?t=[t,r]:(t=null,o=u)):(t=null,o=u);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(o)?(r=".",o++):(r=null,0===s&&a('"."')),null!==(r=null!==r?r:"")?e=[e,t,r]:(e=null,o=l)):(e=null,o=l),null!==e&&(c=i,Fn.host_type="domain",e=n.substring(o,c)),null===e&&(o=i),e}function ae(){var e,t,r,i;if(i=o,null!==(e=y())){for(t=[],null===(r=y())&&(45===n.charCodeAt(o)?(r="-",o++):(r=null,0===s&&a('"-"')),null===r&&(95===n.charCodeAt(o)?(r="_",o++):(r=null,0===s&&a('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(o)?(r="-",o++):(r=null,0===s&&a('"-"')),null===r&&(95===n.charCodeAt(o)?(r="_",o++):(r=null,0===s&&a('"_"'))));null!==t?e=[e,t]:(e=null,o=i)}else e=null,o=i;return e}function ce(){var e,t,r,i;if(i=o,null!==(e=d())){for(t=[],null===(r=y())&&(45===n.charCodeAt(o)?(r="-",o++):(r=null,0===s&&a('"-"')),null===r&&(95===n.charCodeAt(o)?(r="_",o++):(r=null,0===s&&a('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(o)?(r="-",o++):(r=null,0===s&&a('"-"')),null===r&&(95===n.charCodeAt(o)?(r="_",o++):(r=null,0===s&&a('"_"'))));null!==t?e=[e,t]:(e=null,o=i)}else e=null,o=i;return e}function fe(){var e,t,r,i,l,u;return i=o,l=o,91===n.charCodeAt(o)?(e="[",o++):(e=null,0===s&&a('"["')),null!==e&&null!==(t=de())?(93===n.charCodeAt(o)?(r="]",o++):(r=null,0===s&&a('"]"')),null!==r?e=[e,t,r]:(e=null,o=l)):(e=null,o=l),null!==e&&(u=i,Fn.host_type="IPv6",e=n.substring(o,u)),null===e&&(o=i),e}function de(){var e,t,r,i,l,u,c,f,d,h,_,p,m,v,g,y,T;return v=o,g=o,null!==(e=he())?(58===n.charCodeAt(o)?(t=":",o++):(t=null,0===s&&a('":"')),null!==t&&null!==(r=he())?(58===n.charCodeAt(o)?(i=":",o++):(i=null,0===s&&a('":"')),null!==i&&null!==(l=he())?(58===n.charCodeAt(o)?(u=":",o++):(u=null,0===s&&a('":"')),null!==u&&null!==(c=he())?(58===n.charCodeAt(o)?(f=":",o++):(f=null,0===s&&a('":"')),null!==f&&null!==(d=he())?(58===n.charCodeAt(o)?(h=":",o++):(h=null,0===s&&a('":"')),null!==h&&null!==(_=he())?(58===n.charCodeAt(o)?(p=":",o++):(p=null,0===s&&a('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,i,l,u,c,f,d,h,_,p,m]:(e=null,o=g)):(e=null,o=g)):(e=null,o=g)):(e=null,o=g)):(e=null,o=g)):(e=null,o=g)):(e=null,o=g),null===e&&(g=o,"::"===n.substr(o,2)?(e="::",o+=2):(e=null,0===s&&a('"::"')),null!==e&&null!==(t=he())?(58===n.charCodeAt(o)?(r=":",o++):(r=null,0===s&&a('":"')),null!==r&&null!==(i=he())?(58===n.charCodeAt(o)?(l=":",o++):(l=null,0===s&&a('":"')),null!==l&&null!==(u=he())?(58===n.charCodeAt(o)?(c=":",o++):(c=null,0===s&&a('":"')),null!==c&&null!==(f=he())?(58===n.charCodeAt(o)?(d=":",o++):(d=null,0===s&&a('":"')),null!==d&&null!==(h=he())?(58===n.charCodeAt(o)?(_=":",o++):(_=null,0===s&&a('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,i,l,u,c,f,d,h,_,p]:(e=null,o=g)):(e=null,o=g)):(e=null,o=g)):(e=null,o=g)):(e=null,o=g)):(e=null,o=g),null===e&&(g=o,"::"===n.substr(o,2)?(e="::",o+=2):(e=null,0===s&&a('"::"')),null!==e&&null!==(t=he())?(58===n.charCodeAt(o)?(r=":",o++):(r=null,0===s&&a('":"')),null!==r&&null!==(i=he())?(58===n.charCodeAt(o)?(l=":",o++):(l=null,0===s&&a('":"')),null!==l&&null!==(u=he())?(58===n.charCodeAt(o)?(c=":",o++):(c=null,0===s&&a('":"')),null!==c&&null!==(f=he())?(58===n.charCodeAt(o)?(d=":",o++):(d=null,0===s&&a('":"')),null!==d&&null!==(h=_e())?e=[e,t,r,i,l,u,c,f,d,h]:(e=null,o=g)):(e=null,o=g)):(e=null,o=g)):(e=null,o=g)):(e=null,o=g),null===e&&(g=o,"::"===n.substr(o,2)?(e="::",o+=2):(e=null,0===s&&a('"::"')),null!==e&&null!==(t=he())?(58===n.charCodeAt(o)?(r=":",o++):(r=null,0===s&&a('":"')),null!==r&&null!==(i=he())?(58===n.charCodeAt(o)?(l=":",o++):(l=null,0===s&&a('":"')),null!==l&&null!==(u=he())?(58===n.charCodeAt(o)?(c=":",o++):(c=null,0===s&&a('":"')),null!==c&&null!==(f=_e())?e=[e,t,r,i,l,u,c,f]:(e=null,o=g)):(e=null,o=g)):(e=null,o=g)):(e=null,o=g),null===e&&(g=o,"::"===n.substr(o,2)?(e="::",o+=2):(e=null,0===s&&a('"::"')),null!==e&&null!==(t=he())?(58===n.charCodeAt(o)?(r=":",o++):(r=null,0===s&&a('":"')),null!==r&&null!==(i=he())?(58===n.charCodeAt(o)?(l=":",o++):(l=null,0===s&&a('":"')),null!==l&&null!==(u=_e())?e=[e,t,r,i,l,u]:(e=null,o=g)):(e=null,o=g)):(e=null,o=g),null===e&&(g=o,"::"===n.substr(o,2)?(e="::",o+=2):(e=null,0===s&&a('"::"')),null!==e&&null!==(t=he())?(58===n.charCodeAt(o)?(r=":",o++):(r=null,0===s&&a('":"')),null!==r&&null!==(i=_e())?e=[e,t,r,i]:(e=null,o=g)):(e=null,o=g),null===e&&(g=o,"::"===n.substr(o,2)?(e="::",o+=2):(e=null,0===s&&a('"::"')),null!==e&&null!==(t=_e())?e=[e,t]:(e=null,o=g),null===e&&(g=o,"::"===n.substr(o,2)?(e="::",o+=2):(e=null,0===s&&a('"::"')),null!==e&&null!==(t=he())?e=[e,t]:(e=null,o=g),null===e&&(g=o,null!==(e=he())?("::"===n.substr(o,2)?(t="::",o+=2):(t=null,0===s&&a('"::"')),null!==t&&null!==(r=he())?(58===n.charCodeAt(o)?(i=":",o++):(i=null,0===s&&a('":"')),null!==i&&null!==(l=he())?(58===n.charCodeAt(o)?(u=":",o++):(u=null,0===s&&a('":"')),null!==u&&null!==(c=he())?(58===n.charCodeAt(o)?(f=":",o++):(f=null,0===s&&a('":"')),null!==f&&null!==(d=he())?(58===n.charCodeAt(o)?(h=":",o++):(h=null,0===s&&a('":"')),null!==h&&null!==(_=_e())?e=[e,t,r,i,l,u,c,f,d,h,_]:(e=null,o=g)):(e=null,o=g)):(e=null,o=g)):(e=null,o=g)):(e=null,o=g)):(e=null,o=g),null===e&&(g=o,null!==(e=he())?(y=o,58===n.charCodeAt(o)?(t=":",o++):(t=null,0===s&&a('":"')),null!==t&&null!==(r=he())?t=[t,r]:(t=null,o=y),null!==(t=null!==t?t:"")?("::"===n.substr(o,2)?(r="::",o+=2):(r=null,0===s&&a('"::"')),null!==r&&null!==(i=he())?(58===n.charCodeAt(o)?(l=":",o++):(l=null,0===s&&a('":"')),null!==l&&null!==(u=he())?(58===n.charCodeAt(o)?(c=":",o++):(c=null,0===s&&a('":"')),null!==c&&null!==(f=he())?(58===n.charCodeAt(o)?(d=":",o++):(d=null,0===s&&a('":"')),null!==d&&null!==(h=_e())?e=[e,t,r,i,l,u,c,f,d,h]:(e=null,o=g)):(e=null,o=g)):(e=null,o=g)):(e=null,o=g)):(e=null,o=g)):(e=null,o=g),null===e&&(g=o,null!==(e=he())?(y=o,58===n.charCodeAt(o)?(t=":",o++):(t=null,0===s&&a('":"')),null!==t&&null!==(r=he())?t=[t,r]:(t=null,o=y),null!==(t=null!==t?t:"")?(y=o,58===n.charCodeAt(o)?(r=":",o++):(r=null,0===s&&a('":"')),null!==r&&null!==(i=he())?r=[r,i]:(r=null,o=y),null!==(r=null!==r?r:"")?("::"===n.substr(o,2)?(i="::",o+=2):(i=null,0===s&&a('"::"')),null!==i&&null!==(l=he())?(58===n.charCodeAt(o)?(u=":",o++):(u=null,0===s&&a('":"')),null!==u&&null!==(c=he())?(58===n.charCodeAt(o)?(f=":",o++):(f=null,0===s&&a('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,i,l,u,c,f,d]:(e=null,o=g)):(e=null,o=g)):(e=null,o=g)):(e=null,o=g)):(e=null,o=g)):(e=null,o=g),null===e&&(g=o,null!==(e=he())?(y=o,58===n.charCodeAt(o)?(t=":",o++):(t=null,0===s&&a('":"')),null!==t&&null!==(r=he())?t=[t,r]:(t=null,o=y),null!==(t=null!==t?t:"")?(y=o,58===n.charCodeAt(o)?(r=":",o++):(r=null,0===s&&a('":"')),null!==r&&null!==(i=he())?r=[r,i]:(r=null,o=y),null!==(r=null!==r?r:"")?(y=o,58===n.charCodeAt(o)?(i=":",o++):(i=null,0===s&&a('":"')),null!==i&&null!==(l=he())?i=[i,l]:(i=null,o=y),null!==(i=null!==i?i:"")?("::"===n.substr(o,2)?(l="::",o+=2):(l=null,0===s&&a('"::"')),null!==l&&null!==(u=he())?(58===n.charCodeAt(o)?(c=":",o++):(c=null,0===s&&a('":"')),null!==c&&null!==(f=_e())?e=[e,t,r,i,l,u,c,f]:(e=null,o=g)):(e=null,o=g)):(e=null,o=g)):(e=null,o=g)):(e=null,o=g)):(e=null,o=g),null===e&&(g=o,null!==(e=he())?(y=o,58===n.charCodeAt(o)?(t=":",o++):(t=null,0===s&&a('":"')),null!==t&&null!==(r=he())?t=[t,r]:(t=null,o=y),null!==(t=null!==t?t:"")?(y=o,58===n.charCodeAt(o)?(r=":",o++):(r=null,0===s&&a('":"')),null!==r&&null!==(i=he())?r=[r,i]:(r=null,o=y),null!==(r=null!==r?r:"")?(y=o,58===n.charCodeAt(o)?(i=":",o++):(i=null,0===s&&a('":"')),null!==i&&null!==(l=he())?i=[i,l]:(i=null,o=y),null!==(i=null!==i?i:"")?(y=o,58===n.charCodeAt(o)?(l=":",o++):(l=null,0===s&&a('":"')),null!==l&&null!==(u=he())?l=[l,u]:(l=null,o=y),null!==(l=null!==l?l:"")?("::"===n.substr(o,2)?(u="::",o+=2):(u=null,0===s&&a('"::"')),null!==u&&null!==(c=_e())?e=[e,t,r,i,l,u,c]:(e=null,o=g)):(e=null,o=g)):(e=null,o=g)):(e=null,o=g)):(e=null,o=g)):(e=null,o=g),null===e&&(g=o,null!==(e=he())?(y=o,58===n.charCodeAt(o)?(t=":",o++):(t=null,0===s&&a('":"')),null!==t&&null!==(r=he())?t=[t,r]:(t=null,o=y),null!==(t=null!==t?t:"")?(y=o,58===n.charCodeAt(o)?(r=":",o++):(r=null,0===s&&a('":"')),null!==r&&null!==(i=he())?r=[r,i]:(r=null,o=y),null!==(r=null!==r?r:"")?(y=o,58===n.charCodeAt(o)?(i=":",o++):(i=null,0===s&&a('":"')),null!==i&&null!==(l=he())?i=[i,l]:(i=null,o=y),null!==(i=null!==i?i:"")?(y=o,58===n.charCodeAt(o)?(l=":",o++):(l=null,0===s&&a('":"')),null!==l&&null!==(u=he())?l=[l,u]:(l=null,o=y),null!==(l=null!==l?l:"")?(y=o,58===n.charCodeAt(o)?(u=":",o++):(u=null,0===s&&a('":"')),null!==u&&null!==(c=he())?u=[u,c]:(u=null,o=y),null!==(u=null!==u?u:"")?("::"===n.substr(o,2)?(c="::",o+=2):(c=null,0===s&&a('"::"')),null!==c&&null!==(f=he())?e=[e,t,r,i,l,u,c,f]:(e=null,o=g)):(e=null,o=g)):(e=null,o=g)):(e=null,o=g)):(e=null,o=g)):(e=null,o=g)):(e=null,o=g),null===e&&(g=o,null!==(e=he())?(y=o,58===n.charCodeAt(o)?(t=":",o++):(t=null,0===s&&a('":"')),null!==t&&null!==(r=he())?t=[t,r]:(t=null,o=y),null!==(t=null!==t?t:"")?(y=o,58===n.charCodeAt(o)?(r=":",o++):(r=null,0===s&&a('":"')),null!==r&&null!==(i=he())?r=[r,i]:(r=null,o=y),null!==(r=null!==r?r:"")?(y=o,58===n.charCodeAt(o)?(i=":",o++):(i=null,0===s&&a('":"')),null!==i&&null!==(l=he())?i=[i,l]:(i=null,o=y),null!==(i=null!==i?i:"")?(y=o,58===n.charCodeAt(o)?(l=":",o++):(l=null,0===s&&a('":"')),null!==l&&null!==(u=he())?l=[l,u]:(l=null,o=y),null!==(l=null!==l?l:"")?(y=o,58===n.charCodeAt(o)?(u=":",o++):(u=null,0===s&&a('":"')),null!==u&&null!==(c=he())?u=[u,c]:(u=null,o=y),null!==(u=null!==u?u:"")?(y=o,58===n.charCodeAt(o)?(c=":",o++):(c=null,0===s&&a('":"')),null!==c&&null!==(f=he())?c=[c,f]:(c=null,o=y),null!==(c=null!==c?c:"")?("::"===n.substr(o,2)?(f="::",o+=2):(f=null,0===s&&a('"::"')),null!==f?e=[e,t,r,i,l,u,c,f]:(e=null,o=g)):(e=null,o=g)):(e=null,o=g)):(e=null,o=g)):(e=null,o=g)):(e=null,o=g)):(e=null,o=g)):(e=null,o=g))))))))))))))),null!==e&&(T=v,Fn.host_type="IPv6",e=n.substring(o,T)),null===e&&(o=v),e}function he(){var e,t,n,r,i;return i=o,null!==(e=h())&&null!==(t=null!==(t=h())?t:"")&&null!==(n=null!==(n=h())?n:"")&&null!==(r=null!==(r=h())?r:"")?e=[e,t,n,r]:(e=null,o=i),e}function _e(){var e,t,r,i;return i=o,null!==(e=he())?(58===n.charCodeAt(o)?(t=":",o++):(t=null,0===s&&a('":"')),null!==t&&null!==(r=he())?e=[e,t,r]:(e=null,o=i)):(e=null,o=i),null===e&&(e=pe()),e}function pe(){var e,t,r,i,l,u,c,f,d,h;return f=o,d=o,null!==(e=me())?(46===n.charCodeAt(o)?(t=".",o++):(t=null,0===s&&a('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(o)?(i=".",o++):(i=null,0===s&&a('"."')),null!==i&&null!==(l=me())?(46===n.charCodeAt(o)?(u=".",o++):(u=null,0===s&&a('"."')),null!==u&&null!==(c=me())?e=[e,t,r,i,l,u,c]:(e=null,o=d)):(e=null,o=d)):(e=null,o=d)):(e=null,o=d),null!==e&&(h=f,Fn.host_type="IPv4",e=n.substring(o,h)),null===e&&(o=f),e}function me(){var e,t,r,i;return i=o,"25"===n.substr(o,2)?(e="25",o+=2):(e=null,0===s&&a('"25"')),null!==e?(/^[0-5]/.test(n.charAt(o))?(t=n.charAt(o),o++):(t=null,0===s&&a("[0-5]")),null!==t?e=[e,t]:(e=null,o=i)):(e=null,o=i),null===e&&(i=o,50===n.charCodeAt(o)?(e="2",o++):(e=null,0===s&&a('"2"')),null!==e?(/^[0-4]/.test(n.charAt(o))?(t=n.charAt(o),o++):(t=null,0===s&&a("[0-4]")),null!==t&&null!==(r=f())?e=[e,t,r]:(e=null,o=i)):(e=null,o=i),null===e&&(i=o,49===n.charCodeAt(o)?(e="1",o++):(e=null,0===s&&a('"1"')),null!==e&&null!==(t=f())&&null!==(r=f())?e=[e,t,r]:(e=null,o=i),null===e&&(i=o,/^[1-9]/.test(n.charAt(o))?(e=n.charAt(o),o++):(e=null,0===s&&a("[1-9]")),null!==e&&null!==(t=f())?e=[e,t]:(e=null,o=i),null===e&&(e=f())))),e}function ve(){var e,t,n,r,i,s,l,u;return s=o,l=o,null!==(e=null!==(e=f())?e:"")&&null!==(t=null!==(t=f())?t:"")&&null!==(n=null!==(n=f())?n:"")&&null!==(r=null!==(r=f())?r:"")&&null!==(i=null!==(i=f())?i:"")?e=[e,t,n,r,i]:(e=null,o=l),null!==e&&(u=e,u=parseInt(u.join("")),Fn.port=u,e=u),null===e&&(o=s),e}function ge(){var e,t,r,i;for(e=[],i=o,59===n.charCodeAt(o)?(t=";",o++):(t=null,0===s&&a('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,o=i);null!==t;)e.push(t),i=o,59===n.charCodeAt(o)?(t=";",o++):(t=null,0===s&&a('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,o=i);return e}function ye(){var e;return null===(e=Te())&&null===(e=be())&&null===(e=Se())&&null===(e=Ee())&&null===(e=Ce())&&null===(e=Ae())&&(e=we()),e}function Te(){var e,t,r,i,l;return r=o,i=o,"transport="===n.substr(o,10).toLowerCase()?(e=n.substr(o,10),o+=10):(e=null,0===s&&a('"transport="')),null!==e?("udp"===n.substr(o,3).toLowerCase()?(t=n.substr(o,3),o+=3):(t=null,0===s&&a('"udp"')),null===t&&("tcp"===n.substr(o,3).toLowerCase()?(t=n.substr(o,3),o+=3):(t=null,0===s&&a('"tcp"')),null===t&&("sctp"===n.substr(o,4).toLowerCase()?(t=n.substr(o,4),o+=4):(t=null,0===s&&a('"sctp"')),null===t&&("tls"===n.substr(o,3).toLowerCase()?(t=n.substr(o,3),o+=3):(t=null,0===s&&a('"tls"')),null===t&&(t=k())))),null!==t?e=[e,t]:(e=null,o=i)):(e=null,o=i),null!==e&&(l=e[1],Fn.uri_params||(Fn.uri_params={}),e=void(Fn.uri_params.transport=l.toLowerCase())),null===e&&(o=r),e}function be(){var e,t,r,i,l;return r=o,i=o,"user="===n.substr(o,5).toLowerCase()?(e=n.substr(o,5),o+=5):(e=null,0===s&&a('"user="')),null!==e?("phone"===n.substr(o,5).toLowerCase()?(t=n.substr(o,5),o+=5):(t=null,0===s&&a('"phone"')),null===t&&("ip"===n.substr(o,2).toLowerCase()?(t=n.substr(o,2),o+=2):(t=null,0===s&&a('"ip"')),null===t&&(t=k())),null!==t?e=[e,t]:(e=null,o=i)):(e=null,o=i),null!==e&&(l=e[1],Fn.uri_params||(Fn.uri_params={}),e=void(Fn.uri_params.user=l.toLowerCase())),null===e&&(o=r),e}function Se(){var e,t,r,i,l;return r=o,i=o,"method="===n.substr(o,7).toLowerCase()?(e=n.substr(o,7),o+=7):(e=null,0===s&&a('"method="')),null!==e&&null!==(t=ct())?e=[e,t]:(e=null,o=i),null!==e&&(l=e[1],Fn.uri_params||(Fn.uri_params={}),e=void(Fn.uri_params.method=l)),null===e&&(o=r),e}function Ee(){var e,t,r,i,l;return r=o,i=o,"ttl="===n.substr(o,4).toLowerCase()?(e=n.substr(o,4),o+=4):(e=null,0===s&&a('"ttl="')),null!==e&&null!==(t=An())?e=[e,t]:(e=null,o=i),null!==e&&(l=e[1],Fn.params||(Fn.params={}),e=void(Fn.params.ttl=l)),null===e&&(o=r),e}function Ce(){var e,t,r,i,l;return r=o,i=o,"maddr="===n.substr(o,6).toLowerCase()?(e=n.substr(o,6),o+=6):(e=null,0===s&&a('"maddr="')),null!==e&&null!==(t=le())?e=[e,t]:(e=null,o=i),null!==e&&(l=e[1],Fn.uri_params||(Fn.uri_params={}),e=void(Fn.uri_params.maddr=l)),null===e&&(o=r),e}function Ae(){var e,t,r,i,l,u;return i=o,l=o,"lr"===n.substr(o,2).toLowerCase()?(e=n.substr(o,2),o+=2):(e=null,0===s&&a('"lr"')),null!==e?(u=o,61===n.charCodeAt(o)?(t="=",o++):(t=null,0===s&&a('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,o=u),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,o=l)):(e=null,o=l),null!==e&&(Fn.uri_params||(Fn.uri_params={}),e=void(Fn.uri_params.lr=void 0)),null===e&&(o=i),e}function we(){var e,t,r,i,l,u,c,f;return i=o,l=o,null!==(e=Re())?(u=o,61===n.charCodeAt(o)?(t="=",o++):(t=null,0===s&&a('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,o=u),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,o=l)):(e=null,o=l),null!==e&&(c=e[0],f=e[1],Fn.uri_params||(Fn.uri_params={}),f=void 0===f?void 0:f[1],e=void(Fn.uri_params[c.toLowerCase()]=f)),null===e&&(o=i),e}function Re(){var e,t,n;if(n=o,null!==(t=Oe()))for(e=[];null!==t;)e.push(t),t=Oe();else e=null;return null!==e&&(e=e.join("")),null===e&&(o=n),e}function Ie(){var e,t,n;if(n=o,null!==(t=Oe()))for(e=[];null!==t;)e.push(t),t=Oe();else e=null;return null!==e&&(e=e.join("")),null===e&&(o=n),e}function Oe(){var e;return null===(e=Ne())&&null===(e=b())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(o)?(e="[",o++):(e=null,0===s&&a('"["')),null===e&&(93===n.charCodeAt(o)?(e="]",o++):(e=null,0===s&&a('"]"')),null===e&&(47===n.charCodeAt(o)?(e="/",o++):(e=null,0===s&&a('"/"')),null===e&&(58===n.charCodeAt(o)?(e=":",o++):(e=null,0===s&&a('":"')),null===e&&(38===n.charCodeAt(o)?(e="&",o++):(e=null,0===s&&a('"&"')),null===e&&(43===n.charCodeAt(o)?(e="+",o++):(e=null,0===s&&a('"+"')),null===e&&(36===n.charCodeAt(o)?(e="$",o++):(e=null,0===s&&a('"$"')))))))),e}function ke(){var e,t,r,i,l,u,c;if(u=o,63===n.charCodeAt(o)?(e="?",o++):(e=null,0===s&&a('"?"')),null!==e)if(null!==(t=Pe())){for(r=[],c=o,38===n.charCodeAt(o)?(i="&",o++):(i=null,0===s&&a('"&"')),null!==i&&null!==(l=Pe())?i=[i,l]:(i=null,o=c);null!==i;)r.push(i),c=o,38===n.charCodeAt(o)?(i="&",o++):(i=null,0===s&&a('"&"')),null!==i&&null!==(l=Pe())?i=[i,l]:(i=null,o=c);null!==r?e=[e,t,r]:(e=null,o=u)}else e=null,o=u;else e=null,o=u;return e}function Pe(){var e,t,r,i,l,u,c;return i=o,l=o,null!==(e=Ue())?(61===n.charCodeAt(o)?(t="=",o++):(t=null,0===s&&a('"="')),null!==t&&null!==(r=xe())?e=[e,t,r]:(e=null,o=l)):(e=null,o=l),null!==e&&(u=e[0],c=e[2],u=u.join("").toLowerCase(),c=c.join(""),Fn.uri_headers||(Fn.uri_headers={}),e=void(Fn.uri_headers[u]?Fn.uri_headers[u].push(c):Fn.uri_headers[u]=[c])),null===e&&(o=i),e}function Ue(){var e,t;if(null===(t=De())&&null===(t=b())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=De())&&null===(t=b())&&(t=E());else e=null;return e}function xe(){var e,t;for(e=[],null===(t=De())&&null===(t=b())&&(t=E());null!==t;)e.push(t),null===(t=De())&&null===(t=b())&&(t=E());return e}function De(){var e;return 91===n.charCodeAt(o)?(e="[",o++):(e=null,0===s&&a('"["')),null===e&&(93===n.charCodeAt(o)?(e="]",o++):(e=null,0===s&&a('"]"')),null===e&&(47===n.charCodeAt(o)?(e="/",o++):(e=null,0===s&&a('"/"')),null===e&&(63===n.charCodeAt(o)?(e="?",o++):(e=null,0===s&&a('"?"')),null===e&&(58===n.charCodeAt(o)?(e=":",o++):(e=null,0===s&&a('":"')),null===e&&(43===n.charCodeAt(o)?(e="+",o++):(e=null,0===s&&a('"+"')),null===e&&(36===n.charCodeAt(o)?(e="$",o++):(e=null,0===s&&a('"$"')))))))),e}function Me(){var e,t,n,r,i,s;return s=o,null!==(e=ct())&&null!==(t=v())&&null!==(n=qe())&&null!==(r=v())&&null!==(i=et())?e=[e,t,n,r,i]:(e=null,o=s),e}function qe(){var e;return null===(e=Q())&&(e=Le()),e}function Le(){var e,t,r,i;return i=o,null!==(e=$e())?(58===n.charCodeAt(o)?(t=":",o++):(t=null,0===s&&a('":"')),null!==t?(null===(r=He())&&(r=Be()),null!==r?e=[e,t,r]:(e=null,o=i)):(e=null,o=i)):(e=null,o=i),e}function He(){var e,t,r,i,l;return i=o,null===(e=je())&&(e=Fe()),null!==e?(l=o,63===n.charCodeAt(o)?(t="?",o++):(t=null,0===s&&a('"?"')),null!==t&&null!==(r=Ze())?t=[t,r]:(t=null,o=l),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,o=i)):(e=null,o=i),e}function je(){var e,t,r,i;return i=o,"//"===n.substr(o,2)?(e="//",o+=2):(e=null,0===s&&a('"//"')),null!==e&&null!==(t=Xe())&&null!==(r=null!==(r=Fe())?r:"")?e=[e,t,r]:(e=null,o=i),e}function Fe(){var e,t,r;return r=o,47===n.charCodeAt(o)?(e="/",o++):(e=null,0===s&&a('"/"')),null!==e&&null!==(t=We())?e=[e,t]:(e=null,o=r),e}function Be(){var e,t,n,r;if(r=o,null!==(e=Ve())){for(t=[],n=Ge();null!==n;)t.push(n),n=Ge();null!==t?e=[e,t]:(e=null,o=r)}else e=null,o=r;return e}function Ge(){var e;return null===(e=T())&&null===(e=b())&&(e=E()),e}function Ve(){var e;return null===(e=b())&&null===(e=E())&&(59===n.charCodeAt(o)?(e=";",o++):(e=null,0===s&&a('";"')),null===e&&(63===n.charCodeAt(o)?(e="?",o++):(e=null,0===s&&a('"?"')),null===e&&(58===n.charCodeAt(o)?(e=":",o++):(e=null,0===s&&a('":"')),null===e&&(64===n.charCodeAt(o)?(e="@",o++):(e=null,0===s&&a('"@"')),null===e&&(38===n.charCodeAt(o)?(e="&",o++):(e=null,0===s&&a('"&"')),null===e&&(61===n.charCodeAt(o)?(e="=",o++):(e=null,0===s&&a('"="')),null===e&&(43===n.charCodeAt(o)?(e="+",o++):(e=null,0===s&&a('"+"')),null===e&&(36===n.charCodeAt(o)?(e="$",o++):(e=null,0===s&&a('"$"')),null===e&&(44===n.charCodeAt(o)?(e=",",o++):(e=null,0===s&&a('","'))))))))))),e}function We(){var e,t,r,i,l,u;if(l=o,null!==(e=Ye())){for(t=[],u=o,47===n.charCodeAt(o)?(r="/",o++):(r=null,0===s&&a('"/"')),null!==r&&null!==(i=Ye())?r=[r,i]:(r=null,o=u);null!==r;)t.push(r),u=o,47===n.charCodeAt(o)?(r="/",o++):(r=null,0===s&&a('"/"')),null!==r&&null!==(i=Ye())?r=[r,i]:(r=null,o=u);null!==t?e=[e,t]:(e=null,o=l)}else e=null,o=l;return e}function Ye(){var e,t,r,i,l,u;for(l=o,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],u=o,59===n.charCodeAt(o)?(r=";",o++):(r=null,0===s&&a('";"')),null!==r&&null!==(i=Ke())?r=[r,i]:(r=null,o=u);null!==r;)t.push(r),u=o,59===n.charCodeAt(o)?(r=";",o++):(r=null,0===s&&a('";"')),null!==r&&null!==(i=Ke())?r=[r,i]:(r=null,o=u);null!==t?e=[e,t]:(e=null,o=l)}else e=null,o=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=b())&&null===(e=E())&&(58===n.charCodeAt(o)?(e=":",o++):(e=null,0===s&&a('":"')),null===e&&(64===n.charCodeAt(o)?(e="@",o++):(e=null,0===s&&a('"@"')),null===e&&(38===n.charCodeAt(o)?(e="&",o++):(e=null,0===s&&a('"&"')),null===e&&(61===n.charCodeAt(o)?(e="=",o++):(e=null,0===s&&a('"="')),null===e&&(43===n.charCodeAt(o)?(e="+",o++):(e=null,0===s&&a('"+"')),null===e&&(36===n.charCodeAt(o)?(e="$",o++):(e=null,0===s&&a('"$"')),null===e&&(44===n.charCodeAt(o)?(e=",",o++):(e=null,0===s&&a('","'))))))))),e}function $e(){var e,t,r,i,l,u;if(i=o,l=o,null!==(e=d())){for(t=[],null===(r=d())&&null===(r=f())&&(43===n.charCodeAt(o)?(r="+",o++):(r=null,0===s&&a('"+"')),null===r&&(45===n.charCodeAt(o)?(r="-",o++):(r=null,0===s&&a('"-"')),null===r&&(46===n.charCodeAt(o)?(r=".",o++):(r=null,0===s&&a('"."')))));null!==r;)t.push(r),null===(r=d())&&null===(r=f())&&(43===n.charCodeAt(o)?(r="+",o++):(r=null,0===s&&a('"+"')),null===r&&(45===n.charCodeAt(o)?(r="-",o++):(r=null,0===s&&a('"-"')),null===r&&(46===n.charCodeAt(o)?(r=".",o++):(r=null,0===s&&a('"."')))));null!==t?e=[e,t]:(e=null,o=l)}else e=null,o=l;return null!==e&&(u=i,e=void(Fn.scheme=n.substring(o,u))),null===e&&(o=i),e}function Xe(){var e;return null===(e=Je())&&(e=Qe()),e}function Je(){var e,t,r,i;return r=o,i=o,null!==(e=ne())?(64===n.charCodeAt(o)?(t="@",o++):(t=null,0===s&&a('"@"')),null!==t?e=[e,t]:(e=null,o=i)):(e=null,o=i),null!==(e=null!==e?e:"")&&null!==(t=se())?e=[e,t]:(e=null,o=r),e=null!==e?e:""}function Qe(){var e,t;if(null===(t=b())&&null===(t=E())&&(36===n.charCodeAt(o)?(t="$",o++):(t=null,0===s&&a('"$"')),null===t&&(44===n.charCodeAt(o)?(t=",",o++):(t=null,0===s&&a('","')),null===t&&(59===n.charCodeAt(o)?(t=";",o++):(t=null,0===s&&a('";"')),null===t&&(58===n.charCodeAt(o)?(t=":",o++):(t=null,0===s&&a('":"')),null===t&&(64===n.charCodeAt(o)?(t="@",o++):(t=null,0===s&&a('"@"')),null===t&&(38===n.charCodeAt(o)?(t="&",o++):(t=null,0===s&&a('"&"')),null===t&&(61===n.charCodeAt(o)?(t="=",o++):(t=null,0===s&&a('"="')),null===t&&(43===n.charCodeAt(o)?(t="+",o++):(t=null,0===s&&a('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=b())&&null===(t=E())&&(36===n.charCodeAt(o)?(t="$",o++):(t=null,0===s&&a('"$"')),null===t&&(44===n.charCodeAt(o)?(t=",",o++):(t=null,0===s&&a('","')),null===t&&(59===n.charCodeAt(o)?(t=";",o++):(t=null,0===s&&a('";"')),null===t&&(58===n.charCodeAt(o)?(t=":",o++):(t=null,0===s&&a('":"')),null===t&&(64===n.charCodeAt(o)?(t="@",o++):(t=null,0===s&&a('"@"')),null===t&&(38===n.charCodeAt(o)?(t="&",o++):(t=null,0===s&&a('"&"')),null===t&&(61===n.charCodeAt(o)?(t="=",o++):(t=null,0===s&&a('"="')),null===t&&(43===n.charCodeAt(o)?(t="+",o++):(t=null,0===s&&a('"+"'))))))))));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,i,l,u,c,d,h;if(c=o,d=o,"sip"===n.substr(o,3).toLowerCase()?(e=n.substr(o,3),o+=3):(e=null,0===s&&a('"SIP"')),null!==e)if(47===n.charCodeAt(o)?(t="/",o++):(t=null,0===s&&a('"/"')),null!==t){if(null!==(i=f()))for(r=[];null!==i;)r.push(i),i=f();else r=null;if(null!==r)if(46===n.charCodeAt(o)?(i=".",o++):(i=null,0===s&&a('"."')),null!==i){if(null!==(u=f()))for(l=[];null!==u;)l.push(u),u=f();else l=null;null!==l?e=[e,t,r,i,l]:(e=null,o=d)}else e=null,o=d;else e=null,o=d}else e=null,o=d;else e=null,o=d;return null!==e&&(h=c,e=void(Fn.sip_version=n.substring(o,h))),null===e&&(o=c),e}function tt(){var e;return"INVITE"===n.substr(o,6)?(e="INVITE",o+=6):(e=null,0===s&&a('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(o,3)?(e="ACK",o+=3):(e=null,0===s&&a('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(o,7)?(e="OPTIONS",o+=7):(e=null,0===s&&a('"OPTIONS"')),e}function it(){var e;return"BYE"===n.substr(o,3)?(e="BYE",o+=3):(e=null,0===s&&a('"BYE"')),e}function ot(){var e;return"CANCEL"===n.substr(o,6)?(e="CANCEL",o+=6):(e=null,0===s&&a('"CANCEL"')),e}function st(){var e;return"REGISTER"===n.substr(o,8)?(e="REGISTER",o+=8):(e=null,0===s&&a('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(o,9)?(e="SUBSCRIBE",o+=9):(e=null,0===s&&a('"SUBSCRIBE"')),e}function ut(){var e;return"NOTIFY"===n.substr(o,6)?(e="NOTIFY",o+=6):(e=null,0===s&&a('"NOTIFY"')),e}function at(){var e;return"REFER"===n.substr(o,5)?(e="REFER",o+=5):(e=null,0===s&&a('"REFER"')),e}function ct(){var e,t,r;return t=o,null===(e=tt())&&null===(e=nt())&&null===(e=rt())&&null===(e=it())&&null===(e=ot())&&null===(e=st())&&null===(e=lt())&&null===(e=ut())&&null===(e=at())&&(e=k()),null!==e&&(r=t,Fn.method=n.substring(o,r),e=Fn.method),null===e&&(o=t),e}function ft(){var e,t,n,r,i,s;return s=o,null!==(e=et())&&null!==(t=v())&&null!==(n=dt())&&null!==(r=v())&&null!==(i=_t())?e=[e,t,n,r,i]:(e=null,o=s),e}function dt(){var e,t,n;return t=o,null!==(e=ht())&&(n=e,e=void(Fn.status_code=parseInt(n.join("")))),null===e&&(o=t),e}function ht(){var e,t,n,r;return r=o,null!==(e=f())&&null!==(t=f())&&null!==(n=f())?e=[e,t,n]:(e=null,o=r),e}function _t(){var e,t,r,i;for(r=o,e=[],null===(t=T())&&null===(t=b())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=b())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());return null!==e&&(i=r,e=void(Fn.reason_phrase=n.substring(o,i))),null===e&&(o=r),e}function pt(){var e,t,n,r,i,s,l;if(i=o,s=o,null===(e=J())&&(e=mt()),null!==e){for(t=[],l=o,null!==(n=B())&&null!==(r=gt())?n=[n,r]:(n=null,o=l);null!==n;)t.push(n),l=o,null!==(n=B())&&null!==(r=gt())?n=[n,r]:(n=null,o=l);null!==t?e=[e,t]:(e=null,o=s)}else e=null,o=s;return null!==e&&(e=function(e){var t;Fn.multi_header||(Fn.multi_header=[]);try{t=new jn(Fn.uri,Fn.display_name,Fn.params),delete Fn.uri,delete Fn.display_name,delete Fn.params}catch(e){t=null}Fn.multi_header.push({possition:o,offset:e,parsed:t})}(i)),null===e&&(o=i),e}function mt(){var e,t,n,r,i;return i=o,null!==(e=null!==(e=vt())?e:"")&&null!==(t=j())&&null!==(n=Q())&&null!==(r=H())?e=[e,t,n,r]:(e=null,o=i),e}function vt(){var e,t,n,r,i,s,l,u;if(i=o,s=o,null!==(e=k())){for(t=[],l=o,null!==(n=C())&&null!==(r=k())?n=[n,r]:(n=null,o=l);null!==n;)t.push(n),l=o,null!==(n=C())&&null!==(r=k())?n=[n,r]:(n=null,o=l);null!==t?e=[e,t]:(e=null,o=s)}else e=null,o=s;return null===e&&(e=z()),null!==e&&(u=e,e=void(Fn.display_name="string"==typeof u?u:u[1].reduce(function(e,t){return e+t[0]+t[1]},u[0]))),null===e&&(o=i),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,i,l,u;return i=o,l=o,"q"===n.substr(o,1).toLowerCase()?(e=n.substr(o,1),o++):(e=null,0===s&&a('"q"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,o=l),null!==e&&(u=e[2],Fn.params||(Fn.params={}),e=void(Fn.params.q=u)),null===e&&(o=i),e}function Tt(){var e,t,r,i,l,u;return i=o,l=o,"expires"===n.substr(o,7).toLowerCase()?(e=n.substr(o,7),o+=7):(e=null,0===s&&a('"expires"')),null!==e&&null!==(t=M())&&null!==(r=bt())?e=[e,t,r]:(e=null,o=l),null!==e&&(u=e[2],Fn.params||(Fn.params={}),e=void(Fn.params.expires=u)),null===e&&(o=i),e}function bt(){var e,t,n;if(n=o,null!==(t=f()))for(e=[];null!==t;)e.push(t),t=f();else e=null;return null!==e&&(e=parseInt(e.join(""))),null===e&&(o=n),e}function St(){var e,t,r,i,l,u,c,d,h;return u=o,c=o,48===n.charCodeAt(o)?(e="0",o++):(e=null,0===s&&a('"0"')),null!==e?(d=o,46===n.charCodeAt(o)?(t=".",o++):(t=null,0===s&&a('"."')),null!==t&&null!==(r=null!==(r=f())?r:"")&&null!==(i=null!==(i=f())?i:"")&&null!==(l=null!==(l=f())?l:"")?t=[t,r,i,l]:(t=null,o=d),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,o=c)):(e=null,o=c),null!==e&&(h=u,e=parseFloat(n.substring(o,h))),null===e&&(o=u),e}function Et(){var e,t,n,r,i,s,l,u;return r=o,i=o,null!==(e=k())?(s=o,null!==(t=M())&&null!==(n=Ct())?t=[t,n]:(t=null,o=s),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,o=i)):(e=null,o=i),null!==e&&(l=e[0],u=e[1],Fn.params||(Fn.params={}),u=void 0===u?void 0:u[1],e=void(Fn.params[l.toLowerCase()]=u)),null===e&&(o=r),e}function Ct(){var e;return null===(e=k())&&null===(e=le())&&(e=K()),e}function At(){var e;return"render"===n.substr(o,6).toLowerCase()?(e=n.substr(o,6),o+=6):(e=null,0===s&&a('"render"')),null===e&&("session"===n.substr(o,7).toLowerCase()?(e=n.substr(o,7),o+=7):(e=null,0===s&&a('"session"')),null===e&&("icon"===n.substr(o,4).toLowerCase()?(e=n.substr(o,4),o+=4):(e=null,0===s&&a('"icon"')),null===e&&("alert"===n.substr(o,5).toLowerCase()?(e=n.substr(o,5),o+=5):(e=null,0===s&&a('"alert"')),null===e&&(e=k())))),e}function wt(){var e;return null===(e=Rt())&&(e=Et()),e}function Rt(){var e,t,r,i;return i=o,"handling"===n.substr(o,8).toLowerCase()?(e=n.substr(o,8),o+=8):(e=null,0===s&&a('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(o,8).toLowerCase()?(r=n.substr(o,8),o+=8):(r=null,0===s&&a('"optional"')),null===r&&("required"===n.substr(o,8).toLowerCase()?(r=n.substr(o,8),o+=8):(r=null,0===s&&a('"required"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,o=i)):(e=null,o=i),e}function It(){var e,t,n,r,i,s,l,u;if(l=o,null!==(e=Ot()))if(null!==(t=D()))if(null!==(n=xt())){for(r=[],u=o,null!==(i=B())&&null!==(s=Dt())?i=[i,s]:(i=null,o=u);null!==i;)r.push(i),u=o,null!==(i=B())&&null!==(s=Dt())?i=[i,s]:(i=null,o=u);null!==r?e=[e,t,n,r]:(e=null,o=l)}else e=null,o=l;else e=null,o=l;else e=null,o=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(o,4).toLowerCase()?(e=n.substr(o,4),o+=4):(e=null,0===s&&a('"text"')),null===e&&("image"===n.substr(o,5).toLowerCase()?(e=n.substr(o,5),o+=5):(e=null,0===s&&a('"image"')),null===e&&("audio"===n.substr(o,5).toLowerCase()?(e=n.substr(o,5),o+=5):(e=null,0===s&&a('"audio"')),null===e&&("video"===n.substr(o,5).toLowerCase()?(e=n.substr(o,5),o+=5):(e=null,0===s&&a('"video"')),null===e&&("application"===n.substr(o,11).toLowerCase()?(e=n.substr(o,11),o+=11):(e=null,0===s&&a('"application"')),null===e&&(e=Pt()))))),e}function kt(){var e;return"message"===n.substr(o,7).toLowerCase()?(e=n.substr(o,7),o+=7):(e=null,0===s&&a('"message"')),null===e&&("multipart"===n.substr(o,9).toLowerCase()?(e=n.substr(o,9),o+=9):(e=null,0===s&&a('"multipart"')),null===e&&(e=Pt())),e}function Pt(){var e;return null===(e=k())&&(e=Ut()),e}function Ut(){var e,t,r;return r=o,"x-"===n.substr(o,2).toLowerCase()?(e=n.substr(o,2),o+=2):(e=null,0===s&&a('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,o=r),e}function xt(){var e;return null===(e=Pt())&&(e=k()),e}function Dt(){var e,t,n,r;return r=o,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,o=r),e}function Mt(){var e;return null===(e=k())&&(e=K()),e}function qt(){var e,t,n,r;if(n=o,null!==(t=f()))for(e=[];null!==t;)e.push(t),t=f();else e=null;return null!==e&&(r=e,e=void(Fn.value=parseInt(r.join("")))),null===e&&(o=n),e}function Lt(){var e,t,r,i,l,u;if(l=o,null!==(e=P())){for(t=[],u=o,46===n.charCodeAt(o)?(r=".",o++):(r=null,0===s&&a('"."')),null!==r&&null!==(i=P())?r=[r,i]:(r=null,o=u);null!==r;)t.push(r),u=o,46===n.charCodeAt(o)?(r=".",o++):(r=null,0===s&&a('"."')),null!==r&&null!==(i=P())?r=[r,i]:(r=null,o=u);null!==t?e=[e,t]:(e=null,o=l)}else e=null,o=l;return e}function Ht(){var e;return null===(e=jt())&&(e=Et()),e}function jt(){var e,t,r,i,l,u;return i=o,l=o,"tag"===n.substr(o,3).toLowerCase()?(e=n.substr(o,3),o+=3):(e=null,0===s&&a('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,o=l),null!==e&&(u=e[2],e=void(Fn.tag=u)),null===e&&(o=i),e}function Ft(){var e,t,r,i,l,u,c,f;if(c=o,"digest"===n.substr(o,6).toLowerCase()?(e=n.substr(o,6),o+=6):(e=null,0===s&&a('"Digest"')),null!==e)if(null!==(t=C()))if(null!==(r=Vt())){for(i=[],f=o,null!==(l=F())&&null!==(u=Vt())?l=[l,u]:(l=null,o=f);null!==l;)i.push(l),f=o,null!==(l=F())&&null!==(u=Vt())?l=[l,u]:(l=null,o=f);null!==i?e=[e,t,r,i]:(e=null,o=c)}else e=null,o=c;else e=null,o=c;else e=null,o=c;return null===e&&(e=Bt()),e}function Bt(){var e,t,n,r,i,s,l,u;if(l=o,null!==(e=k()))if(null!==(t=C()))if(null!==(n=Gt())){for(r=[],u=o,null!==(i=F())&&null!==(s=Gt())?i=[i,s]:(i=null,o=u);null!==i;)r.push(i),u=o,null!==(i=F())&&null!==(s=Gt())?i=[i,s]:(i=null,o=u);null!==r?e=[e,t,n,r]:(e=null,o=l)}else e=null,o=l;else e=null,o=l;else e=null,o=l;return e}function Gt(){var e,t,n,r;return r=o,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=K()),null!==n?e=[e,t,n]:(e=null,o=r)):(e=null,o=r),e}function Vt(){var e;return null===(e=Wt())&&null===(e=Kt())&&null===(e=$t())&&null===(e=Jt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Gt()),e}function Wt(){var e,t,r,i;return i=o,"realm"===n.substr(o,5).toLowerCase()?(e=n.substr(o,5),o+=5):(e=null,0===s&&a('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Yt())?e=[e,t,r]:(e=null,o=i),e}function Yt(){var e,t,n;return t=o,null!==(e=z())&&(n=e,e=void(Fn.realm=n)),null===e&&(o=t),e}function Kt(){var e,t,r,i,l,u,c,f,d;if(f=o,"domain"===n.substr(o,6).toLowerCase()?(e=n.substr(o,6),o+=6):(e=null,0===s&&a('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(i=zt())){if(l=[],d=o,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,o=d);null!==u;){if(l.push(u),d=o,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,o=d)}null!==l&&null!==(u=W())?e=[e,t,r,i,l,u]:(e=null,o=f)}else e=null,o=f;else e=null,o=f;else e=null,o=f;else e=null,o=f;return e}function zt(){var e;return null===(e=Le())&&(e=Fe()),e}function $t(){var e,t,r,i;return i=o,"nonce"===n.substr(o,5).toLowerCase()?(e=n.substr(o,5),o+=5):(e=null,0===s&&a('"nonce"')),null!==e&&null!==(t=M())&&null!==(r=Xt())?e=[e,t,r]:(e=null,o=i),e}function Xt(){var e,t,n;return t=o,null!==(e=z())&&(n=e,e=void(Fn.nonce=n)),null===e&&(o=t),e}function Jt(){var e,t,r,i,l,u;return i=o,l=o,"opaque"===n.substr(o,6).toLowerCase()?(e=n.substr(o,6),o+=6):(e=null,0===s&&a('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,o=l),null!==e&&(u=e[2],e=void(Fn.opaque=u)),null===e&&(o=i),e}function Qt(){var e,t,r,i,l;return i=o,"stale"===n.substr(o,5).toLowerCase()?(e=n.substr(o,5),o+=5):(e=null,0===s&&a('"stale"')),null!==e&&null!==(t=M())?(l=o,"true"===n.substr(o,4).toLowerCase()?(r=n.substr(o,4),o+=4):(r=null,0===s&&a('"true"')),null!==r&&(r=void(Fn.stale=!0)),null===r&&(o=l),null===r&&(l=o,"false"===n.substr(o,5).toLowerCase()?(r=n.substr(o,5),o+=5):(r=null,0===s&&a('"false"')),null!==r&&(r=void(Fn.stale=!1)),null===r&&(o=l)),null!==r?e=[e,t,r]:(e=null,o=i)):(e=null,o=i),e}function Zt(){var e,t,r,i,l,u;return i=o,l=o,"algorithm"===n.substr(o,9).toLowerCase()?(e=n.substr(o,9),o+=9):(e=null,0===s&&a('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(o,3).toLowerCase()?(r=n.substr(o,3),o+=3):(r=null,0===s&&a('"MD5"')),null===r&&("md5-sess"===n.substr(o,8).toLowerCase()?(r=n.substr(o,8),o+=8):(r=null,0===s&&a('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,o=l)):(e=null,o=l),null!==e&&(u=e[2],e=void(Fn.algorithm=u.toUpperCase())),null===e&&(o=i),e}function en(){var e,t,r,i,l,u,c,f,d,h;if(f=o,"qop"===n.substr(o,3).toLowerCase()?(e=n.substr(o,3),o+=3):(e=null,0===s&&a('"qop"')),null!==e)if(null!==(t=M()))if(null!==(r=V())){if(d=o,null!==(i=tn())){for(l=[],h=o,44===n.charCodeAt(o)?(u=",",o++):(u=null,0===s&&a('","')),null!==u&&null!==(c=tn())?u=[u,c]:(u=null,o=h);null!==u;)l.push(u),h=o,44===n.charCodeAt(o)?(u=",",o++):(u=null,0===s&&a('","')),null!==u&&null!==(c=tn())?u=[u,c]:(u=null,o=h);null!==l?i=[i,l]:(i=null,o=d)}else i=null,o=d;null!==i&&null!==(l=W())?e=[e,t,r,i,l]:(e=null,o=f)}else e=null,o=f;else e=null,o=f;else e=null,o=f;return e}function tn(){var e,t,r;return t=o,"auth-int"===n.substr(o,8).toLowerCase()?(e=n.substr(o,8),o+=8):(e=null,0===s&&a('"auth-int"')),null===e&&("auth"===n.substr(o,4).toLowerCase()?(e=n.substr(o,4),o+=4):(e=null,0===s&&a('"auth"')),null===e&&(e=k())),null!==e&&(r=e,Fn.qop||(Fn.qop=[]),e=void Fn.qop.push(r.toLowerCase())),null===e&&(o=t),e}function nn(){var e,t,n,r,i,s,l;if(i=o,s=o,null!==(e=mt())){for(t=[],l=o,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,o=l);null!==n;)t.push(n),l=o,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,o=l);null!==t?e=[e,t]:(e=null,o=s)}else e=null,o=s;return null!==e&&(e=function(e){var t;Fn.multi_header||(Fn.multi_header=[]);try{t=new jn(Fn.uri,Fn.display_name,Fn.params),delete Fn.uri,delete Fn.display_name,delete Fn.params}catch(e){t=null}Fn.multi_header.push({possition:o,offset:e,parsed:t})}(i)),null===e&&(o=i),e}function rn(){var e;return null===(e=on())&&(e=Et()),e}function on(){var e,t,r,i,l,u,c;if(l=o,u=o,"cause"===n.substr(o,5).toLowerCase()?(e=n.substr(o,5),o+=5):(e=null,0===s&&a('"cause"')),null!==e)if(null!==(t=M())){if(null!==(i=f()))for(r=[];null!==i;)r.push(i),i=f();else r=null;null!==r?e=[e,t,r]:(e=null,o=u)}else e=null,o=u;else e=null,o=u;return null!==e&&(c=e[2],e=void(Fn.cause=parseInt(c.join("")))),null===e&&(o=l),e}function sn(){var e,t,n,r,i,s;if(i=o,null!==(e=mt())){for(t=[],s=o,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,o=s);null!==n;)t.push(n),s=o,null!==(n=B())&&null!==(r=Et())?n=[n,r]:(n=null,o=s);null!==t?e=[e,t]:(e=null,o=i)}else e=null,o=i;return e}function ln(){var e,t,r;return t=o,"active"===n.substr(o,6).toLowerCase()?(e=n.substr(o,6),o+=6):(e=null,0===s&&a('"active"')),null===e&&("pending"===n.substr(o,7).toLowerCase()?(e=n.substr(o,7),o+=7):(e=null,0===s&&a('"pending"')),null===e&&("terminated"===n.substr(o,10).toLowerCase()?(e=n.substr(o,10),o+=10):(e=null,0===s&&a('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(Fn.state=n.substring(o,r))),null===e&&(o=t),e}function un(){var e,t,r,i,l,u,c,f;return i=o,l=o,"reason"===n.substr(o,6).toLowerCase()?(e=n.substr(o,6),o+=6):(e=null,0===s&&a('"reason"')),null!==e&&null!==(t=M())&&null!==(r=an())?e=[e,t,r]:(e=null,o=l),null!==e&&(e=void(void 0!==(u=e[2])&&(Fn.reason=u))),null===e&&(o=i),null===e&&(i=o,l=o,"expires"===n.substr(o,7).toLowerCase()?(e=n.substr(o,7),o+=7):(e=null,0===s&&a('"expires"')),null!==e&&null!==(t=M())&&null!==(r=bt())?e=[e,t,r]:(e=null,o=l),null!==e&&(e=void(void 0!==(f=e[2])&&(Fn.expires=f))),null===e&&(o=i),null===e&&(i=o,l=o,"retry_after"===n.substr(o,11).toLowerCase()?(e=n.substr(o,11),o+=11):(e=null,0===s&&a('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=bt())?e=[e,t,r]:(e=null,o=l),null!==e&&(e=void(void 0!==(c=e[2])&&(Fn.retry_after=c))),null===e&&(o=i),null===e&&(e=Et()))),e}function an(){var e;return"deactivated"===n.substr(o,11).toLowerCase()?(e=n.substr(o,11),o+=11):(e=null,0===s&&a('"deactivated"')),null===e&&("probation"===n.substr(o,9).toLowerCase()?(e=n.substr(o,9),o+=9):(e=null,0===s&&a('"probation"')),null===e&&("rejected"===n.substr(o,8).toLowerCase()?(e=n.substr(o,8),o+=8):(e=null,0===s&&a('"rejected"')),null===e&&("timeout"===n.substr(o,7).toLowerCase()?(e=n.substr(o,7),o+=7):(e=null,0===s&&a('"timeout"')),null===e&&("giveup"===n.substr(o,6).toLowerCase()?(e=n.substr(o,6),o+=6):(e=null,0===s&&a('"giveup"')),null===e&&("noresource"===n.substr(o,10).toLowerCase()?(e=n.substr(o,10),o+=10):(e=null,0===s&&a('"noresource"')),null===e&&("invariant"===n.substr(o,9).toLowerCase()?(e=n.substr(o,9),o+=9):(e=null,0===s&&a('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=jt())&&(e=Et()),e}function fn(){var e,t,n,r,i,s,l,u;if(l=o,null!==(e=yn()))if(null!==(t=C()))if(null!==(n=Sn())){for(r=[],u=o,null!==(i=B())&&null!==(s=dn())?i=[i,s]:(i=null,o=u);null!==i;)r.push(i),u=o,null!==(i=B())&&null!==(s=dn())?i=[i,s]:(i=null,o=u);null!==r?e=[e,t,n,r]:(e=null,o=l)}else e=null,o=l;else e=null,o=l;else e=null,o=l;return e}function dn(){var e;return null===(e=hn())&&null===(e=_n())&&null===(e=pn())&&null===(e=mn())&&null===(e=vn())&&(e=Et()),e}function hn(){var e,t,r,i,l,u;return i=o,l=o,"ttl"===n.substr(o,3).toLowerCase()?(e=n.substr(o,3),o+=3):(e=null,0===s&&a('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,o=l),null!==e&&(u=e[2],e=void(Fn.ttl=u)),null===e&&(o=i),e}function _n(){var e,t,r,i,l,u;return i=o,l=o,"maddr"===n.substr(o,5).toLowerCase()?(e=n.substr(o,5),o+=5):(e=null,0===s&&a('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,o=l),null!==e&&(u=e[2],e=void(Fn.maddr=u)),null===e&&(o=i),e}function pn(){var e,t,r,i,l,u;return i=o,l=o,"received"===n.substr(o,8).toLowerCase()?(e=n.substr(o,8),o+=8):(e=null,0===s&&a('"received"')),null!==e&&null!==(t=M())?(null===(r=pe())&&(r=de()),null!==r?e=[e,t,r]:(e=null,o=l)):(e=null,o=l),null!==e&&(u=e[2],e=void(Fn.received=u)),null===e&&(o=i),e}function mn(){var e,t,r,i,l,u;return i=o,l=o,"branch"===n.substr(o,6).toLowerCase()?(e=n.substr(o,6),o+=6):(e=null,0===s&&a('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,o=l),null!==e&&(u=e[2],e=void(Fn.branch=u)),null===e&&(o=i),e}function vn(){var e,t,r,i,l;return i=o,"rport"===n.substr(o,5).toLowerCase()?(e=n.substr(o,5),o+=5):(e=null,0===s&&a('"rport"')),null!==e?(l=o,null!==(t=M())&&null!==(r=gn())?t=[t,r]:(t=null,o=l),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,o=i)):(e=null,o=i),e}function gn(){var e,t,n,r,i,s,l,u;return s=o,l=o,null!==(e=null!==(e=f())?e:"")&&null!==(t=null!==(t=f())?t:"")&&null!==(n=null!==(n=f())?n:"")&&null!==(r=null!==(r=f())?r:"")&&null!==(i=null!==(i=f())?i:"")?e=[e,t,n,r,i]:(e=null,o=l),null!==e&&(u=e,e=void(Fn.rport=parseInt(u.join("")))),null===e&&(o=s),e}function yn(){var e,t,n,r,i,s;return s=o,null!==(e=Tn())&&null!==(t=D())&&null!==(n=k())&&null!==(r=D())&&null!==(i=bn())?e=[e,t,n,r,i]:(e=null,o=s),e}function Tn(){var e,t,r;return t=o,"sip"===n.substr(o,3).toLowerCase()?(e=n.substr(o,3),o+=3):(e=null,0===s&&a('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(Fn.protocol=r)),null===e&&(o=t),e}function bn(){var e,t,r;return t=o,"udp"===n.substr(o,3).toLowerCase()?(e=n.substr(o,3),o+=3):(e=null,0===s&&a('"UDP"')),null===e&&("tcp"===n.substr(o,3).toLowerCase()?(e=n.substr(o,3),o+=3):(e=null,0===s&&a('"TCP"')),null===e&&("tls"===n.substr(o,3).toLowerCase()?(e=n.substr(o,3),o+=3):(e=null,0===s&&a('"TLS"')),null===e&&("sctp"===n.substr(o,4).toLowerCase()?(e=n.substr(o,4),o+=4):(e=null,0===s&&a('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(Fn.transport=r)),null===e&&(o=t),e}function Sn(){var e,t,n,r,i;return r=o,null!==(e=En())?(i=o,null!==(t=G())&&null!==(n=Cn())?t=[t,n]:(t=null,o=i),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,o=r)):(e=null,o=r),e}function En(){var e,t,r;return t=o,null===(e=pe())&&null===(e=fe())&&(e=ue()),null!==e&&(r=t,e=void(Fn.host=n.substring(o,r))),null===e&&(o=t),e}function Cn(){var e,t,n,r,i,s,l,u;return s=o,l=o,null!==(e=null!==(e=f())?e:"")&&null!==(t=null!==(t=f())?t:"")&&null!==(n=null!==(n=f())?n:"")&&null!==(r=null!==(r=f())?r:"")&&null!==(i=null!==(i=f())?i:"")?e=[e,t,n,r,i]:(e=null,o=l),null!==e&&(u=e,e=void(Fn.port=parseInt(u.join("")))),null===e&&(o=s),e}function An(){var e,t,n,r,i;return r=o,i=o,null!==(e=f())&&null!==(t=null!==(t=f())?t:"")&&null!==(n=null!==(n=f())?n:"")?e=[e,t,n]:(e=null,o=i),null!==e&&(e=parseInt(e.join(""))),null===e&&(o=r),e}function wn(){var e,t,n;return t=o,null!==(e=bt())&&(n=e,e=void(Fn.expires=n)),null===e&&(o=t),e}function Rn(){var e;return null===(e=In())&&(e=Et()),e}function In(){var e,t,r,i,l,u;return i=o,l=o,"refresher"===n.substr(o,9).toLowerCase()?(e=n.substr(o,9),o+=9):(e=null,0===s&&a('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(o,3).toLowerCase()?(r=n.substr(o,3),o+=3):(r=null,0===s&&a('"uac"')),null===r&&("uas"===n.substr(o,3).toLowerCase()?(r=n.substr(o,3),o+=3):(r=null,0===s&&a('"uas"'))),null!==r?e=[e,t,r]:(e=null,o=l)):(e=null,o=l),null!==e&&(u=e[2],e=void(Fn.refresher=u.toLowerCase())),null===e&&(o=i),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=C());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=C());return e}function Nn(){var e,t,r,i,l,u,c,f,d,h,_,p;return h=o,_=o,null!==(e=Pn())?(45===n.charCodeAt(o)?(t="-",o++):(t=null,0===s&&a('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(o)?(i="-",o++):(i=null,0===s&&a('"-"')),null!==i&&null!==(l=kn())?(45===n.charCodeAt(o)?(u="-",o++):(u=null,0===s&&a('"-"')),null!==u&&null!==(c=kn())?(45===n.charCodeAt(o)?(f="-",o++):(f=null,0===s&&a('"-"')),null!==f&&null!==(d=Un())?e=[e,t,r,i,l,u,c,f,d]:(e=null,o=_)):(e=null,o=_)):(e=null,o=_)):(e=null,o=_)):(e=null,o=_),null!==e&&(p=h,e[0],e=void(Fn=n.substring(o+5,p))),null===e&&(o=h),e}function kn(){var e,t,n,r,i;return i=o,null!==(e=h())&&null!==(t=h())&&null!==(n=h())&&null!==(r=h())?e=[e,t,n,r]:(e=null,o=i),e}function Pn(){var e,t,n;return n=o,null!==(e=kn())&&null!==(t=kn())?e=[e,t]:(e=null,o=n),e}function Un(){var e,t,n,r;return r=o,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,o=r),e}function xn(){var e,t,r,i,l,u,c;return i=o,l=o,null!==(e=U())?(u=o,64===n.charCodeAt(o)?(t="@",o++):(t=null,0===s&&a('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,o=u),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,o=l)):(e=null,o=l),null!==e&&(c=i,e=void(Fn.call_id=n.substring(o,c))),null===e&&(o=i),e}function Dn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,i,l,u;return i=o,l=o,"to-tag"===n.substr(o,6)?(e="to-tag",o+=6):(e=null,0===s&&a('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,o=l),null!==e&&(u=e[2],e=void(Fn.to_tag=u)),null===e&&(o=i),e}function qn(){var e,t,r,i,l,u;return i=o,l=o,"from-tag"===n.substr(o,8)?(e="from-tag",o+=8):(e=null,0===s&&a('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,o=l),null!==e&&(u=e[2],e=void(Fn.from_tag=u)),null===e&&(o=i),e}function Ln(){var e,t;return t=o,"early-only"===n.substr(o,10)?(e="early-only",o+=10):(e=null,0===s&&a('"early-only"')),null!==e&&(e=void(Fn.early_only=!0)),null===e&&(o=t),e}var Hn=e("./URI"),jn=e("./NameAddrHeader"),Fn={};if(null===i[r]()||o!==n.length){var Bn=Math.max(o,l),Gn=Bn2&&void 0!==arguments[2]?arguments[2]:{},i=e;if(void 0===e||void 0===t)throw new TypeError("Not enough arguments");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(i));var o=h.cloneArray(r.extraHeaders),s=h.cloneObject(r.eventHandlers),l=r.contentType||"text/plain",u={};for(var a in r.fromUserName&&(u.from_uri=new m("sip",r.fromUserName,this._ua.configuration.uri.host),o.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),r.fromDisplayName&&(u.from_display_name=r.fromDisplayName),s)Object.prototype.hasOwnProperty.call(s,a)&&this.on(a,s[a]);o.push("Content-Type: ".concat(l)),this._request=new d.OutgoingRequest(f.MESSAGE,e,this._ua,u,o),t&&(this._request.body=t);var c=new _(this._ua,this._request,{onRequestTimeout:function(){n._onRequestTimeout()},onTransportError:function(){n._onTransportError()},onReceiveResponse:function(e){n._receiveResponse(e)}});this._newMessage("local",this._request),c.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 p.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),i=e.body;if("incoming"!==this._direction)throw new p.NotSupportedError('"reject" not supported for outgoing Message');if(this._is_replied)throw new Error("incoming Message already replied");if(t<300||t>=700)throw new TypeError("Invalid status_code: ".concat(t));this._is_replied=!0,this._request.reply(t,n,r,i)}},{key:"_receiveResponse",value:function(e){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(e.status_code):break;case/^2[0-9]{2}$/.test(e.status_code):this._succeeded("remote",e);break;default:var t=h.sipErrorCause(e.status_code);this._failed("remote",e,t)}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,f.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,f.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){v.debug("MESSAGE failed"),this._close(),v.debug('emit "failed"'),this.emit("failed",{originator:e,response:t||null,cause:n})}},{key:"_succeeded",value:function(e,t){v.debug("MESSAGE succeeded"),this._close(),v.debug('emit "succeeded"'),this.emit("succeeded",{originator:e,response:t})}}])&&i(n.prototype,r),o&&i(n,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,r,o}()},{"./Constants":2,"./Exceptions":6,"./Logger":9,"./RequestSender":21,"./SIPMessage":22,"./URI":29,"./Utils":30,events:33}],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 i(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}}])&&i(t.prototype,n),r&&i(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,n,r}()},{"./Grammar":7,"./URI":29}],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 i(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return o(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?o(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,l=!0,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,s=e},f:function(){try{l||null==n.return||n.return()}finally{if(u)throw s}}}}function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n0&&o._setExpiresTimer(),o}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&c(e,t)}(t,f),n=t,o=[{key:"C",get:function(){return v}}],(r=[{key:"C",get:function(){return v}},{key:"receiveRequest",value:function(e){if(e.method===h.SUBSCRIBE){e.hasHeader("expires")?this._expires=parseInt(e.getHeader("expires")):(this._expires=900,m.debug("missing Expires header field, default value set: ".concat(this._expires))),e.reply(200,null,["Expires: ".concat(this._expires),"".concat(this._contact)]);var t=e.body,n=e.getHeader("content-type"),r=0===this._expires;r||this._setExpiresTimer(),m.debug('emit "subscribe"'),this.emit("subscribe",r,e,t,n),r&&this._dialogTerminated(v.RECEIVE_UNSUBSCRIBE)}else e.reply(405)}},{key:"start",value:function(){m.debug("start()"),this.receiveRequest(this._initial_subscribe)}},{key:"setActiveState",value:function(){m.debug("setActiveState()"),this._state===v.STATE_PENDING&&(this._state=v.STATE_ACTIVE)}},{key:"notify",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(m.debug("notify()"),this._state===v.STATE_TERMINATED)throw new Error("Cannot send notify in terminated state.");var t=Math.floor((this._expires_timestamp-(new Date).getTime())/1e3);t<0&&(t=0),this._notify([";expires=".concat(t)],e)}},{key:"_notify",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;if(this._dialog){var o,s="Subscription-State: ".concat(this._stateToString()),l=i(e);try{for(l.s();!(o=l.n()).done;){s+=o.value}}catch(e){l.e(e)}finally{l.f()}var u=this._headers.slice();u.push(s),r&&(u=u.concat(r)),n&&u.push("Content-Type: ".concat(this._content_type)),this._dialog.sendRequest(h.NOTIFY,{body:n,extraHeaders:u,eventHandlers:{onRequestTimeout:function(){t._dialogTerminated(v.NOTIFY_RESPONSE_TIMEOUT)},onTransportError:function(){t._dialogTerminated(v.NOTIFY_TRANSPORT_ERROR)},onErrorResponse:function(e){401===e.status_code||407===e.status_code?t._dialogTerminated(v.NOTIFY_FAILED_AUTHENTICATION):t._dialogTerminated(v.NOTIFY_NON_OK_RESPONSE)},onDialogError:function(){t._dialogTerminated(v.NOTIFY_NON_OK_RESPONSE)}}})}else m.warn("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;m.debug("terminate()"),this._state=v.STATE_TERMINATED;var r=[];t&&r.push(";reason=".concat(t)),null!==n&&r.push(";retry-after=".concat(n)),this._notify(r,e),this._dialogTerminated("timeout"===t?v.SUBSCRIPTION_EXPIRED:v.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){this._dialog&&(this._state=v.STATE_TERMINATED,clearTimeout(this._expires_timer),this._dialog&&(this._dialog.terminate(),this._dialog=null),e!==v.SUBSCRIPTION_EXPIRED&&(m.debug('emit "terminated" code='.concat(e,", send final notify=false")),this.emit("terminated",e,!1)))}},{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&&(m.debug('emit "terminated" code='.concat(v.SUBSCRIPTION_EXPIRED,", send final notify=true")),e.emit("terminated",v.SUBSCRIPTION_EXPIRED,!0))},1e3*this._expires)}},{key:"_stateToString",value:function(){switch(this._state){case v.STATE_PENDING:return"pending";case v.STATE_ACTIVE:return"active";case v.STATE_TERMINATED:return"terminated";default:throw new TypeError("wrong state value")}}}])&&s(n.prototype,r),o&&s(n,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,r,o}()},{"./Constants":2,"./Dialog":3,"./Logger":9,"./Utils":30,events:33}],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 i(e,t){for(var n=0;n2&&void 0!==arguments[2]?arguments[2]:{},i=e;if(void 0===e)throw new TypeError("A target is required for OPTIONS");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(i));var o=h.cloneArray(r.extraHeaders),s=h.cloneObject(r.eventHandlers),l=r.contentType||"application/sdp";for(var u in s)Object.prototype.hasOwnProperty.call(s,u)&&this.on(u,s[u]);o.push("Content-Type: ".concat(l)),this._request=new d.OutgoingRequest(f.OPTIONS,e,this._ua,null,o),t&&(this._request.body=t);var a=new _(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=h.cloneArray(e.extraHeaders),n=e.body;if("incoming"!==this._direction)throw new p.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=h.cloneArray(e.extraHeaders),i=e.body;if("incoming"!==this._direction)throw new p.NotSupportedError('"reject" not supported for outgoing Options');if(this._is_replied)throw new Error("incoming Options already replied");if(t<300||t>=700)throw new TypeError("Invalid status_code: ".concat(t));this._is_replied=!0,this._request.reply(t,n,r,i)}},{key:"_receiveResponse",value:function(e){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(e.status_code):break;case/^2[0-9]{2}$/.test(e.status_code):this._succeeded("remote",e);break;default:var t=h.sipErrorCause(e.status_code);this._failed("remote",e,t)}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,f.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,f.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){m.debug("OPTIONS 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("OPTIONS succeeded"),this._close(),m.debug('emit "succeeded"'),this.emit("succeeded",{originator:e,response:t})}}])&&i(n.prototype,r),o&&i(n,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,r,o}()},{"./Constants":2,"./Exceptions":6,"./Logger":9,"./RequestSender":21,"./SIPMessage":22,"./Utils":30,events:33}],14:[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){if("string"==typeof e)return i(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?i(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,o=function(){};return{s:o,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,l=!0,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,s=e},f:function(){try{l||null==n.return||n.return()}finally{if(u)throw s}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);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 s,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,s=e},f:function(){try{l||null==n.return||n.return()}finally{if(u)throw s}}}}function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;R.debug("connect()");var r=e,i=v.cloneObject(t.eventHandlers),o=v.cloneArray(t.extraHeaders),s=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 f in this._sessionTimers.enabled&&v.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=_.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=_.SESSION_EXPIRES),i)Object.prototype.hasOwnProperty.call(i,f)&&this.on(f,i[f]);this._from_tag=v.newTag();var d=t.anonymous||!1,h={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:d,outbound:!0}),d?(h.from_display_name="Anonymous",h.from_uri=new w("sip","anonymous","anonymous.invalid"),o.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),o.push("Privacy: id")):t.fromUserName&&(h.from_uri=new w("sip",t.fromUserName,this._ua.configuration.uri.host),o.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(h.from_display_name=t.fromDisplayName),o.push("Contact: ".concat(this._contact)),o.push("Content-Type: application/sdp"),this._sessionTimers.enabled&&o.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,h,o),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(s,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;R.debug("init_incoming()");var i=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==i?e.reply(415):(this._status=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]:{};R.debug("answer()");var n=this._request,r=v.cloneArray(t.extraHeaders),o=v.cloneObject(t.mediaConstraints),s=t.mediaStream||null,l=v.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,a=t.rtcAnswerConstraints||null,c=v.cloneObject(t.rtcOfferConstraints),f=!1,d=!1,h=!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=i(g.media);try{for(T.s();!(y=T.n()).done;){var b=y.value;"audio"===b.type&&(f=!0,b.direction&&"sendrecv"!==b.direction||(h=!0)),"video"===b.type&&(d=!0,b.direction&&"sendrecv"!==b.direction||(m=!0))}}catch(e){T.e(e)}finally{T.f()}if(s&&!1===o.audio){var S,E=i(s.getAudioTracks());try{for(E.s();!(S=E.n()).done;){var C=S.value;s.removeTrack(C)}}catch(e){E.e(e)}finally{E.f()}}if(s&&!1===o.video){var A,w=i(s.getVideoTracks());try{for(w.s();!(A=w.n()).done;){var O=A.value;s.removeTrack(O)}}catch(e){w.e(e)}finally{w.f()}}s||void 0!==o.audio||(o.audio=h),s||void 0!==o.video||(o.video=m),s||f||c.offerToReceiveAudio||(o.audio=!1),s||d||c.offerToReceiveVideo||(o.video=!1),this._createRTCConnection(l,u),Promise.resolve().then(function(){return s||(o.audio||o.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(o).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),R.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};R.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),R.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&&R.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]:{};R.debug("terminate()");var n,r=t.cause||_.causes.BYE,i=v.cloneArray(t.extraHeaders),o=t.body,s=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(R.debug("canceling session"),s&&(s<200||s>=700))throw new TypeError("Invalid status_code: ".concat(s));s&&(l=l||_.REASON_PHRASE[s]||"",n="SIP ;cause=".concat(s,' ;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(R.debug("rejecting session"),(s=s||480)<300||s>=700)throw new TypeError("Invalid status_code: ".concat(s));this._request.reply(s,l,i,o),this._failed("local",null,_.causes.REJECTED);break;case I.STATUS_WAITING_FOR_ACK:case I.STATUS_CONFIRMED:if(R.debug("terminating session"),l=t.reason_phrase||_.REASON_PHRASE[s]||"",s&&(s<200||s>=700))throw new TypeError("Invalid status_code: ".concat(s));if(s&&i.push("Reason: SIP ;cause=".concat(s,'; 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:i,body:o}),u.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===m.C.STATUS_TERMINATED&&(e.sendRequest(_.BYE,{extraHeaders:i,body:o}),u.terminate())}),this._ended("local",null,r),this._dialog=u,this._ua.newDialog(u)}else this.sendRequest(_.BYE,{extraHeaders:i,body:o}),this._ended("local",null,r)}}},{key:"sendDTMF",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};R.debug("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,i=t.interToneGap||null,o=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(o!==_.DTMF_TRANSPORT.INFO&&o!==_.DTMF_TRANSPORT.RFC2833)throw new TypeError("invalid transportType: ".concat(o));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?rS.C.MAX_DURATION?(R.debug('"duration" value is greater than the maximum allowed, setting it to '.concat(S.C.MAX_DURATION," milliseconds")),r=S.C.MAX_DURATION):r=Math.abs(r):r=S.C.DEFAULT_DURATION,t.duration=r,i&&!v.isDecimal(i))throw new TypeError("Invalid interToneGap: ".concat(i));if(i?i=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)s=2e3;else{var u=new S(this);t.eventHandlers={onFailed:function(){o._tones=null}},u.send(l,t),s=r+i}setTimeout(e.bind(this),s)}.call(this));else{var s=this._getDTMFRTPSender();s&&(e=s.toneBuffer+e,s.insertDTMF(e,r,i))}}},{key:"sendInfo",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(R.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 E(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.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};R.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(R.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(R.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;R.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 i={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:i,rtcOfferConstraints:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:i,rtcOfferConstraints:r,extraHeaders:t.extraHeaders}),!0}},{key:"refer",value:function(e,t){var n=this;R.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 i=new A(this);i.sendRefer(e,t);var o=i.id;return this._referSubscribers[o]=i,i.on("requestFailed",function(){delete n._referSubscribers[o]}),i.on("accepted",function(){delete n._referSubscribers[o]}),i.on("failed",function(){delete n._referSubscribers[o]}),i}},{key:"sendRequest",value:function(e,t){return R.debug("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(R.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};R.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}),R.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 i=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;i&&i.match(/^application\/dtmf-relay/i)?new S(this).init_incoming(e):void 0!==i?new E(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(){R.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(){R.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(){R.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){R.debug("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){R.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||(R.debug("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(R.debug("_isReadyToReOffer() | session not established yet"),!1):(R.debug("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(R.debug("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(R.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){R.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&&(R.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})}),R.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(R.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 R.warn('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return R.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,R.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',e),n.emit("peerconnection:setlocaldescriptionfailed",e),Promise.reject(e)})}).then(function(){var i=t&&t.iceRestart;if("complete"===r.iceGatheringState&&!i||"gathering"===r.iceGatheringState&&n._iceReady){n._rtcReady=!0;var o={originator:"local",type:e,sdp:r.localDescription.sdp};return R.debug('emit "sdp"'),n.emit("sdp",o),Promise.resolve(o.sdp)}return new Promise(function(t){var i,o,s=!1;n._iceReady=!1;var l=function(){if(!s){r.removeEventListener("icecandidate",i),r.removeEventListener("icegatheringstatechange",o),s=!0,n._rtcReady=!0,n._iceReady=!0;var l={originator:"local",type:e,sdp:r.localDescription.sdp};R.debug('emit "sdp"'),n.emit("sdp",l),t(l.sdp)}};r.addEventListener("icecandidate",i=function(e){var t=e.candidate;t?n.emit("icecandidate",{candidate:t,ready:l}):l()}),r.addEventListener("icegatheringstatechange",o=function(){"complete"===r.iceGatheringState&&l()})})})}},{key:"_createDialog",value:function(e,t,n){var r="UAS"===t?e.to_tag:e.from_tag,i="UAS"===t?e.from_tag:e.to_tag,o=e.call_id+r+i,s=this._earlyDialogs[o];if(n)return!!s||((s=new T(this,e,t,T.C.STATUS_EARLY)).error?(R.debug(s.error),this._failed("remote",e,_.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[o]=s,!0));if(this._from_tag=e.from_tag,this._to_tag=e.to_tag,s)return s.update(e,t),this._dialog=s,delete this._earlyDialogs[o],!0;var l=new T(this,e,t);return l.error?(R.debug(l.error),this._failed("remote",e,_.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;R.debug("receiveReinvite()");var n=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0,r={request:e,callback:void 0,reject:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};i=!0;var n=t.status_code||403,r=t.reason_phrase||"",o=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,o)}.bind(this)},i=!1;if(this.emit("reinvite",r),!i){if(this._late_sdp=!1,!e.body)return this._late_sdp=!0,this._remoteHold&&(this._remoteHold=!1,this._onunhold("remote")),void(this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._createLocalDescription("offer",t._rtcOfferConstraints)}).then(function(e){o.call(t,e)}).catch(function(){e.reply(500)}));if("application/sdp"!==n)return R.debug("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==I.STATUS_TERMINATED&&o.call(t,e)}).catch(function(e){R.warn(e)})}function o(t){var n=this,i=["Contact: ".concat(this._contact)];this._handleSessionTimersInIncomingRequest(e,i),this._late_sdp&&(t=this._mangleOffer(t)),e.reply(200,null,i,t,function(){n._status=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.debug("receiveUpdate()");var n=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0,r={request:e,callback:void 0,reject:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};i=!0;var n=t.status_code||403,r=t.reason_phrase||"",o=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,o)}.bind(this)},i=!1;if(this.emit("update",r),!i)if(e.body){if("application/sdp"!==n)return R.debug("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==I.STATUS_TERMINATED&&o.call(t,e)}).catch(function(e){R.warn(e)})}else o.call(this,null);function o(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.debug("_processInDialogSdpOffer()");var n,r=e.parseSDP(),o=!1,s=i(r.media);try{for(s.s();!(n=s.n()).done;){var l=n.value;if(-1!==O.indexOf(l.type)){var u=l.direction||r.direction||"sendrecv";if("sendonly"!==u&&"inactive"!==u){o=!1;break}o=!0}}}catch(e){s.e(e)}finally{s.f()}var a={originator:"remote",type:"offer",sdp:e.body};R.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),R.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===o?(t._remoteHold=!1,t._onunhold("remote")):!1===t._remoteHold&&!0===o&&(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.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){R.warn("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var n=this;if(R.debug("receiveRefer()"),!e.refer_to)return R.debug("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==_.SIP)return R.debug("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var r=new C(this,e.cseq);R.debug('emit "refer"'),this.emit("refer",{request:e,accept:function(i,o){(function(n){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(n="function"==typeof n?n:null,this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;var o=new t(this._ua);if(o.on("progress",function(e){var t=e.response;r.notify(t.status_code,t.reason_phrase)}),o.on("accepted",function(e){var t=e.response;r.notify(t.status_code,t.reason_phrase)}),o.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 s=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));i.extraHeaders=v.cloneArray(i.extraHeaders),i.extraHeaders.push("Replaces: ".concat(s))}o.connect(e.refer_to.uri.toAor(),i,n)}).call(n,i,o)},reject:function(){(function(){r.notify(603)}).call(n)}})}},{key:"_receiveNotify",value:function(e){switch(R.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 n=this;R.debug("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(r){(function(n){var r=this;if(this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;var i=new t(this._ua);i.on("confirmed",function(){r.terminate()}),i.init_incoming(e,n)}).call(n,r)},reject:function(){(function(){R.debug("Replaced INVITE rejected by the user"),e.reply(486)}).call(n)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,i=new b(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),R.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,R.debug('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),i.send()}).catch(function(e){r._status!==I.STATUS_TERMINATED&&R.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;R.warn("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(R.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 R.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){R.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};R.debug('emit "sdp"'),this.emit("sdp",r);var i=new RTCSessionDescription({type:"answer",sdp:r.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._connection.setRemoteDescription(i)}).then(function(){return t._progress("remote",e)}).catch(function(e){R.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 o={originator:"remote",type:"answer",sdp:e.body};R.debug('emit "sdp"'),this.emit("sdp",o);var s=new RTCSessionDescription({type:"answer",sdp:o.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(s).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),R.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]:{};R.debug("sendReinvite()");var n=v.cloneArray(t.extraHeaders),r=v.cloneObject(t.eventHandlers),i=t.rtcOfferConstraints||this._rtcOfferConstraints||null,o=!1;function s(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),n.push("Content-Type: application/sdp"),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return e._createLocalDescription("offer",i)}).then(function(t){var i={originator:"local",type:"offer",sdp:t=e._mangleOffer(t)};R.debug('emit "sdp"'),e.emit("sdp",i),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),o)return;if(this._handleSessionTimersInIncomingResponse(e),!e.body)return void s.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void s.call(this);var n={originator:"remote",type:"answer",sdp:e.body};R.debug('emit "sdp"'),this.emit("sdp",n);var i=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._connection.setRemoteDescription(i)}).then(function(){r.succeeded&&r.succeeded(e)}).catch(function(e){s.call(t),R.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}).call(e,t),o=!0},onErrorResponse:function(t){s.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){s()})}},{key:"_sendUpdate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};R.debug("sendUpdate()");var n=v.cloneArray(t.extraHeaders),r=v.cloneObject(t.eventHandlers),i=t.rtcOfferConstraints||this._rtcOfferConstraints||null,o=t.sdpOffer||!1,s=!1;function l(e){var t=this;if(this._status!==I.STATUS_TERMINATED&&!s)if(this._handleSessionTimersInIncomingResponse(e),o){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.debug('emit "sdp"'),this.emit("sdp",n);var i=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._connection.setRemoteDescription(i)}).then(function(){r.succeeded&&r.succeeded(e)}).catch(function(e){u.call(t),R.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")),o?(n.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return e._createLocalDescription("offer",i)}).then(function(t){var r={originator:"local",type:"offer",sdp:t=e._mangleOffer(t)};R.debug('emit "sdp"'),e.emit("sdp",r),e.sendRequest(_.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),s=!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){R.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){R.debug("mangleOffer() | me on hold, mangling offer");var t,n=i(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.debug("mangleOffer() | both on hold, mangling offer");var o,s=i(e.media);try{for(s.s();!(o=s.n()).done;){var l=o.value;-1!==O.indexOf(l.type)&&(l.direction="inactive")}}catch(e){s.e(e)}finally{s.f()}}else if(this._remoteHold){R.debug("mangleOffer() | remote on hold, mangling offer");var u,a=i(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()&&(R.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&&(R.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=i(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=i(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.debug("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){R.debug("session connecting"),R.debug('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){R.debug("session progress"),R.debug('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){R.debug("session accepted"),this._start_time=new Date,R.debug('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){R.debug("session confirmed"),this._is_confirmed=!0,R.debug('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){R.debug("session ended"),this._end_time=new Date,this._close(),R.debug('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){R.debug("session failed"),R.debug('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),R.debug('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){R.debug("session onhold"),this._setLocalMediaStatus(),R.debug('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){R.debug("session onunhold"),this._setLocalMediaStatus(),R.debug('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;R.debug("session onmute"),this._setLocalMediaStatus(),R.debug('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;R.debug("session onunmute"),this._setLocalMediaStatus(),R.debug('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}}])&&s(n.prototype,r),o&&s(n,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,r,o}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./Logger":9,"./RTCSession/DTMF":16,"./RTCSession/Info":17,"./RTCSession/ReferNotifier":18,"./RTCSession/ReferSubscriber":19,"./RequestSender":21,"./SIPMessage":22,"./Timers":25,"./Transactions":26,"./URI":29,"./Utils":30,events:33,"sdp-transform":39}],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 i(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 d.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 i="Signal=".concat(this._tone,"\r\n");i+="Duration=".concat(this._duration),this._session.newDTMF({originator:"local",dtmf:this,request:this._request}),this._session.sendRequest(f.INFO,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t.emit("succeeded",{originator:"remote",response:e})},onErrorResponse:function(e){t.eventHandlers.onFailed&&t.eventHandlers.onFailed(),t.emit("failed",{originator:"remote",response:e})},onRequestTimeout:function(){t._session.onRequestTimeout()},onTransportError:function(){t._session.onTransportError()},onDialogError:function(){t._session.onDialogError()}},body:i})}},{key:"init_incoming",value:function(e){var t=/^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*/,n=/^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*/;if(this._direction="incoming",this._request=e,e.reply(200),e.body){var r=e.body.split("\n");r.length>=1&&t.test(r[0])&&(this._tone=r[0].replace(t,"$2")),r.length>=2&&n.test(r[1])&&(this._duration=parseInt(r[1].replace(n,"$2"),10))}this._duration||(this._duration=p.DEFAULT_DURATION),this._tone?this._session.newDTMF({originator:"remote",dtmf:this,request:e}):_.debug("invalid INFO DTMF received, discarded")}}])&&i(n.prototype,r),o&&i(n,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,r,o}(),t.exports.C=p},{"../Constants":2,"../Exceptions":6,"../Logger":9,"../Utils":30,events:33}],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 i(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 f.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var i=d.cloneArray(r.extraHeaders);i.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(c.INFO,{extraHeaders:i,eventHandlers:{onSuccessResponse:function(e){n.emit("succeeded",{originator:"remote",response:e})},onErrorResponse:function(e){n.emit("failed",{originator:"remote",response:e})},onTransportError:function(){n._session.onTransportError()},onRequestTimeout:function(){n._session.onRequestTimeout()},onDialogError:function(){n._session.onDialogError()}},body:t})}},{key:"init_incoming",value:function(e){this._direction="incoming",this.request=e,e.reply(200),this._contentType=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0,this._body=e.body,this._session.newInfo({originator:"remote",info:this,request:e})}}])&&i(n.prototype,r),o&&i(n,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,r,o}()},{"../Constants":2,"../Exceptions":6,"../Utils":30,events:33}],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 i(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),this._session.sendRequest(l.NOTIFY,{extraHeaders:["Event: ".concat(a.event_type,";id=").concat(this._id),"Subscription-State: ".concat(n),"Content-Type: ".concat(a.body_type)],body:"SIP/2.0 ".concat(e," ").concat(t),eventHandlers:{onErrorResponse:function(){this._active=!1}}}))}}])&&i(e.prototype,t),n&&i(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n}()},{"../Constants":2,"../Logger":9}],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 i(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:{};_.debug("sendRefer()");var r=h.cloneArray(n.extraHeaders),i=h.cloneObject(n.eventHandlers);for(var o in i)Object.prototype.hasOwnProperty.call(i,o)&&this.on(o,i[o]);var s=null;n.replaces&&(s=n.replaces._request.call_id,s+=";to-tag=".concat(n.replaces._to_tag),s+=";from-tag=".concat(n.replaces._from_tag),s=encodeURIComponent(s));var l="Refer-To: <".concat(e).concat(s?"?Replaces=".concat(s):"",">");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(f.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,f.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,f.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,f.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,f.causes.DIALOG_ERROR)}}});this._id=a.cseq}},{key:"receiveNotify",value:function(e){if(_.debug("receiveNotify()"),e.body){var t=d.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 _.debug('receiveNotify() | error parsing NOTIFY body: "'.concat(e.body,'"'))}}},{key:"_requestSucceeded",value:function(e){_.debug("REFER succeeded"),_.debug('emit "requestSucceeded"'),this.emit("requestSucceeded",{response:e})}},{key:"_requestFailed",value:function(e,t){_.debug("REFER failed"),_.debug('emit "requestFailed"'),this.emit("requestFailed",{response:e||null,cause:t})}}])&&i(n.prototype,r),o&&i(n,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,r,o}()},{"../Constants":2,"../Grammar":7,"../Logger":9,"../Utils":30,events:33}],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 i(e,t){for(var n=0;n"'),this._contact+=";reg-id=".concat(this._reg_id),this._contact+=";+sip.instance=".concat(this._sipInstance)},(t=[{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)f.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=l.newTag();this._ua.configuration.register_from_tag_trail&&("function"==typeof this._ua.configuration.register_from_tag_trail?n+=this._ua.configuration.register_from_tag_trail():n+=this._ua.configuration.register_from_tag_trail);var r=new a.OutgoingRequest(u.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1,from_tag:n},t),i=new c(this._ua,r,{onRequestTimeout:function(){e._registrationFailure(null,u.causes.REQUEST_TIMEOUT)},onTransportError:function(){e._registrationFailure(null,u.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")){f.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){f.debug("no Contact header pointing to us, response ignored");break}var i=r.getParam("expires");!i&&t.hasHeader("expires")&&(i=t.getHeader("expires")),i||(i=e._expires),(i=Number(i))<10&&(i=10);var o=i>64?1e3*i/2+Math.floor(1e3*(i/2-32)*Math.random()):1e3*i-5e3;e._registrationTimer=setTimeout(function(){e._registrationTimer=null,0===e._ua.listeners("registrationExpiring").length?e.register():e._ua.emit("registrationExpiring")},o),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._registering=!1,e.register()):(f.debug("423 response received for REGISTER without Min-Expires"),e._registrationFailure(t,u.causes.SIP_FAILURE_CODE));break;default:var s=l.sipErrorCause(t.status_code);e._registrationFailure(t,s)}}});this._registering=!0,i.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 a.OutgoingRequest(u.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},n);new c(this._ua,r,{onRequestTimeout:function(){e._unregistered(null,u.causes.REQUEST_TIMEOUT)},onTransportError:function(){e._unregistered(null,u.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=l.sipErrorCause(t.status_code);e._unregistered(t,n)}}}).send()}else f.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})}}])&&i(e.prototype,t),n&&i(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n}()},{"./Constants":2,"./Logger":9,"./RequestSender":21,"./SIPMessage":22,"./Utils":30}],21:[function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function i(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,s=!0,l=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){l=!0,o=e},f:function(){try{s||null==n.return||n.return()}finally{if(l)throw o}}}}function a(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",m.MAX_FORWARDS);var l=i.to_uri||n,u=i.to_tag?{tag:i.to_tag}:null,a=void 0!==i.to_display_name?i.to_display_name:null;this.to=new g(l,a,u),this.setHeader("to",this.to.toString());var f,d=i.from_uri||r.configuration.uri,h={tag:i.from_tag||v.newTag()};f=void 0!==i.from_display_name?i.from_display_name:r.configuration.display_name?r.configuration.display_name:null,this.from=new g(d,f,h),this.setHeader("from",this.from.toString());var _=i.call_id||r.configuration.jssip_id+v.createRandomToken(15);this.call_id=_,this.setHeader("call-id",_);var p=i.cseq||Math.floor(1e4*Math.random());this.cseq=p,this.setHeader("cseq","".concat(p," ").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=v.headerize(e),this.headers[e]){if(!(t>=this.headers[e].length)){var n=this.headers[e][t],r=n.raw;if(n.parsed)return n.parsed;var i=y.parse(r,e.replace(/-/g,"_"));return-1===i?(this.headers[e].splice(t,1),void T.debug('error parsing "'.concat(e,'" header field with value "').concat(r,'"'))):(n.parsed=i,i)}T.debug('not so many "'.concat(e,'" headers present'))}else T.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[v.headerize(e)]=[n]}},{key:"parseSDP",value:function(e){return!e&&this.sdp?this.sdp:(this.sdp=_.parse(this.body||""),this.sdp)}},{key:"toString",value:function(){return this.data}}])}(),C=function(e){function t(e){var n;return c(this,t),(n=r(this,t)).ua=e,n.headers={},n.ruri=null,n.transport=null,n.server_transaction=null,n}return o(t,E),d(t,[{key:"reply",value:function(e,t,n,r,i,o){var s=[],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||m.REASON_PHRASE[e]||"",n=v.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===m.INVITE&&e>100&&e<=200){var c,f=u(this.getHeaders("record-route"));try{for(f.s();!(c=f.n()).done;){var d=c.value;a+="Record-Route: ".concat(d,"\r\n")}}catch(e){f.e(e)}finally{f.f()}}var h,_=u(this.getHeaders("via"));try{for(_.s();!(h=_.n()).done;){var p=h.value;a+="Via: ".concat(p,"\r\n")}}catch(e){_.e(e)}finally{_.f()}!this.to_tag&&e>100?l+=";tag=".concat(v.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 m.INVITE:this.ua.configuration.session_timers&&s.push("timer"),(this.ua.contact.pub_gruu||this.ua.contact.temp_gruu)&&s.push("gruu"),s.push("ice","replaces");break;case m.UPDATE:this.ua.configuration.session_timers&&s.push("timer"),r&&s.push("ice"),s.push("replaces")}if(s.push("outbound"),this.method===m.OPTIONS?(a+="Allow: ".concat(m.ALLOWED_METHODS,"\r\n"),a+="Accept: ".concat(m.ACCEPTED_BODY_TYPES,"\r\n")):405===e?a+="Allow: ".concat(m.ALLOWED_METHODS,"\r\n"):415===e&&(a+="Accept: ".concat(m.ACCEPTED_BODY_TYPES,"\r\n")),a+="Supported: ".concat(s,"\r\n"),r){var b=v.str_utf8_length(r);a+="Content-Type: application/sdp\r\n",a+="Content-Length: ".concat(b,"\r\n\r\n"),a+=r}else a+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,a,i,o)}},{key:"reply_sl",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=this.getHeaders("via");if(!e||e<100||e>699)throw new TypeError("Invalid status_code: ".concat(e));if(t&&"string"!=typeof t&&!(t instanceof String))throw new TypeError("Invalid reason_phrase: ".concat(t));t=t||m.REASON_PHRASE[e]||"";var r,i="SIP/2.0 ".concat(e," ").concat(t,"\r\n"),o=u(n);try{for(o.s();!(r=o.n()).done;){var s=r.value;i+="Via: ".concat(s,"\r\n")}}catch(e){o.e(e)}finally{o.f()}var l=this.getHeader("To");if(!this.to_tag&&e>100?l+=";tag=".concat(v.newTag()):this.to_tag&&!this.s("to").hasParam("tag")&&(l+=";tag=".concat(this.to_tag)),i+="To: ".concat(l,"\r\n"),i+="From: ".concat(this.getHeader("From"),"\r\n"),i+="Call-ID: ".concat(this.call_id,"\r\n"),i+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n"),this.ua.configuration.extra_headers){var a,c=u(this.ua.configuration.extra_headers);try{for(c.s();!(a=c.n()).done;){var f=a.value;i+="".concat(f.trim(),"\r\n")}}catch(e){c.e(e)}finally{c.f()}}i+="Content-Length: ".concat(0,"\r\n\r\n"),this.transport.send(i)}}])}(),A=function(e){function t(){var e;return c(this,t),(e=r(this,t)).headers={},e.status_code=null,e.reason_phrase=null,e}return o(t,E),d(t)}();t.exports={OutgoingRequest:b,InitialOutgoingInviteRequest:S,IncomingRequest:C,IncomingResponse:A}},{"./Constants":2,"./Grammar":7,"./Logger":9,"./NameAddrHeader":11,"./Utils":30,"sdp-transform":39}],23:[function(e,t,n){"use strict";var r=e("./Logger"),i=e("./Utils"),o=e("./Grammar"),s=new r("Socket");n.isSocket=function(e){if(Array.isArray(e))return!1;if(void 0===e)return s.warn("undefined JsSIP.Socket instance"),!1;try{if(!i.isString(e.url))throw s.warn("missing or invalid JsSIP.Socket url property"),new Error("Missing or invalid JsSIP.Socket url property");if(!i.isString(e.via_transport))throw s.warn("missing or invalid JsSIP.Socket via_transport property"),new Error("Missing or invalid JsSIP.Socket via_transport property");if(-1===o.parse(e.sip_uri,"SIP_URI"))throw s.warn("missing or invalid JsSIP.Socket sip_uri property"),new Error("missing or invalid JsSIP.Socket sip_uri property")}catch(e){return!1}try{["connect","disconnect","send"].forEach(function(t){if(!i.isFunction(e[t]))throw s.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":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 i(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return o(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?o(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,l=!0,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,s=e},f:function(){try{l||null==n.return||n.return()}finally{if(u)throw s}}}}function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n2e3&&(y.debug("update sending re-SUBSCRIBE time"),this._scheduleSubscribe(l))}s!==T.STATE_PENDING&&o===T.STATE_PENDING?(y.debug('emit "pending"'),this.emit("pending")):s!==T.STATE_ACTIVE&&o===T.STATE_ACTIVE&&(y.debug('emit "active"'),this.emit("active"));var a=e.body,c=o===T.STATE_TERMINATED;if(a){var f=e.getHeader("content-type");y.debug('emit "notify"'),this.emit("notify",c,e,a,f)}if(c){var d=i.reason,_=void 0;i.params&&void 0!==i.params["retry-after"]&&(_=parseInt(i.params["retry-after"])),this._dialogTerminated(T.RECEIVE_FINAL_NOTIFY,d,_)}}},{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;y.debug("subscribe()"),this._state===T.STATE_INIT?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(y.debug("terminate()"),!this._terminated){this._terminated=!0;var n=this._headers.map(function(e){return e.startsWith("Expires")?"Expires: 0":e});this._state===T.STATE_INIT?this._sendInitialSubscribe(t,n):this._sendSubsequentSubscribe(t,n);this._unsubscribe_timeout_timer=setTimeout(function(){e._dialogTerminated(T.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._state=T.STATE_NOTIFY_WAIT;var r=new m.OutgoingRequest(h.SUBSCRIBE,this._ua.normalizeTarget(this._target),this._ua,this._params,t,e);new v(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 g(this,e,"UAC");if(t.error)return y.warn(t.error),void this._dialogTerminated(T.SUBSCRIBE_BAD_OK_RESPONSE);this._dialog=t,y.debug('emit "accepted"'),this.emit("accepted");var n,r=i(this._queue);try{for(r.s();!(n=r.n()).done;){var o=n.value;y.debug("dequeue subscribe"),this._sendSubsequentSubscribe(o.body,o.headers)}}catch(e){r.e(e)}finally{r.f()}}var s=e.getHeader("expires");0===s||s||(y.warn("response without Expires header"),s="900");var l=parseInt(s);l>0&&this._scheduleSubscribe(l)}else 401===e.status_code||407===e.status_code?this._dialogTerminated(T.SUBSCRIBE_FAILED_AUTHENTICATION):e.status_code>=300&&this._dialogTerminated(T.SUBSCRIBE_NON_OK_RESPONSE)}},{key:"_sendSubsequentSubscribe",value:function(e,t){var n=this;if(this._state!==T.STATE_TERMINATED){if(!this._dialog)return y.debug("enqueue subscribe"),void this._queue.push({body:e,headers:t.slice()});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(h.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._state!==T.STATE_TERMINATED&&(this._state=T.STATE_TERMINATED,clearTimeout(this._expires_timer),clearTimeout(this._unsubscribe_timeout_timer),this._dialog&&(this._dialog.terminate(),this._dialog=null),y.debug('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,y.debug("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 T.STATE_PENDING;case"active":return T.STATE_ACTIVE;case"terminated":return T.STATE_TERMINATED;case"init":return T.STATE_INIT;case"notify_wait":return T.STATE_NOTIFY_WAIT;default:throw new TypeError("wrong state value")}}}])&&s(n.prototype,r),o&&s(n,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,r,o}()},{"./Constants":2,"./Dialog":3,"./Grammar":7,"./Logger":9,"./RequestSender":21,"./SIPMessage":22,"./Utils":30,events:33}],25:[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}},{}],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 i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(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()},m.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)}}}])}(),A=function(e){function t(e,n,r,o){var s;i(this,t),(s=u(this,t)).id="z9hG4bK".concat(Math.floor(1e7*Math.random())),s.transport=n,s.request=r,s.eventHandlers=o;var l="SIP/2.0/".concat(n.via_transport);return l+=" ".concat(e.configuration.via_host,";branch=").concat(s.id),s.request.setHeader("via",l),s}return c(t,d),s(t,[{key:"C",get:function(){return S}},{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()}}])}(),w=function(e){function t(e,n,r){var o;return i(this,t),(o=u(this,t)).type=S.NON_INVITE_SERVER,o.id=r.via_branch,o.ua=e,o.transport=n,o.request=r,o.last_response="",r.server_transaction=o,o.state=S.STATUS_TRYING,e.newTransaction(o),o}return c(t,d),s(t,[{key:"C",get:function(){return S}},{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(S.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(S.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var i=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(){i.timer_J()},m.TIMER_J),this.transport.send(t)?n&&n():(this.onTransportError(),r&&r());break;case S.STATUS_COMPLETED:}}}])}(),R=function(e){function t(e,n,r){var o;return i(this,t),(o=u(this,t)).type=S.INVITE_SERVER,o.id=r.via_branch,o.ua=e,o.transport=n,o.request=r,o.last_response="",r.server_transaction=o,o.state=S.STATUS_PROCEEDING,e.newTransaction(o),o.resendProvisionalTimer=null,r.reply(100),o}return c(t,d),s(t,[{key:"C",get:function(){return S}},{key:"stateChanged",value:function(e){this.state=e,this.emit("stateChanged")}},{key:"timer_H",value:function(){b.debug("Timer H expired for transaction ".concat(this.id)),this.state===S.STATUS_COMPLETED&&b.debug("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(){b.debug("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,b.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(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 i=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(){i.resend_provisional()},m.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(){i.timer_L()},m.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(){i.timer_H()},m.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}}])}();t.exports={C:S,NonInviteClientTransaction:E,InviteClientTransaction:C,AckClientTransaction:A,NonInviteServerTransaction:w,InviteServerTransaction:R,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 S.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case S.STATUS_ACCEPTED:}return!0}break;case _.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()},m.TIMER_I),!0;break;case _.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,"./Logger":9,"./SIPMessage":22,"./Timers":25,events:33}],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 i(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:c.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),a.debug("new()"),this.status=c.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){a.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(!l.isSocket(e.socket))throw new TypeError("Invalid argument. invalid 'JsSIP.Socket' instance");if(e.weight&&!Number(e.weight))throw new TypeError("Invalid argument. 'weight' attribute is not a number");this.sockets.push({socket:e.socket,weight:e.weight||0,status:c.SOCKET_STATUS_READY})},this),this._getSocket()},(t=[{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(){a.debug("connect()"),this.isConnected()?a.debug("Transport is already connected"):this.isConnecting()?a.debug("Transport is connecting"):(this.close_requested=!1,this.status=c.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){a.debug("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=c.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(a.debug("send()"),!this.isConnected())return a.warn("unable to send message, transport is not connected"),!1;var t=e.toString();return a.debug("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===c.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===c.STATUS_CONNECTING}},{key:"_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),a.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!==c.SOCKET_STATUS_ERROR&&(0===e.length?e.push(t):t.weight>e[0].weight?e=[t]:t.weight===e[0].weight&&e.push(t))}),0===e.length)return this.sockets.forEach(function(e){e.status=c.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=c.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=c.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=c.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 a.debug("received binary message failed to be converted into string, message discarded")}a.debug("received binary message:\n\n".concat(e,"\n"))}else a.debug("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else a.debug("received message with CRLF Keep Alive response");else{a.debug("received message with double-CRLF Keep Alive request");try{this.socket.send("\r\n")}catch(e){a.warn("error sending Keep Alive response: ".concat(e))}}}}])&&i(e.prototype,t),n&&i(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n}()},{"./Constants":2,"./Logger":9,"./Socket":23}],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 i(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 i in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,i)&&(-1!==r.indexOf(i)?Object.defineProperty(this._configuration,i,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,i,{writable:!1,configurable:!1}));for(var o in R.debug("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(w.settings,o))switch(o){case"uri":case"registrar_server":R.debug("- ".concat(o,": ").concat(this._configuration[o]));break;case"password":case"ha1":case"authorization_jwt":R.debug("- ".concat(o,": NOT SHOWN"));break;default:R.debug("- ".concat(o,": ").concat(JSON.stringify(this._configuration[o])))}}}])&&i(n.prototype,r),o&&i(n,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,r,o}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Logger":9,"./Message":10,"./Notifier":12,"./Options":13,"./Parser":14,"./RTCSession":15,"./Registrator":20,"./SIPMessage":22,"./Subscriber":24,"./Transactions":26,"./Transport":27,"./URI":29,"./Utils":30,"./sanityCheck":32,events:33}],29:[function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function i(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return o(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?o(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,l=!0,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,s=e},f:function(){try{l||null==n.return||n.return()}finally{if(u)throw s}}}}function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},s=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 l in this._parameters={},this._headers={},this._scheme=t||u.SIP,this._user=n,this._host=r,this._port=i,o)Object.prototype.hasOwnProperty.call(o,l)&&this.setParam(l,o[l]);for(var a in s)Object.prototype.hasOwnProperty.call(s,a)&&this.setHeader(a,s[a])}return t=e,r=[{key:"parse",value:function(e){return-1!==(e=c.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[a.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[a.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(a.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=a.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(a.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 r in this._headers)if(Object.prototype.hasOwnProperty.call(this._headers,r)){var o,s=i(this._headers[r]);try{for(s.s();!(o=s.n()).done;){var l=o.value;e.push("".concat(r,"=").concat(l))}}catch(e){s.e(e)}finally{s.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(a.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}}])&&s(t.prototype,n),r&&s(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,n,r}()},{"./Constants":2,"./Grammar":7,"./Utils":30}],30:[function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function i(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return o(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?o(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,l=!0,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,s=e},f:function(){try{l||null==n.return||n.return()}finally{if(u)throw s}}}}function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=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,i=1073741824&e,o=1073741824&t,s=(1073741823&e)+(1073741823&t);return i&o?2147483648^s^n^r:i|o?1073741824&s?3221225472^s^n^r:1073741824^s^n^r:s^n^r}function r(e,r,i,o,s,l,u){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,i,o),s),u)),n(t(e,l),r)}function i(e,r,i,o,s,l,u){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,i,o),s),u)),n(t(e,l),r)}function o(e,r,i,o,s,l,u){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,i,o),s),u)),n(t(e,l),r)}function s(e,r,i,o,s,l,u){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,i,o),s),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,f,d,h,_,p,m,v;for(u=function(e){for(var t,n=e.length,r=n+8,i=16*((r-r%64)/64+1),o=new Array(i-1),s=0,l=0;l>>29,o}(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":29}],31:[function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function i(e,t){for(var n=0;n=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,l=!0,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,s=e},f:function(){try{l||null==n.return||n.return()}finally{if(u)throw s}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n1)return d.debug("more than one Via header field present in the response, dropping the response"),!1},function(){var e=f.str_utf8_length(o.body),t=o.getHeader("content-length");if(e0&&l.length>o){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=s[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=s[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,i=m(e,r),o=0;o=0;s--)if(n[s]===t||n[s].listener===t){l=n[s].listener,o=s;break}if(o<0)return this;0===o?n.shift():function(e,t){for(var n=t,r=n+1,i=e.length;r=0;o--)this.removeListener(e,t[o]);return this},s.prototype.listeners=function(e){return _(this,e,!0)},s.prototype.rawListeners=function(e){return _(this,e,!1)},s.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):p.call(e,t)},s.prototype.listenerCount=p,s.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]}},{}],34:[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,i=0;e[0].replace(/%[a-zA-Z%]/g,e=>{"%%"!==e&&(r++,"%c"===e&&(i=r))}),e.splice(i,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")||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;let e;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&(e=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(e[1],10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},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:i}=t.exports;i.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}).call(this)}).call(this,e("_process"))},{"./common":35,_process:37}],35:[function(e,t,n){t.exports=function(t){function n(e){let t,i,o,s=null;function l(...e){if(!l.enabled)return;const r=l,i=Number(new Date),o=i-(t||i);r.diff=o,r.prev=t,r.curr=i,t=i,e[0]=n.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let s=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,(t,i)=>{if("%%"===t)return"%";s++;const o=n.formatters[i];if("function"==typeof o){const n=e[s];t=o.call(r,n),e.splice(s,1),s--}return t}),n.formatArgs.call(r,e),(r.log||n.log).apply(r,e)}return l.namespace=e,l.useColors=n.useColors(),l.color=n.selectColor(e),l.extend=r,l.destroy=n.destroy,Object.defineProperty(l,"enabled",{enumerable:!0,configurable:!1,get:()=>null!==s?s:(i!==n.namespaces&&(i=n.namespaces,o=n.enabled(e)),o),set:e=>{s=e}}),"function"==typeof n.init&&n.init(l),l}function r(e,t){const r=n(this.namespace+(void 0===t?":":t)+e);return r.log=this.log,r}function i(e,t){let n=0,r=0,i=-1,o=0;for(;n"-"+e)].join(",");return n.enable(""),e},n.enable=function(e){n.save(e),n.namespaces=e,n.names=[],n.skips=[];const t=("string"==typeof e?e:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(const e of t)"-"===e[0]?n.skips.push(e.slice(1)):n.names.push(e)},n.enabled=function(e){for(const t of n.skips)if(i(e,t))return!1;for(const t of n.names)if(i(e,t))return!0;return!1},n.humanize=e("ms"),n.destroy=function(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")},Object.keys(t).forEach(e=>{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+(i?"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*s;case"hours":case"hour":case"hrs":case"hr":case"h":return n*o;case"minutes":case"minute":case"mins":case"min":case"m":return n*i;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>=s)return a(e,t,s,"day");if(t>=o)return a(e,t,o,"hour");if(t>=i)return a(e,t,i,"minute");if(t>=r)return a(e,t,r,"second");return e+" ms"}(e):function(e){var t=Math.abs(e);if(t>=s)return Math.round(e/s)+"d";if(t>=o)return Math.round(e/o)+"h";if(t>=i)return Math.round(e/i)+"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))}},{}],37:[function(e,t,n){var r,i,o=t.exports={};function s(){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===s||!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:s}catch(e){r=s}try{i="function"==typeof clearTimeout?clearTimeout:l}catch(e){i=l}}();var a,c=[],f=!1,d=-1;function h(){f&&a&&(f=!1,a.length?c=a.concat(c):d=-1,c.length&&_())}function _(){if(!f){var e=u(h);f=!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),i=0;i=r)return e;var i=n[t];switch(t+=1,e){case"%%":return"%";case"%s":return String(i);case"%d":return Number(i);case"%v":return""}})}.apply(null,r)},s=["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||s,i=t.innerOrder||l,u=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?u.push(o(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){u.push(o(t,n,e))})})}),e.media.forEach(function(e){u.push(o("m",r.m[0],e)),i.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?u.push(o(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){u.push(o(t,n,e))})})})}),u.join("\r\n")+"\r\n"}},{"./grammar":38}],42:[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/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/lib/Constants.d.ts b/lib/Constants.d.ts index 2d7527838..31297cc62 100644 --- a/lib/Constants.d.ts +++ b/lib/Constants.d.ts @@ -57,7 +57,7 @@ export declare 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/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.d.ts b/lib/Notifier.d.ts new file mode 100644 index 000000000..89ec127bc --- /dev/null +++ b/lib/Notifier.d.ts @@ -0,0 +1,24 @@ +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 { + start(): void; + setActiveState(): void; + notify(body?: string): void; + terminate(body?: string, reason?: string): void; + get state(): string; + get id(): string; + static get C(): typeof NotifierTerminatedCode; + get C(): typeof NotifierTerminatedCode; +} diff --git a/lib/Notifier.js b/lib/Notifier.js new file mode 100644 index 000000000..b3d51ae22 --- /dev/null +++ b/lib/Notifier.js @@ -0,0 +1,387 @@ +const EventEmitter = require('events').EventEmitter; +const Logger = require('./Logger'); +const JsSIP_C = require('./Constants'); +const Utils = require('./Utils'); +const Dialog = require('./Dialog'); + +const logger = new Logger('Notifier'); + +/** + * 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, + + // Notifer states + STATE_PENDING : 0, + STATE_ACTIVE : 1, + STATE_TERMINATED : 2 +}; + +/** + * RFC 6665 Notifier implementation. + */ +module.exports = class Notifier extends EventEmitter +{ + /** + * Expose C object. + */ + static get C() + { + return C; + } + + get C() + { + return C; + } + + /** + * @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, { extraHeaders, allowEvents, pending }) + { + logger.debug('new'); + + super(); + + if (!subscribe) + { + 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'); + } + + 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; + + // Custom session empty object for high level use. + this.data = {}; + + this._dialog = null; + + const eventName = subscribe.getHeader('event'); + + this._content_type = contentType; + this._expires = parseInt(subscribe.getHeader('expires')); + 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._ua._contact.toString()}`; + + this._headers.push(this._contact); + } + + if (allowEvents) + { + this._headers.push(`Allow-Events: ${allowEvents}`); + } + + this._target = subscribe.from.uri.user; + subscribe.to_tag = Utils.newTag(); + + // Create dialog for normal and fetch-subscribe. + const dialog = new Dialog(this, subscribe, 'UAS'); + + this._dialog = dialog; + + if (this._expires > 0) + { + // Set expires timer and time-stamp. + this._setExpiresTimer(); + } + } + + /** + * Dialog callback. + * Called also for initial subscribe. + * Supported RFC 6665 4.4.3: initial fetch subscribe (with expires: 0). + */ + receiveRequest(request) + { + if (request.method !== JsSIP_C.SUBSCRIBE) + { + request.reply(405); + + return; + } + + 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}` ]); + + const body = request.body; + const content_type = request.getHeader('content-type'); + const is_unsubscribe = this._expires === 0; + + if (!is_unsubscribe) + { + this._setExpiresTimer(); + } + + logger.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. + */ + start() + { + logger.debug('start()'); + + this.receiveRequest(this._initial_subscribe); + } + + /** + * Switch pending dialog state to active. + */ + setActiveState() + { + logger.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. + */ + 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) + { + logger.warn('final notify has sent'); + + return; + } + + // Build Subscription-State header with parameters. + let subsState = `Subscription-State: ${this._stateToString()}`; + + for (const param of subsStateParameters) + { + subsState += param; + } + + let headers = this._headers.slice(); + + headers.push(subsState); + + if (extraHeaders) + { + headers = headers.concat(extraHeaders); + } + + if (body) + { + headers.push(`Content-Type: ${this._content_type}`); + } + + 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); + } + } + }); + } + + /** + * 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) + { + logger.debug('terminate()'); + + this._state = C.STATE_TERMINATED; + + const subsStateParameters = []; + + if (reason) + { + subsStateParameters.push(`;reason=${reason}`); + } + + if (retryAfter !== null) + { + subsStateParameters.push(`;retry-after=${retryAfter}`); + } + + this._notify(subsStateParameters, body); + + this._dialogTerminated(reason === 'timeout' ? C.SUBSCRIPTION_EXPIRED : C.SEND_FINAL_NOTIFY); + } + + /** + * Get dialog state. + */ + get state() + { + return this._state; + } + + /** + * Get dialog id. + */ + get id() + { + return this._dialog ? this._dialog.id : null; + } + + /** + * Private API + */ + _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; + } + + // 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() + { + this._expires_timestamp = new Date().getTime() + (this._expires * 1000); + + clearTimeout(this._expires_timer); + this._expires_timer = setTimeout(() => + { + if (!this._dialog) + { + return; + } + + logger.debug(`emit "terminated" code=${C.SUBSCRIPTION_EXPIRED}, send final notify=true`); + this.emit('terminated', C.SUBSCRIPTION_EXPIRED, true); + }, this._expires * 1000); + } + + _stateToString() + { + switch (this._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'); + } + } +}; diff --git a/lib/Subscriber.d.ts b/lib/Subscriber.d.ts new file mode 100644 index 000000000..eb87b0948 --- /dev/null +++ b/lib/Subscriber.d.ts @@ -0,0 +1,23 @@ +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_BAD_OK_RESPONSE = 3, + SUBSCRIBE_FAILED_AUTHENTICATION = 4, + UNSUBSCRIBE_TIMEOUT = 5, + RECEIVE_FINAL_NOTIFY = 6, + RECEIVE_BAD_NOTIFY = 7 +} + +export class Subscriber extends EventEmitter { + subscribe(body?: string): void; + terminate(body?: string): void; + get state(): string; + get id(): string; + static get C(): typeof SubscriberTerminatedCode; + get C(): typeof SubscriberTerminatedCode; +} diff --git a/lib/Subscriber.js b/lib/Subscriber.js new file mode 100644 index 000000000..31cfc01ac --- /dev/null +++ b/lib/Subscriber.js @@ -0,0 +1,605 @@ +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 logger = new Logger('Subscriber'); + +/** + * Termination codes. + */ +const 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 = class Subscriber extends EventEmitter +{ + /** + * Expose C object. + */ + static get C() + { + return C; + } + + get C() + { + return C; + } + + /** + * @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. + */ + constructor(ua, target, eventName, accept, { expires, contentType, + allowEvents, params, extraHeaders }) + { + logger.debug('new'); + + super(); + + // 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 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. + this.data = {}; + + 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; + + let eventValue = this._event_name; + + if (this._event_id) + { + eventValue += `;id=${this._event_id}`; + } + + this._headers = Utils.cloneArray(extraHeaders); + this._headers = this._headers.concat([ + `Event: ${eventValue}`, + `Expires: ${this._expires}`, + `Accept: ${accept}` + ]); + + if (!this._headers.find((header) => header.startsWith('Contact'))) + { + + const contact = `Contact: ${this._ua._contact.toString()}`; + + this._headers.push(contact); + } + + if (allowEvents) + { + this._headers.push(`Allow-Events: ${allowEvents}`); + } + + // To enqueue subscribes created before receive initial subscribe OK. + this._queue = []; + } + + onRequestTimeout() + { + this._dialogTerminated(C.SUBSCRIBE_RESPONSE_TIMEOUT); + } + + onTransportError() + { + this._dialogTerminated(C.SUBSCRIBE_TRANSPORT_ERROR); + } + + /** + * Dialog callback. + */ + receiveRequest(request) + { + if (request.method !== JsSIP_C.NOTIFY) + { + logger.warn('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) + { + logger.warn('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) + { + logger.warn('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) + { + logger.warn('missed Subscription-State header'); + request.reply(400); + this._dialogTerminated(C.RECEIVE_BAD_NOTIFY); + + return; + } + + request.reply(200); + + const new_state = this._stateStringToNumber(subs_state.state); + const prev_state = this._state; + + if (prev_state !== C.STATE_TERMINATED && new_state !== C.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 time is shorter and the difference is not too small. + if (this._expires_timestamp - expires_timestamp > max_time_deviation) + { + logger.debug('update sending re-SUBSCRIBE time'); + + this._scheduleSubscribe(expires); + } + } + } + + 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) + { + logger.debug('emit "active"'); + this.emit('active'); + } + + const body = request.body; + + // Check if the notify is final. + const is_final = new_state === C.STATE_TERMINATED; + + // Notify event fired only for notify with body. + if (body) + { + const content_type = request.getHeader('content-type'); + + logger.debug('emit "notify"'); + this.emit('notify', is_final, request, body, content_type); + } + + if (is_final) + { + 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); + } + } + + /** + * User API + */ + + /** + * Send the initial (non-fetch) and subsequent subscribe. + * @param {string} body - subscribe request body. + */ + subscribe(body = null) + { + logger.debug('subscribe()'); + + if (this._state === C.STATE_INIT) + { + 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 + */ + terminate(body = null) + { + logger.debug('terminate()'); + + // Prevent duplication un-subscribe sending. + if (this._terminated) + { + + return; + } + this._terminated = true; + + // Set header Expires: 0. + const headers = this._headers.map((header) => + { + return header.startsWith('Expires') ? 'Expires: 0' : header; + }); + + if (this._state === C.STATE_INIT) + { + // fetch-subscribe - initial subscribe with Expires: 0. + 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._dialogTerminated(C.UNSUBSCRIBE_TIMEOUT); + }, final_notify_timeout); + } + + /** + * Get dialog state. + */ + get state() + { + return this._state; + } + + /** + * Get dialog id. + */ + get id() + { + return this._dialog ? this._dialog.id : null; + } + + /** + * Private API. + */ + _sendInitialSubscribe(body, headers) + { + if (body) + { + if (!this._content_type) + { + throw new TypeError('content_type is undefined'); + } + + headers = headers.slice(); + 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); + + const request_sender = new RequestSender(this._ua, request, { + onRequestTimeout : () => + { + this.onRequestTimeout(); + }, + onTransportError : () => + { + this.onTransportError(); + }, + 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 + logger.warn(dialog.error); + this._dialogTerminated(C.SUBSCRIBE_BAD_OK_RESPONSE); + + return; + } + + this._dialog = dialog; + + logger.debug('emit "accepted"'); + this.emit('accepted'); + + // Subsequent subscribes saved in the queue until dialog created. + for (const subscribe of this._queue) + { + logger.debug('dequeue subscribe'); + + this._sendSubsequentSubscribe(subscribe.body, subscribe.headers); + } + } + + // Check expires value. + let expires_value = response.getHeader('expires'); + + if (expires_value !== 0 && !expires_value) + { + logger.warn('response without Expires header'); + + // RFC 6665 3.1.1 subscribe OK response 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._state === C.STATE_TERMINATED) + { + return; + } + + if (!this._dialog) + { + logger.debug('enqueue subscribe'); + + this._queue.push({ body, headers: headers.slice() }); + + return; + } + + 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, + eventHandlers : { + onRequestTimeout : () => + { + this.onRequestTimeout(); + }, + onTransportError : () => + { + this.onTransportError(); + }, + onSuccessResponse : (response) => + { + this._receiveSubscribeResponse(response); + }, + onErrorResponse : (response) => + { + this._receiveSubscribeResponse(response); + }, + onDialogError : (response) => + { + this._receiveSubscribeResponse(response); + } + } + }); + } + + _dialogTerminated(terminationCode, reason = undefined, retryAfter = undefined) + { + // To prevent duplicate emit terminated event. + if (this._state === C.STATE_TERMINATED) + { + return; + } + + this._state = C.STATE_TERMINATED; + + // Clear timers. + clearTimeout(this._expires_timer); + clearTimeout(this._unsubscribe_timeout_timer); + + if (this._dialog) + { + this._dialog.terminate(); + this._dialog = null; + } + + logger.debug(`emit "terminated" code=${terminationCode}`); + this.emit('terminated', terminationCode, reason, retryAfter); + } + + _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 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. + 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; + + this._expires_timestamp = new Date().getTime() + (expires * 1000); + + logger.debug(`next SUBSCRIBE will be sent in ${Math.floor(timeout / 1000)} sec`); + + clearTimeout(this._expires_timer); + this._expires_timer = setTimeout(() => + { + this._expires_timer = null; + this._sendSubsequentSubscribe(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'); + } + } +}; diff --git a/lib/UA.d.ts b/lib/UA.d.ts index 6ee4a7881..0fff768d4 100644 --- a/lib/UA.d.ts +++ b/lib/UA.d.ts @@ -5,6 +5,8 @@ import {AnswerOptions, Originator, RTCSession, RTCSessionEventMap, TerminateOpti 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' @@ -125,6 +127,7 @@ export type IncomingOptionsListener = (event: IncomingOptionsEvent) => void; export type OutgoingOptionsListener = (event: OutgoingOptionsEvent) => void; export type OptionsListener = IncomingOptionsListener | OutgoingOptionsListener; export type SipEventListener = (event: { event: T; request: IncomingRequest; }) => void +export type SipSubscribeListener = (event: { event: T; request: IncomingRequest; }) => void export interface UAEventMap { connecting: ConnectingListener; @@ -137,6 +140,7 @@ export interface UAEventMap { newRTCSession: RTCSessionListener; newMessage: MessageListener; sipEvent: SipEventListener; + newSubscribe: SipSubscribeListener; newOptions: OptionsListener; } @@ -153,6 +157,38 @@ export interface UAContact { toString(options?: UAContactOptions): 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 { + expires?: number; + contentType?: string; + allowEvents?: string; + params?: SubscriberParams; + extraHeaders?: string[]; +} + +export interface NotifierOptions { + allowEvents?: string; + extraHeaders?: string[]; + pending?: boolean; +} + declare enum UAStatus { // UA status codes. STATUS_INIT = 0, @@ -189,6 +225,10 @@ export class UA extends EventEmitter { sendMessage(target: string | URI, body: string, options?: SendMessageOptions): Message; + subscribe(target: string, eventName: string, accept: string, options?: SubscriberOptions): Subscriber; + + notify( subscribe: IncomingRequest, contentType: string, options?: NotifierOptions): Notifier; + terminateSessions(options?: TerminateOptions): void; isRegistered(): boolean; diff --git a/lib/UA.js b/lib/UA.js index 919b66af3..6597b627f 100644 --- a/lib/UA.js +++ b/lib/UA.js @@ -3,6 +3,8 @@ 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'); @@ -257,6 +259,26 @@ module.exports = class UA extends EventEmitter return message; } + /** + * Create subscriber instance + */ + subscribe(target, eventName, accept, options) + { + logger.debug('subscribe()'); + + return new Subscriber(this, target, eventName, accept, options); + } + + /** + * Create notifier instance + */ + notify(subscribe, contentType, options) + { + logger.debug('notify()'); + + return new Notifier(this, subscribe, contentType, options); + } + /** * Send a SIP OPTIONS. * @@ -640,6 +662,15 @@ module.exports = class UA extends EventEmitter 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. @@ -726,6 +757,12 @@ module.exports = class UA extends EventEmitter }); request.reply(200); break; + case JsSIP_C.SUBSCRIBE: + this.emit('newSubscribe', { + event : request.event, + request + }); + break; default: request.reply(405); break; diff --git a/test/include/loopSocket.js b/test/include/loopSocket.js new file mode 100644 index 000000000..9a92d9a21 --- /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)}`; + } +}; diff --git a/test/test-UA-subscriber-notifier.js b/test/test-UA-subscriber-notifier.js new file mode 100644 index 000000000..e9a82a378 --- /dev/null +++ b/test/test-UA-subscriber-notifier.js @@ -0,0 +1,179 @@ +/* eslint no-console: 0*/ + +require('./include/common'); +const JsSIP = require('../'); +const LoopSocket = require('./include/LoopSocket'); + +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 WEATHER_REQUEST = 'Please report the weather condition'; + const WEATHER_REPORT = '+20..+24°C, no precipitation, light wind'; + + function createSubscriber(ua) + { + const options = { + expires : 3600, + contentType : CONTENT_TYPE, + params : null + }; + + const subscriber = ua.subscribe(TARGET, EVENT_NAME, SUBSCRIBE_ACCEPT, options); + + subscriber.on('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(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) => + { + test.ok(++eventSequence === 12, 'subscriber terminated'); + test.ok(terminationCode === subscriber.C.RECEIVE_FINAL_NOTIFY); + test.ok(reason === undefined); + test.ok(retryAfter === undefined); + + ua.stop(); + + test.done(); + }); + + subscriber.on('accepted', () => + { + test.ok(++eventSequence === 5, 'initial subscribe accepted'); + }); + + test.ok(++eventSequence === 2, 'send subscribe'); + + 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, 'timeout'); + } + }); + + notifier.start(); + } + + // Start JsSIP UA with loop socket. + const config = + { + sockets : new LoopSocket(), // message sending itself, with modified Call-ID + uri : REQUEST_URI, + contact_uri : CONTACT_URI, + register : false + }; + + const ua = new JsSIP.UA(config); + + // Uncomment to see SIP communication + // JsSIP.debug.enable('JsSIP:*'); + + ua.on('newSubscribe', (e) => + { + 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); + }); + + ua.on('connected', () => + { + test.ok(++eventSequence === 1, 'socket connected'); + + createSubscriber(ua); + }); + + ua.start(); + } +};