diff --git a/dist/jssip.js b/dist/jssip.js index 0631707..a86ff7d 100644 --- a/dist/jssip.js +++ b/dist/jssip.js @@ -294,7 +294,7 @@ exports.load = function (dst, src) { } } }; -},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":20,"./URI":25,"./Utils":26}],2:[function(require,module,exports){ +},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":26,"./Utils":27}],2:[function(require,module,exports){ "use strict"; var pkg = require('../package.json'); @@ -470,7 +470,7 @@ module.exports = { CONNECTION_RECOVERY_MAX_INTERVAL: 30, CONNECTION_RECOVERY_MIN_INTERVAL: 2 }; -},{"../package.json":38}],3:[function(require,module,exports){ +},{"../package.json":39}],3:[function(require,module,exports){ "use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -479,6 +479,8 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } +var Logger = require('./Logger'); + var SIPMessage = require('./SIPMessage'); var JsSIP_C = require('./Constants'); @@ -489,8 +491,7 @@ var Dialog_RequestSender = require('./Dialog/RequestSender'); var Utils = require('./Utils'); -var debug = require('debug')('JsSIP:Dialog'); - +var logger = new Logger('Dialog'); var C = { // Dialog states. STATUS_EARLY: 1, @@ -565,14 +566,14 @@ module.exports = /*#__PURE__*/function () { this._ua.newDialog(this); - debug("new ".concat(type, " dialog created with status ").concat(this._state === C.STATUS_EARLY ? 'EARLY' : 'CONFIRMED')); + logger.debug("new ".concat(type, " dialog created with status ").concat(this._state === C.STATUS_EARLY ? 'EARLY' : 'CONFIRMED')); } _createClass(Dialog, [{ key: "update", value: function update(message, type) { this._state = C.STATUS_CONFIRMED; - debug("dialog ".concat(this._id.toString(), " changed to CONFIRMED state")); + logger.debug("dialog ".concat(this._id.toString(), " changed to CONFIRMED state")); if (type === 'UAC') { // RFC 3261 13.2.2.4. @@ -582,7 +583,7 @@ module.exports = /*#__PURE__*/function () { }, { key: "terminate", value: function terminate() { - debug("dialog ".concat(this._id.toString(), " deleted")); + logger.debug("dialog ".concat(this._id.toString(), " deleted")); this._ua.destroyDialog(this); } @@ -748,7 +749,7 @@ module.exports = /*#__PURE__*/function () { return Dialog; }(); -},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":19,"./Transactions":22,"./Utils":26,"debug":30}],4:[function(require,module,exports){ +},{"./Constants":2,"./Dialog/RequestSender":4,"./Logger":9,"./SIPMessage":20,"./Transactions":23,"./Utils":27}],4:[function(require,module,exports){ "use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -871,7 +872,7 @@ module.exports = /*#__PURE__*/function () { return DialogRequestSender; }(); -},{"../Constants":2,"../RTCSession":12,"../RequestSender":18,"../Transactions":22}],5:[function(require,module,exports){ +},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":23}],5:[function(require,module,exports){ "use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -880,13 +881,11 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } -var Utils = require('./Utils'); +var Logger = require('./Logger'); -var debug = require('debug')('JsSIP:DigestAuthentication'); - -var debugerror = require('debug')('JsSIP:ERROR:DigestAuthentication'); +var Utils = require('./Utils'); -debugerror.log = console.warn.bind(console); +var logger = new Logger('DigestAuthentication'); module.exports = /*#__PURE__*/function () { function DigestAuthentication(credentials) { @@ -919,7 +918,7 @@ module.exports = /*#__PURE__*/function () { return this._ha1; default: - debugerror('get() | cannot get "%s" parameter', parameter); + logger.warn('get() | cannot get "%s" parameter', parameter); return undefined; } } @@ -946,7 +945,7 @@ module.exports = /*#__PURE__*/function () { if (this._algorithm) { if (this._algorithm !== 'MD5') { - debugerror('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'); + logger.warn('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'); return false; } } else { @@ -954,12 +953,12 @@ module.exports = /*#__PURE__*/function () { } if (!this._nonce) { - debugerror('authenticate() | challenge without Digest nonce, authentication aborted'); + logger.warn('authenticate() | challenge without Digest nonce, authentication aborted'); return false; } if (!this._realm) { - debugerror('authenticate() | challenge without Digest realm, authentication aborted'); + logger.warn('authenticate() | challenge without Digest realm, authentication aborted'); return false; } // If no plain SIP password is provided. @@ -967,13 +966,13 @@ module.exports = /*#__PURE__*/function () { if (!this._credentials.password) { // If ha1 is not provided we cannot authenticate. if (!this._credentials.ha1) { - debugerror('authenticate() | no plain SIP password nor ha1 provided, authentication aborted'); + logger.warn('authenticate() | no plain SIP password nor ha1 provided, authentication aborted'); return false; } // If the realm does not match the stored realm we cannot authenticate. if (this._credentials.realm !== this._realm) { - debugerror('authenticate() | no plain SIP password, and stored `realm` does not match the given `realm`, cannot authenticate [stored:"%s", given:"%s"]', this._credentials.realm, this._realm); + logger.warn('authenticate() | no plain SIP password, and stored `realm` does not match the given `realm`, cannot authenticate [stored:"%s", given:"%s"]', this._credentials.realm, this._realm); return false; } } // 'qop' can contain a list of values (Array). Let's choose just one. @@ -986,7 +985,7 @@ module.exports = /*#__PURE__*/function () { this._qop = 'auth'; } else { // Otherwise 'qop' is present but does not contain 'auth' or 'auth-int', so abort here. - debugerror('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted'); + logger.warn('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted'); return false; } } else { @@ -1023,26 +1022,26 @@ module.exports = /*#__PURE__*/function () { // HA2 = MD5(A2) = MD5(method:digestURI). a2 = "".concat(this._method, ":").concat(this._uri); ha2 = Utils.calculateMD5(a2); - debug('authenticate() | using qop=auth [a2:"%s"]', a2); // Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2). + logger.debug('authenticate() | using qop=auth [a2:"%s"]', a2); // Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2). this._response = Utils.calculateMD5("".concat(this._ha1, ":").concat(this._nonce, ":").concat(this._ncHex, ":").concat(this._cnonce, ":auth:").concat(ha2)); } else if (this._qop === 'auth-int') { // HA2 = MD5(A2) = MD5(method:digestURI:MD5(entityBody)). a2 = "".concat(this._method, ":").concat(this._uri, ":").concat(Utils.calculateMD5(body ? body : '')); ha2 = Utils.calculateMD5(a2); - debug('authenticate() | using qop=auth-int [a2:"%s"]', a2); // Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2). + logger.debug('authenticate() | using qop=auth-int [a2:"%s"]', a2); // Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2). this._response = Utils.calculateMD5("".concat(this._ha1, ":").concat(this._nonce, ":").concat(this._ncHex, ":").concat(this._cnonce, ":auth-int:").concat(ha2)); } else if (this._qop === null) { // HA2 = MD5(A2) = MD5(method:digestURI). a2 = "".concat(this._method, ":").concat(this._uri); ha2 = Utils.calculateMD5(a2); - debug('authenticate() | using qop=null [a2:"%s"]', a2); // Response = MD5(HA1:nonce:HA2). + logger.debug('authenticate() | using qop=null [a2:"%s"]', a2); // Response = MD5(HA1:nonce:HA2). this._response = Utils.calculateMD5("".concat(this._ha1, ":").concat(this._nonce, ":").concat(ha2)); } - debug('authenticate() | response generated'); + logger.debug('authenticate() | response generated'); return true; } /** @@ -1081,7 +1080,7 @@ module.exports = /*#__PURE__*/function () { return DigestAuthentication; }(); -},{"./Utils":26,"debug":30}],6:[function(require,module,exports){ +},{"./Logger":9,"./Utils":27}],6:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } @@ -16098,7 +16097,7 @@ module.exports = function () { result.SyntaxError.prototype = Error.prototype; return result; }(); -},{"./NameAddrHeader":10,"./URI":25}],8:[function(require,module,exports){ +},{"./NameAddrHeader":11,"./URI":26}],8:[function(require,module,exports){ "use strict"; var pkg = require('../package.json'); @@ -16147,7 +16146,61 @@ module.exports = { } }; -},{"../package.json":38,"./Constants":2,"./Exceptions":6,"./Grammar":7,"./NameAddrHeader":10,"./UA":24,"./URI":25,"./Utils":26,"./WebSocketInterface":27,"debug":30}],9:[function(require,module,exports){ +},{"../package.json":39,"./Constants":2,"./Exceptions":6,"./Grammar":7,"./NameAddrHeader":11,"./UA":25,"./URI":26,"./Utils":27,"./WebSocketInterface":28,"debug":31}],9:[function(require,module,exports){ +"use strict"; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +var debug = require('debug'); + +var APP_NAME = 'JsSIP'; + +module.exports = /*#__PURE__*/function () { + function Logger(prefix) { + _classCallCheck(this, Logger); + + if (prefix) { + this._debug = debug["default"]("".concat(APP_NAME, ":").concat(prefix)); + this._warn = debug["default"]("".concat(APP_NAME, ":WARN:").concat(prefix)); + this._error = debug["default"]("".concat(APP_NAME, ":ERROR:").concat(prefix)); + } else { + this._debug = debug["default"](APP_NAME); + this._warn = debug["default"]("".concat(APP_NAME, ":WARN")); + this._error = debug["default"]("".concat(APP_NAME, ":ERROR")); + } + /* eslint-disable no-console */ + + + this._debug.log = console.info.bind(console); + this._warn.log = console.warn.bind(console); + this._error.log = console.error.bind(console); + /* eslint-enable no-console */ + } + + _createClass(Logger, [{ + key: "debug", + get: function get() { + return this._debug; + } + }, { + key: "warn", + get: function get() { + return this._warn; + } + }, { + key: "error", + get: function get() { + return this._error; + } + }]); + + return Logger; +}(); +},{"debug":31}],10:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } @@ -16174,6 +16227,8 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g var EventEmitter = require('events').EventEmitter; +var Logger = require('./Logger'); + var JsSIP_C = require('./Constants'); var SIPMessage = require('./SIPMessage'); @@ -16184,7 +16239,7 @@ var RequestSender = require('./RequestSender'); var Exceptions = require('./Exceptions'); -var debug = require('debug')('JsSIP:Message'); +var logger = new Logger('Message'); module.exports = /*#__PURE__*/function (_EventEmitter) { _inherits(Message, _EventEmitter); @@ -16410,11 +16465,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_failed", value: function _failed(originator, response, cause) { - debug('MESSAGE failed'); + logger.debug('MESSAGE failed'); this._close(); - debug('emit "failed"'); + logger.debug('emit "failed"'); this.emit('failed', { originator: originator, response: response || null, @@ -16424,11 +16479,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_succeeded", value: function _succeeded(originator, response) { - debug('MESSAGE succeeded'); + logger.debug('MESSAGE succeeded'); this._close(); - debug('emit "succeeded"'); + logger.debug('emit "succeeded"'); this.emit('succeeded', { originator: originator, response: response @@ -16453,7 +16508,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return Message; }(EventEmitter); -},{"./Constants":2,"./Exceptions":6,"./RequestSender":18,"./SIPMessage":19,"./Utils":26,"debug":30,"events":29}],10:[function(require,module,exports){ +},{"./Constants":2,"./Exceptions":6,"./Logger":9,"./RequestSender":19,"./SIPMessage":20,"./Utils":27,"events":30}],11:[function(require,module,exports){ "use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -16587,7 +16642,7 @@ module.exports = /*#__PURE__*/function () { return NameAddrHeader; }(); -},{"./Grammar":7,"./URI":25}],11:[function(require,module,exports){ +},{"./Grammar":7,"./URI":26}],12:[function(require,module,exports){ "use strict"; function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } @@ -16596,13 +16651,13 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o = function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } +var Logger = require('./Logger'); + var Grammar = require('./Grammar'); var SIPMessage = require('./SIPMessage'); -var debugerror = require('debug')('JsSIP:ERROR:Parser'); - -debugerror.log = console.warn.bind(console); +var logger = new Logger('Parser'); /** * Parse SIP Message */ @@ -16613,7 +16668,7 @@ exports.parseMessage = function (data, ua) { var headerEnd = data.indexOf('\r\n'); if (headerEnd === -1) { - debugerror('parseMessage() | no CRLF found, not a SIP message'); + logger.warn('parseMessage() | no CRLF found, not a SIP message'); return; } // Parse first line. Check if it is a Request or a Reply. @@ -16622,7 +16677,7 @@ exports.parseMessage = function (data, ua) { var parsed = Grammar.parse(firstLine, 'Request_Response'); if (parsed === -1) { - debugerror("parseMessage() | error parsing first line of SIP message: \"".concat(firstLine, "\"")); + logger.warn("parseMessage() | error parsing first line of SIP message: \"".concat(firstLine, "\"")); return; } else if (!parsed.status_code) { message = new SIPMessage.IncomingRequest(ua); @@ -16648,14 +16703,14 @@ exports.parseMessage = function (data, ua) { break; } // Data.indexOf returned -1 due to a malformed message. else if (headerEnd === -1) { - debugerror('parseMessage() | malformed message'); + logger.warn('parseMessage() | malformed message'); return; } parsed = parseHeader(message, data, headerStart, headerEnd); if (parsed !== true) { - debugerror('parseMessage() |', parsed.error); + logger.warn('parseMessage() |', parsed.error); return; } @@ -16919,7 +16974,7 @@ function parseHeader(message, data, headerStart, headerEnd) { return true; } } -},{"./Grammar":7,"./SIPMessage":19,"debug":30}],12:[function(require,module,exports){ +},{"./Grammar":7,"./Logger":9,"./SIPMessage":20}],13:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } @@ -16955,6 +17010,8 @@ var EventEmitter = require('events').EventEmitter; var sdp_transform = require('sdp-transform'); +var Logger = require('./Logger'); + var JsSIP_C = require('./Constants'); var Exceptions = require('./Exceptions'); @@ -16981,11 +17038,7 @@ var RTCSession_ReferSubscriber = require('./RTCSession/ReferSubscriber'); var URI = require('./URI'); -var debug = require('debug')('JsSIP:RTCSession'); - -var debugerror = require('debug')('JsSIP:ERROR:RTCSession'); - -debugerror.log = console.warn.bind(console); +var logger = new Logger('RTCSession'); var C = { // RTCSession states. STATUS_NULL: 0, @@ -17026,7 +17079,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _classCallCheck(this, RTCSession); - debug('new'); + logger.debug('new'); _this = _super.call(this); _this._id = null; _this._ua = ua; @@ -17160,7 +17213,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function connect(target) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var initCallback = arguments.length > 2 ? arguments[2] : undefined; - debug('connect()'); + logger.debug('connect()'); var originalTarget = target; var eventHandlers = Utils.cloneObject(options.eventHandlers); var extraHeaders = Utils.cloneArray(options.extraHeaders); @@ -17273,7 +17326,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function init_incoming(request, initCallback) { var _this2 = this; - debug('init_incoming()'); + logger.debug('init_incoming()'); var expires; var contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined; // Check body and content type. @@ -17364,7 +17417,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var _this3 = this; var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - debug('answer()'); + logger.debug('answer()'); var request = this._request; var extraHeaders = Utils.cloneArray(options.extraHeaders); var mediaConstraints = Utils.cloneObject(options.mediaConstraints); @@ -17529,7 +17582,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this3._failed('local', null, JsSIP_C.causes.USER_DENIED_MEDIA_ACCESS); - debugerror('emit "getusermediafailed" [error:%o]', error); + logger.warn('emit "getusermediafailed" [error:%o]', error); _this3.emit('getusermediafailed', error); @@ -17560,7 +17613,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: 'offer', sdp: request.body }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); _this3.emit('sdp', e); @@ -17575,7 +17628,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this3._failed('system', null, JsSIP_C.causes.WEBRTC_ERROR); - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); _this3.emit('peerconnection:setremotedescriptionfailed', error); @@ -17626,7 +17679,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return; } - debugerror(error); + logger.warn(error); }); } /** @@ -17639,7 +17692,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var _this4 = this; var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - debug('terminate()'); + logger.debug('terminate()'); var cause = options.cause || JsSIP_C.causes.BYE; var extraHeaders = Utils.cloneArray(options.extraHeaders); var body = options.body; @@ -17656,7 +17709,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { case C.STATUS_NULL: case C.STATUS_INVITE_SENT: case C.STATUS_1XX_RECEIVED: - debug('canceling session'); + logger.debug('canceling session'); if (status_code && (status_code < 200 || status_code >= 700)) { throw new TypeError("Invalid status_code: ".concat(status_code)); @@ -17682,7 +17735,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { case C.STATUS_WAITING_FOR_ANSWER: case C.STATUS_ANSWERED: - debug('rejecting session'); + logger.debug('rejecting session'); status_code = status_code || 480; if (status_code < 300 || status_code >= 700) { @@ -17697,7 +17750,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { case C.STATUS_WAITING_FOR_ACK: case C.STATUS_CONFIRMED: - debug('terminating session'); + logger.debug('terminating session'); reason_phrase = options.reason_phrase || JsSIP_C.REASON_PHRASE[status_code] || ''; if (status_code && (status_code < 200 || status_code >= 700)) { @@ -17763,7 +17816,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { key: "sendDTMF", value: function sendDTMF(tones) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - debug('sendDTMF() | tones: %s', tones); + logger.debug('sendDTMF() | tones: %s', tones); var position = 0; var duration = options.duration || null; var interToneGap = options.interToneGap || null; @@ -17799,10 +17852,10 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } else if (!duration) { duration = RTCSession_DTMF.C.DEFAULT_DURATION; } else if (duration < RTCSession_DTMF.C.MIN_DURATION) { - debug("\"duration\" value is lower than the minimum allowed, setting it to ".concat(RTCSession_DTMF.C.MIN_DURATION, " milliseconds")); + logger.debug("\"duration\" value is lower than the minimum allowed, setting it to ".concat(RTCSession_DTMF.C.MIN_DURATION, " milliseconds")); duration = RTCSession_DTMF.C.MIN_DURATION; } else if (duration > RTCSession_DTMF.C.MAX_DURATION) { - debug("\"duration\" value is greater than the maximum allowed, setting it to ".concat(RTCSession_DTMF.C.MAX_DURATION, " milliseconds")); + logger.debug("\"duration\" value is greater than the maximum allowed, setting it to ".concat(RTCSession_DTMF.C.MAX_DURATION, " milliseconds")); duration = RTCSession_DTMF.C.MAX_DURATION; } else { duration = Math.abs(duration); @@ -17815,7 +17868,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } else if (!interToneGap) { interToneGap = RTCSession_DTMF.C.DEFAULT_INTER_TONE_GAP; } else if (interToneGap < RTCSession_DTMF.C.MIN_INTER_TONE_GAP) { - debug("\"interToneGap\" value is lower than the minimum allowed, setting it to ".concat(RTCSession_DTMF.C.MIN_INTER_TONE_GAP, " milliseconds")); + logger.debug("\"interToneGap\" value is lower than the minimum allowed, setting it to ".concat(RTCSession_DTMF.C.MIN_INTER_TONE_GAP, " milliseconds")); interToneGap = RTCSession_DTMF.C.MIN_INTER_TONE_GAP; } else { interToneGap = Math.abs(interToneGap); @@ -17882,7 +17935,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { key: "sendInfo", value: function sendInfo(contentType, body) { var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; - debug('sendInfo()'); // Check Session Status. + logger.debug('sendInfo()'); // Check Session Status. if (this._status !== C.STATUS_CONFIRMED && this._status !== C.STATUS_WAITING_FOR_ACK) { throw new Exceptions.InvalidStateError(this._status); @@ -17902,7 +17955,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { audio: true, video: false }; - debug('mute()'); + logger.debug('mute()'); var audioMuted = false, videoMuted = false; @@ -17938,7 +17991,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { audio: true, video: true }; - debug('unmute()'); + logger.debug('unmute()'); var audioUnMuted = false, videoUnMuted = false; @@ -17978,7 +18031,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var done = arguments.length > 1 ? arguments[1] : undefined; - debug('hold()'); + logger.debug('hold()'); if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { return false; @@ -18033,7 +18086,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var done = arguments.length > 1 ? arguments[1] : undefined; - debug('unhold()'); + logger.debug('unhold()'); if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { return false; @@ -18088,7 +18141,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var done = arguments.length > 1 ? arguments[1] : undefined; - debug('renegotiate()'); + logger.debug('renegotiate()'); var rtcOfferConstraints = options.rtcOfferConstraints || null; if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { @@ -18142,7 +18195,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function refer(target, options) { var _this9 = this; - debug('refer()'); + logger.debug('refer()'); var originalTarget = target; if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { @@ -18180,7 +18233,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "sendRequest", value: function sendRequest(method, options) { - debug('sendRequest()'); + logger.debug('sendRequest()'); return this._dialog.sendRequest(method, options); } /** @@ -18192,7 +18245,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function receiveRequest(request) { var _this10 = this; - debug('receiveRequest()'); + logger.debug('receiveRequest()'); if (request.method === JsSIP_C.CANCEL) { /* RFC3261 15 States that a UAS may have accepted an invitation while a CANCEL @@ -18240,7 +18293,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: 'answer', sdp: request.body }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); this.emit('sdp', e); var answer = new RTCSessionDescription({ type: 'answer', @@ -18258,7 +18311,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { status_code: 488 }); - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); _this10.emit('peerconnection:setremotedescriptionfailed', error); }); @@ -18354,7 +18407,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "onTransportError", value: function onTransportError() { - debugerror('onTransportError()'); + logger.warn('onTransportError()'); if (this._status !== C.STATUS_TERMINATED) { this.terminate({ @@ -18367,7 +18420,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "onRequestTimeout", value: function onRequestTimeout() { - debugerror('onRequestTimeout()'); + logger.warn('onRequestTimeout()'); if (this._status !== C.STATUS_TERMINATED) { this.terminate({ @@ -18380,7 +18433,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "onDialogError", value: function onDialogError() { - debugerror('onDialogError()'); + logger.warn('onDialogError()'); if (this._status !== C.STATUS_TERMINATED) { this.terminate({ @@ -18394,14 +18447,14 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "newDTMF", value: function newDTMF(data) { - debug('newDTMF()'); + logger.debug('newDTMF()'); this.emit('newDTMF', data); } // Called from Info handler. }, { key: "newInfo", value: function newInfo(data) { - debug('newInfo()'); + logger.debug('newInfo()'); this.emit('newInfo', data); } /** @@ -18412,19 +18465,19 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { key: "_isReadyToReOffer", value: function _isReadyToReOffer() { if (!this._rtcReady) { - debug('_isReadyToReOffer() | internal WebRTC status not ready'); + logger.debug('_isReadyToReOffer() | internal WebRTC status not ready'); return false; } // No established yet. if (!this._dialog) { - debug('_isReadyToReOffer() | session not established yet'); + logger.debug('_isReadyToReOffer() | session not established yet'); return false; } // Another INVITE transaction is in progress. if (this._dialog.uac_pending_reply === true || this._dialog.uas_pending_reply === true) { - debug('_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress'); + logger.debug('_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress'); return false; } @@ -18433,10 +18486,10 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_close", value: function _close() { - debug('close()'); // Close local MediaStream if it was not given by the user. + logger.debug('close()'); // Close local MediaStream if it was not given by the user. if (this._localMediaStream && this._localMediaStreamLocallyGenerated) { - debug('close() | closing local MediaStream'); + logger.debug('close() | closing local MediaStream'); Utils.closeMediaStream(this._localMediaStream); } @@ -18450,7 +18503,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { try { this._connection.close(); } catch (error) { - debugerror('close() | error closing the RTCPeerConnection: %o', error); + logger.warn('close() | error closing the RTCPeerConnection: %o', error); } } // Terminate signaling. // Clear SIP timers. @@ -18537,7 +18590,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._timers.ackTimer = setTimeout(function () { if (_this11._status === C.STATUS_WAITING_FOR_ACK) { - debug('no ACK received, terminating the session'); + logger.debug('no ACK received, terminating the session'); clearTimeout(_this11._timers.invite2xxTimer); _this11.sendRequest(JsSIP_C.BYE); @@ -18565,7 +18618,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } }); - debug('emit "peerconnection"'); + logger.debug('emit "peerconnection"'); this.emit('peerconnection', { peerconnection: this._connection }); @@ -18575,7 +18628,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function _createLocalDescription(type, constraints) { var _this13 = this; - debug('createLocalDescription()'); + logger.debug('createLocalDescription()'); if (type !== 'offer' && type !== 'answer') throw new Error("createLocalDescription() | invalid type \"".concat(type, "\"")); var connection = this._connection; this._rtcReady = false; @@ -18583,7 +18636,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { .then(function () { if (type === 'offer') { return connection.createOffer(constraints)["catch"](function (error) { - debugerror('emit "peerconnection:createofferfailed" [error:%o]', error); + logger.warn('emit "peerconnection:createofferfailed" [error:%o]', error); _this13.emit('peerconnection:createofferfailed', error); @@ -18591,7 +18644,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }); } else { return connection.createAnswer(constraints)["catch"](function (error) { - debugerror('emit "peerconnection:createanswerfailed" [error:%o]', error); + logger.warn('emit "peerconnection:createanswerfailed" [error:%o]', error); _this13.emit('peerconnection:createanswerfailed', error); @@ -18602,7 +18655,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { .then(function (desc) { return connection.setLocalDescription(desc)["catch"](function (error) { _this13._rtcReady = true; - debugerror('emit "peerconnection:setlocaldescriptionfailed" [error:%o]', error); + logger.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]', error); _this13.emit('peerconnection:setlocaldescriptionfailed', error); @@ -18617,7 +18670,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: type, sdp: connection.localDescription.sdp }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); _this13.emit('sdp', e); @@ -18640,7 +18693,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: type, sdp: connection.localDescription.sdp }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); _this13.emit('sdp', e); @@ -18686,7 +18739,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { early_dialog = new Dialog(this, message, type, Dialog.C.STATUS_EARLY); // Dialog has been successfully created. if (early_dialog.error) { - debug(early_dialog.error); + logger.debug(early_dialog.error); this._failed('remote', message, JsSIP_C.causes.INTERNAL_ERROR); @@ -18712,7 +18765,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var dialog = new Dialog(this, message, type); if (dialog.error) { - debug(dialog.error); + logger.debug(dialog.error); this._failed('remote', message, JsSIP_C.causes.INTERNAL_ERROR); @@ -18732,7 +18785,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function _receiveReinvite(request) { var _this14 = this; - debug('receiveReinvite()'); + logger.debug('receiveReinvite()'); var contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined; var data = { request: request, @@ -18789,7 +18842,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { if (contentType !== 'application/sdp') { - debug('invalid Content-Type'); + logger.debug('invalid Content-Type'); request.reply(415); return; } @@ -18802,7 +18855,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { sendAnswer.call(_this14, desc); })["catch"](function (error) { - debugerror(error); + logger.warn(error); }); function sendAnswer(desc) { @@ -18838,7 +18891,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function _receiveUpdate(request) { var _this16 = this; - debug('receiveUpdate()'); + logger.debug('receiveUpdate()'); var contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined; var data = { request: request, @@ -18878,7 +18931,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } if (contentType !== 'application/sdp') { - debug('invalid Content-Type'); + logger.debug('invalid Content-Type'); request.reply(415); return; } @@ -18891,7 +18944,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { sendAnswer.call(_this16, desc); })["catch"](function (error) { - debugerror(error); + logger.warn(error); }); function sendAnswer(desc) { @@ -18911,7 +18964,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function _processInDialogSdpOffer(request) { var _this17 = this; - debug('_processInDialogSdpOffer()'); + logger.debug('_processInDialogSdpOffer()'); var sdp = request.parseSDP(); var hold = false; @@ -18947,7 +19000,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: 'offer', sdp: request.body }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); this.emit('sdp', e); var offer = new RTCSessionDescription({ type: 'offer', @@ -18961,7 +19014,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return _this17._connection.setRemoteDescription(offer)["catch"](function (error) { request.reply(488); - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); _this17.emit('peerconnection:setremotedescriptionfailed', error); @@ -18989,11 +19042,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return _this17._createLocalDescription('answer', _this17._rtcAnswerConstraints)["catch"](function (error) { request.reply(500); - debugerror('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]', error); + logger.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]', error); throw error; }); })["catch"](function (error) { - debugerror('_processInDialogSdpOffer() failed [error: %o]', error); + logger.warn('_processInDialogSdpOffer() failed [error: %o]', error); }); return this._connectionPromiseQueue; } @@ -19006,16 +19059,16 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function _receiveRefer(request) { var _this18 = this; - debug('receiveRefer()'); + logger.debug('receiveRefer()'); if (!request.refer_to) { - debug('no Refer-To header field present in REFER'); + logger.debug('no Refer-To header field present in REFER'); request.reply(400); return; } if (request.refer_to.uri.scheme !== JsSIP_C.SIP) { - debug('Refer-To header field points to a non-SIP URI scheme'); + logger.debug('Refer-To header field points to a non-SIP URI scheme'); request.reply(416); return; } // Reply before the transaction timer expires. @@ -19023,7 +19076,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { request.reply(202); var notifier = new RTCSession_ReferNotifier(this, request.cseq); - debug('emit "refer"'); // Emit 'refer'. + logger.debug('emit "refer"'); // Emit 'refer'. this.emit('refer', { request: request, @@ -19083,7 +19136,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_receiveNotify", value: function _receiveNotify(request) { - debug('receiveNotify()'); + logger.debug('receiveNotify()'); if (!request.event) { request.reply(400); @@ -19130,7 +19183,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function _receiveReplaces(request) { var _this20 = this; - debug('receiveReplaces()'); + logger.debug('receiveReplaces()'); function _accept2(initCallback) { var _this19 = this; @@ -19148,7 +19201,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } function _reject2() { - debug('Replaced INVITE rejected by the user'); + logger.debug('Replaced INVITE rejected by the user'); request.reply(486); } // Emit 'replace'. @@ -19204,7 +19257,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this21._failed('local', null, JsSIP_C.causes.USER_DENIED_MEDIA_ACCESS); - debugerror('emit "getusermediafailed" [error:%o]', error); + logger.warn('emit "getusermediafailed" [error:%o]', error); _this21.emit('getusermediafailed', error); @@ -19239,7 +19292,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this21._request.body = desc; _this21._status = C.STATUS_INVITE_SENT; - debug('emit "sending" [request:%o]', _this21._request); // Emit 'sending' so the app can mangle the body before the request is sent. + logger.debug('emit "sending" [request:%o]', _this21._request); // Emit 'sending' so the app can mangle the body before the request is sent. _this21.emit('sending', { request: _this21._request @@ -19251,7 +19304,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return; } - debugerror(error); + logger.warn(error); }); } /** @@ -19266,7 +19319,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }); if (!(sender && sender.dtmf)) { - debugerror('sendDTMF() | no local audio track to send DTMF with'); + logger.warn('sendDTMF() | no local audio track to send DTMF with'); return; } @@ -19281,7 +19334,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function _receiveInviteResponse(response) { var _this22 = this; - debug('receiveInviteResponse()'); // Handle 2XX retransmissions and responses from forked requests. + logger.debug('receiveInviteResponse()'); // Handle 2XX retransmissions and responses from forked requests. if (this._dialog && response.status_code >= 200 && response.status_code <= 299) { /* @@ -19296,7 +19349,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var dialog = new Dialog(this, response, 'UAC'); if (dialog.error !== undefined) { - debug(dialog.error); + logger.debug(dialog.error); return; } @@ -19330,7 +19383,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { { // Do nothing with 1xx responses without To tag. if (!response.to_tag) { - debug('1xx response received without to tag'); + logger.debug('1xx response received without to tag'); break; } // Create Early Dialog if 1XX comes with contact. @@ -19355,7 +19408,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: 'answer', sdp: response.body }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); this.emit('sdp', e); var answer = new RTCSessionDescription({ type: 'answer', @@ -19366,7 +19419,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }).then(function () { return _this22._progress('remote', response); })["catch"](function (error) { - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); _this22.emit('peerconnection:setremotedescriptionfailed', error); }); @@ -19395,7 +19448,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: 'answer', sdp: response.body }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); this.emit('sdp', _e); var _answer = new RTCSessionDescription({ @@ -19430,7 +19483,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _this22._failed('remote', response, JsSIP_C.causes.BAD_MEDIA_DESCRIPTION); - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); _this22.emit('peerconnection:setremotedescriptionfailed', error); }); @@ -19456,7 +19509,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var _this23 = this; var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - debug('sendReinvite()'); + logger.debug('sendReinvite()'); var extraHeaders = Utils.cloneArray(options.extraHeaders); var eventHandlers = Utils.cloneObject(options.eventHandlers); var rtcOfferConstraints = options.rtcOfferConstraints || this._rtcOfferConstraints || null; @@ -19477,7 +19530,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: 'offer', sdp: sdp }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); _this23.emit('sdp', e); @@ -19540,7 +19593,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: 'answer', sdp: response.body }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); this.emit('sdp', e); var answer = new RTCSessionDescription({ type: 'answer', @@ -19554,7 +19607,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } })["catch"](function (error) { onFailed.call(_this24); - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); _this24.emit('peerconnection:setremotedescriptionfailed', error); }); @@ -19576,7 +19629,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var _this25 = this; var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - debug('sendUpdate()'); + logger.debug('sendUpdate()'); var extraHeaders = Utils.cloneArray(options.extraHeaders); var eventHandlers = Utils.cloneObject(options.eventHandlers); var rtcOfferConstraints = options.rtcOfferConstraints || this._rtcOfferConstraints || null; @@ -19599,7 +19652,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: 'offer', sdp: sdp }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); _this25.emit('sdp', e); @@ -19688,7 +19741,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { type: 'answer', sdp: response.body }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); this.emit('sdp', e); var answer = new RTCSessionDescription({ type: 'answer', @@ -19702,7 +19755,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } })["catch"](function (error) { onFailed.call(_this26); - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); _this26.emit('peerconnection:setremotedescriptionfailed', error); }); @@ -19721,7 +19774,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_acceptAndTerminate", value: function _acceptAndTerminate(response, status_code, reason_phrase) { - debug('acceptAndTerminate()'); + logger.debug('acceptAndTerminate()'); var extraHeaders = []; if (status_code) { @@ -19754,7 +19807,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { sdp = sdp_transform.parse(sdp); // Local hold. if (this._localHold && !this._remoteHold) { - debug('mangleOffer() | me on hold, mangling offer'); + logger.debug('mangleOffer() | me on hold, mangling offer'); var _iterator5 = _createForOfIteratorHelper(sdp.media), _step5; @@ -19782,7 +19835,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } } // Local and remote hold. else if (this._localHold && this._remoteHold) { - debug('mangleOffer() | both on hold, mangling offer'); + logger.debug('mangleOffer() | both on hold, mangling offer'); var _iterator6 = _createForOfIteratorHelper(sdp.media), _step6; @@ -19804,7 +19857,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } } // Remote hold. else if (this._remoteHold) { - debug('mangleOffer() | remote on hold, mangling offer'); + logger.debug('mangleOffer() | remote on hold, mangling offer'); var _iterator7 = _createForOfIteratorHelper(sdp.media), _step7; @@ -19926,7 +19979,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return; } - debug('runSessionTimer() | sending session refresh request'); + logger.debug('runSessionTimer() | sending session refresh request'); if (_this27._sessionTimers.refreshMethod === JsSIP_C.UPDATE) { _this27._sendUpdate(); @@ -19941,7 +19994,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return; } - debugerror('runSessionTimer() | timer expired, terminating the session'); + logger.warn('runSessionTimer() | timer expired, terminating the session'); _this27.terminate({ cause: JsSIP_C.causes.REQUEST_TIMEOUT, @@ -19996,7 +20049,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_newRTCSession", value: function _newRTCSession(originator, request) { - debug('newRTCSession()'); + logger.debug('newRTCSession()'); this._ua.newRTCSession(this, { originator: originator, @@ -20007,8 +20060,8 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_connecting", value: function _connecting(request) { - debug('session connecting'); - debug('emit "connecting"'); + logger.debug('session connecting'); + logger.debug('emit "connecting"'); this.emit('connecting', { request: request }); @@ -20016,8 +20069,8 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_progress", value: function _progress(originator, response) { - debug('session progress'); - debug('emit "progress"'); + logger.debug('session progress'); + logger.debug('emit "progress"'); this.emit('progress', { originator: originator, response: response || null @@ -20026,9 +20079,9 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_accepted", value: function _accepted(originator, message) { - debug('session accepted'); + logger.debug('session accepted'); this._start_time = new Date(); - debug('emit "accepted"'); + logger.debug('emit "accepted"'); this.emit('accepted', { originator: originator, response: message || null @@ -20037,9 +20090,9 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_confirmed", value: function _confirmed(originator, ack) { - debug('session confirmed'); + logger.debug('session confirmed'); this._is_confirmed = true; - debug('emit "confirmed"'); + logger.debug('emit "confirmed"'); this.emit('confirmed', { originator: originator, ack: ack || null @@ -20048,12 +20101,12 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_ended", value: function _ended(originator, message, cause) { - debug('session ended'); + logger.debug('session ended'); this._end_time = new Date(); this._close(); - debug('emit "ended"'); + logger.debug('emit "ended"'); this.emit('ended', { originator: originator, message: message || null, @@ -20063,9 +20116,9 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_failed", value: function _failed(originator, message, cause) { - debug('session failed'); // Emit private '_failed' event first. + logger.debug('session failed'); // Emit private '_failed' event first. - debug('emit "_failed"'); + logger.debug('emit "_failed"'); this.emit('_failed', { originator: originator, message: message || null, @@ -20074,7 +20127,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._close(); - debug('emit "failed"'); + logger.debug('emit "failed"'); this.emit('failed', { originator: originator, message: message || null, @@ -20084,11 +20137,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_onhold", value: function _onhold(originator) { - debug('session onhold'); + logger.debug('session onhold'); this._setLocalMediaStatus(); - debug('emit "hold"'); + logger.debug('emit "hold"'); this.emit('hold', { originator: originator }); @@ -20096,11 +20149,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_onunhold", value: function _onunhold(originator) { - debug('session onunhold'); + logger.debug('session onunhold'); this._setLocalMediaStatus(); - debug('emit "unhold"'); + logger.debug('emit "unhold"'); this.emit('unhold', { originator: originator }); @@ -20110,11 +20163,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function _onmute(_ref5) { var audio = _ref5.audio, video = _ref5.video; - debug('session onmute'); + logger.debug('session onmute'); this._setLocalMediaStatus(); - debug('emit "muted"'); + logger.debug('emit "muted"'); this.emit('muted', { audio: audio, video: video @@ -20125,11 +20178,11 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function _onunmute(_ref6) { var audio = _ref6.audio, video = _ref6.video; - debug('session onunmute'); + logger.debug('session onunmute'); this._setLocalMediaStatus(); - debug('emit "unmuted"'); + logger.debug('emit "unmuted"'); this.emit('unmuted', { audio: audio, video: video @@ -20203,7 +20256,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return RTCSession; }(EventEmitter); -},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":13,"./RTCSession/Info":14,"./RTCSession/ReferNotifier":15,"./RTCSession/ReferSubscriber":16,"./RequestSender":18,"./SIPMessage":19,"./Timers":21,"./Transactions":22,"./URI":25,"./Utils":26,"debug":30,"events":29,"sdp-transform":35}],13:[function(require,module,exports){ +},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./Logger":9,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":22,"./Transactions":23,"./URI":26,"./Utils":27,"events":30,"sdp-transform":36}],14:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } @@ -20230,17 +20283,15 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g var EventEmitter = require('events').EventEmitter; +var Logger = require('../Logger'); + var JsSIP_C = require('../Constants'); var Exceptions = require('../Exceptions'); var Utils = require('../Utils'); -var debug = require('debug')('JsSIP:RTCSession:DTMF'); - -var debugerror = require('debug')('JsSIP:ERROR:RTCSession:DTMF'); - -debugerror.log = console.warn.bind(console); +var logger = new Logger('RTCSession:DTMF'); var C = { MIN_DURATION: 70, MAX_DURATION: 6000, @@ -20377,7 +20428,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } if (!this._tone) { - debug('invalid INFO DTMF received, discarded'); + logger.debug('invalid INFO DTMF received, discarded'); } else { this._session.newDTMF({ originator: 'remote', @@ -20406,7 +20457,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { module.exports.C = C; -},{"../Constants":2,"../Exceptions":6,"../Utils":26,"debug":30,"events":29}],14:[function(require,module,exports){ +},{"../Constants":2,"../Exceptions":6,"../Logger":9,"../Utils":27,"events":30}],15:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } @@ -20433,10 +20484,6 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g var EventEmitter = require('events').EventEmitter; -var debugerror = require('debug')('JsSIP:ERROR:RTCSession:Info'); - -debugerror.log = console.warn.bind(console); - var JsSIP_C = require('../Constants'); var Exceptions = require('../Exceptions'); @@ -20546,7 +20593,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return Info; }(EventEmitter); -},{"../Constants":2,"../Exceptions":6,"../Utils":26,"debug":30,"events":29}],15:[function(require,module,exports){ +},{"../Constants":2,"../Exceptions":6,"../Utils":27,"events":30}],16:[function(require,module,exports){ "use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -20555,10 +20602,11 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } -var JsSIP_C = require('../Constants'); +var Logger = require('../Logger'); -var debug = require('debug')('JsSIP:RTCSession:ReferNotifier'); +var JsSIP_C = require('../Constants'); +var logger = new Logger('RTCSession:ReferNotifier'); var C = { event_type: 'refer', body_type: 'message/sipfrag;version=2.0', @@ -20580,7 +20628,7 @@ module.exports = /*#__PURE__*/function () { _createClass(ReferNotifier, [{ key: "notify", value: function notify(code, reason) { - debug('notify()'); + logger.debug('notify()'); if (this._active === false) { return; @@ -20611,7 +20659,7 @@ module.exports = /*#__PURE__*/function () { return ReferNotifier; }(); -},{"../Constants":2,"debug":30}],16:[function(require,module,exports){ +},{"../Constants":2,"../Logger":9}],17:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } @@ -20638,13 +20686,15 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g var EventEmitter = require('events').EventEmitter; +var Logger = require('../Logger'); + var JsSIP_C = require('../Constants'); var Grammar = require('../Grammar'); var Utils = require('../Utils'); -var debug = require('debug')('JsSIP:RTCSession:ReferSubscriber'); +var logger = new Logger('RTCSession:ReferSubscriber'); module.exports = /*#__PURE__*/function (_EventEmitter) { _inherits(ReferSubscriber, _EventEmitter); @@ -20668,7 +20718,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var _this2 = this; var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - debug('sendRefer()'); + logger.debug('sendRefer()'); var extraHeaders = Utils.cloneArray(options.extraHeaders); var eventHandlers = Utils.cloneObject(options.eventHandlers); // Set event handlers. @@ -20722,7 +20772,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "receiveNotify", value: function receiveNotify(request) { - debug('receiveNotify()'); + logger.debug('receiveNotify()'); if (!request.body) { return; @@ -20731,7 +20781,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var status_line = Grammar.parse(request.body.trim(), 'Status_Line'); if (status_line === -1) { - debug("receiveNotify() | error parsing NOTIFY body: \"".concat(request.body, "\"")); + logger.debug("receiveNotify() | error parsing NOTIFY body: \"".concat(request.body, "\"")); return; } @@ -20768,8 +20818,8 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_requestSucceeded", value: function _requestSucceeded(response) { - debug('REFER succeeded'); - debug('emit "requestSucceeded"'); + logger.debug('REFER succeeded'); + logger.debug('emit "requestSucceeded"'); this.emit('requestSucceeded', { response: response }); @@ -20777,8 +20827,8 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "_requestFailed", value: function _requestFailed(response, cause) { - debug('REFER failed'); - debug('emit "requestFailed"'); + logger.debug('REFER failed'); + logger.debug('emit "requestFailed"'); this.emit('requestFailed', { response: response || null, cause: cause @@ -20793,7 +20843,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return ReferSubscriber; }(EventEmitter); -},{"../Constants":2,"../Grammar":7,"../Utils":26,"debug":30,"events":29}],17:[function(require,module,exports){ +},{"../Constants":2,"../Grammar":7,"../Logger":9,"../Utils":27,"events":30}],18:[function(require,module,exports){ "use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -20802,6 +20852,8 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } +var Logger = require('./Logger'); + var Utils = require('./Utils'); var JsSIP_C = require('./Constants'); @@ -20810,8 +20862,7 @@ var SIPMessage = require('./SIPMessage'); var RequestSender = require('./RequestSender'); -var debug = require('debug')('JsSIP:Registrator'); - +var logger = new Logger('Registrator'); var MIN_REGISTER_EXPIRES = 10; // In seconds. module.exports = /*#__PURE__*/function () { @@ -20884,7 +20935,7 @@ module.exports = /*#__PURE__*/function () { var _this = this; if (this._registering) { - debug('Register request in progress...'); + logger.debug('Register request in progress...'); return; } @@ -20932,7 +20983,7 @@ module.exports = /*#__PURE__*/function () { _this._registering = false; if (!response.hasHeader('Contact')) { - debug('no Contact header in response to REGISTER, response ignored'); + logger.debug('no Contact header in response to REGISTER, response ignored'); break; } @@ -20945,7 +20996,7 @@ module.exports = /*#__PURE__*/function () { }); if (!contact) { - debug('no Contact header pointing to us, response ignored'); + logger.debug('no Contact header pointing to us, response ignored'); break; } @@ -21005,7 +21056,7 @@ module.exports = /*#__PURE__*/function () { _this.register(); } else { // This response MUST contain a Min-Expires header field. - debug('423 response received for REGISTER without Min-Expires'); + logger.debug('423 response received for REGISTER without Min-Expires'); _this._registrationFailure(response, JsSIP_C.causes.SIP_FAILURE_CODE); } @@ -21033,7 +21084,7 @@ module.exports = /*#__PURE__*/function () { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; if (!this._registered) { - debug('already unregistered'); + logger.debug('already unregistered'); return; } @@ -21153,7 +21204,7 @@ module.exports = /*#__PURE__*/function () { return Registrator; }(); -},{"./Constants":2,"./RequestSender":18,"./SIPMessage":19,"./Utils":26,"debug":30}],18:[function(require,module,exports){ +},{"./Constants":2,"./Logger":9,"./RequestSender":19,"./SIPMessage":20,"./Utils":27}],19:[function(require,module,exports){ "use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -21162,14 +21213,15 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } +var Logger = require('./Logger'); + var JsSIP_C = require('./Constants'); var DigestAuthentication = require('./DigestAuthentication'); var Transactions = require('./Transactions'); -var debug = require('debug')('JsSIP:RequestSender'); // Default event handlers. - +var logger = new Logger('RequestSender'); // Default event handlers. var EventHandlers = { onRequestTimeout: function onRequestTimeout() {}, @@ -21273,7 +21325,7 @@ module.exports = /*#__PURE__*/function () { if (!challenge) { - debug("".concat(response.status_code, " with wrong or missing challenge, cannot authenticate")); + logger.debug("".concat(response.status_code, " with wrong or missing challenge, cannot authenticate")); this._eventHandlers.onReceiveResponse(response); @@ -21328,7 +21380,7 @@ module.exports = /*#__PURE__*/function () { return RequestSender; }(); -},{"./Constants":2,"./DigestAuthentication":5,"./Transactions":22,"debug":30}],19:[function(require,module,exports){ +},{"./Constants":2,"./DigestAuthentication":5,"./Logger":9,"./Transactions":23}],20:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } @@ -21361,6 +21413,8 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d var sdp_transform = require('sdp-transform'); +var Logger = require('./Logger'); + var JsSIP_C = require('./Constants'); var Utils = require('./Utils'); @@ -21369,7 +21423,7 @@ var NameAddrHeader = require('./NameAddrHeader'); var Grammar = require('./Grammar'); -var debug = require('debug')('JsSIP:SIPMessage'); +var logger = new Logger('SIPMessage'); /** * -param {String} method request method * -param {String} ruri request uri @@ -21381,7 +21435,6 @@ var debug = require('debug')('JsSIP:SIPMessage'); * -param {String} [body] */ - var OutgoingRequest = /*#__PURE__*/function () { function OutgoingRequest(method, ruri, ua, params, extraHeaders, body) { _classCallCheck(this, OutgoingRequest); @@ -21860,10 +21913,10 @@ var IncomingMessage = /*#__PURE__*/function () { name = Utils.headerize(name); if (!this.headers[name]) { - debug("header \"".concat(name, "\" not present")); + logger.debug("header \"".concat(name, "\" not present")); return; } else if (idx >= this.headers[name].length) { - debug("not so many \"".concat(name, "\" headers present")); + logger.debug("not so many \"".concat(name, "\" headers present")); return; } @@ -21880,7 +21933,7 @@ var IncomingMessage = /*#__PURE__*/function () { if (parsed === -1) { this.headers[name].splice(idx, 1); // delete from headers - debug("error parsing \"".concat(name, "\" header field with value \"").concat(value, "\"")); + logger.debug("error parsing \"".concat(name, "\" header field with value \"").concat(value, "\"")); return; } else { header.parsed = parsed; @@ -22183,16 +22236,16 @@ module.exports = { IncomingRequest: IncomingRequest, IncomingResponse: IncomingResponse }; -},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":26,"debug":30,"sdp-transform":35}],20:[function(require,module,exports){ +},{"./Constants":2,"./Grammar":7,"./Logger":9,"./NameAddrHeader":11,"./Utils":27,"sdp-transform":36}],21:[function(require,module,exports){ "use strict"; +var Logger = require('./Logger'); + var Utils = require('./Utils'); var Grammar = require('./Grammar'); -var debugerror = require('debug')('JsSIP:ERROR:Socket'); - -debugerror.log = console.warn.bind(console); +var logger = new Logger('Socket'); /** * Interface documentation: https://jssip.net/documentation/$last_version/api/socket/ * @@ -22219,24 +22272,24 @@ exports.isSocket = function (socket) { } if (typeof socket === 'undefined') { - debugerror('undefined JsSIP.Socket instance'); + logger.warn('undefined JsSIP.Socket instance'); return false; } // Check Properties. try { if (!Utils.isString(socket.url)) { - debugerror('missing or invalid JsSIP.Socket url property'); + logger.warn('missing or invalid JsSIP.Socket url property'); throw new Error(); } if (!Utils.isString(socket.via_transport)) { - debugerror('missing or invalid JsSIP.Socket via_transport property'); + logger.warn('missing or invalid JsSIP.Socket via_transport property'); throw new Error(); } if (Grammar.parse(socket.sip_uri, 'SIP_URI') === -1) { - debugerror('missing or invalid JsSIP.Socket sip_uri property'); + logger.warn('missing or invalid JsSIP.Socket sip_uri property'); throw new Error(); } } catch (e) { @@ -22247,7 +22300,7 @@ exports.isSocket = function (socket) { try { ['connect', 'disconnect', 'send'].forEach(function (method) { if (!Utils.isFunction(socket[method])) { - debugerror("missing or invalid JsSIP.Socket method: ".concat(method)); + logger.warn("missing or invalid JsSIP.Socket method: ".concat(method)); throw new Error(); } }); @@ -22257,7 +22310,7 @@ exports.isSocket = function (socket) { return true; }; -},{"./Grammar":7,"./Utils":26,"debug":30}],21:[function(require,module,exports){ +},{"./Grammar":7,"./Logger":9,"./Utils":27}],22:[function(require,module,exports){ "use strict"; var T1 = 500, @@ -22279,7 +22332,7 @@ module.exports = { PROVISIONAL_RESPONSE_INTERVAL: 60000 // See RFC 3261 Section 13.3.1.1 }; -},{}],22:[function(require,module,exports){ +},{}],23:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } @@ -22306,22 +22359,19 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g var EventEmitter = require('events').EventEmitter; +var Logger = require('./Logger'); + var JsSIP_C = require('./Constants'); var SIPMessage = require('./SIPMessage'); var Timers = require('./Timers'); -var debugnict = require('debug')('JsSIP:NonInviteClientTransaction'); - -var debugict = require('debug')('JsSIP:InviteClientTransaction'); - -var debugact = require('debug')('JsSIP:AckClientTransaction'); - -var debugnist = require('debug')('JsSIP:NonInviteServerTransaction'); - -var debugist = require('debug')('JsSIP:InviteServerTransaction'); - +var loggernict = new Logger('NonInviteClientTransaction'); +var loggerict = new Logger('InviteClientTransaction'); +var loggeract = new Logger('AckClientTransaction'); +var loggernist = new Logger('NonInviteServerTransaction'); +var loggerist = new Logger('InviteServerTransaction'); var C = { // Transaction states. STATUS_TRYING: 1, @@ -22388,7 +22438,7 @@ var NonInviteClientTransaction = /*#__PURE__*/function (_EventEmitter) { }, { key: "onTransportError", value: function onTransportError() { - debugnict("transport error occurred, deleting transaction ".concat(this.id)); + loggernict.debug("transport error occurred, deleting transaction ".concat(this.id)); clearTimeout(this.F); clearTimeout(this.K); this.stateChanged(C.STATUS_TERMINATED); @@ -22398,7 +22448,7 @@ var NonInviteClientTransaction = /*#__PURE__*/function (_EventEmitter) { }, { key: "timer_F", value: function timer_F() { - debugnict("Timer F expired for transaction ".concat(this.id)); + loggernict.debug("Timer F expired for transaction ".concat(this.id)); this.stateChanged(C.STATUS_TERMINATED); this.ua.destroyTransaction(this); this.eventHandlers.onRequestTimeout(); @@ -22513,7 +22563,7 @@ var InviteClientTransaction = /*#__PURE__*/function (_EventEmitter2) { clearTimeout(this.M); if (this.state !== C.STATUS_ACCEPTED) { - debugict("transport error occurred, deleting transaction ".concat(this.id)); + loggerict.debug("transport error occurred, deleting transaction ".concat(this.id)); this.eventHandlers.onTransportError(); } @@ -22524,7 +22574,7 @@ var InviteClientTransaction = /*#__PURE__*/function (_EventEmitter2) { }, { key: "timer_M", value: function timer_M() { - debugict("Timer M expired for transaction ".concat(this.id)); + loggerict.debug("Timer M expired for transaction ".concat(this.id)); if (this.state === C.STATUS_ACCEPTED) { clearTimeout(this.B); @@ -22536,7 +22586,7 @@ var InviteClientTransaction = /*#__PURE__*/function (_EventEmitter2) { }, { key: "timer_B", value: function timer_B() { - debugict("Timer B expired for transaction ".concat(this.id)); + loggerict.debug("Timer B expired for transaction ".concat(this.id)); if (this.state === C.STATUS_CALLING) { this.stateChanged(C.STATUS_TERMINATED); @@ -22547,7 +22597,7 @@ var InviteClientTransaction = /*#__PURE__*/function (_EventEmitter2) { }, { key: "timer_D", value: function timer_D() { - debugict("Timer D expired for transaction ".concat(this.id)); + loggerict.debug("Timer D expired for transaction ".concat(this.id)); clearTimeout(this.B); this.stateChanged(C.STATUS_TERMINATED); this.ua.destroyTransaction(this); @@ -22684,7 +22734,7 @@ var AckClientTransaction = /*#__PURE__*/function (_EventEmitter3) { }, { key: "onTransportError", value: function onTransportError() { - debugact("transport error occurred for transaction ".concat(this.id)); + loggeract.debug("transport error occurred for transaction ".concat(this.id)); this.eventHandlers.onTransportError(); } }, { @@ -22729,7 +22779,7 @@ var NonInviteServerTransaction = /*#__PURE__*/function (_EventEmitter4) { }, { key: "timer_J", value: function timer_J() { - debugnist("Timer J expired for transaction ".concat(this.id)); + loggernist.debug("Timer J expired for transaction ".concat(this.id)); this.stateChanged(C.STATUS_TERMINATED); this.ua.destroyTransaction(this); } @@ -22738,7 +22788,7 @@ var NonInviteServerTransaction = /*#__PURE__*/function (_EventEmitter4) { value: function onTransportError() { if (!this.transportError) { this.transportError = true; - debugnist("transport error occurred, deleting transaction ".concat(this.id)); + loggernist.debug("transport error occurred, deleting transaction ".concat(this.id)); clearTimeout(this.J); this.stateChanged(C.STATUS_TERMINATED); this.ua.destroyTransaction(this); @@ -22851,10 +22901,10 @@ var InviteServerTransaction = /*#__PURE__*/function (_EventEmitter5) { }, { key: "timer_H", value: function timer_H() { - debugist("Timer H expired for transaction ".concat(this.id)); + loggerist.debug("Timer H expired for transaction ".concat(this.id)); if (this.state === C.STATUS_COMPLETED) { - debugist('ACK not received, dialog will be terminated'); + loggerist.debug('ACK not received, dialog will be terminated'); } this.stateChanged(C.STATUS_TERMINATED); @@ -22870,7 +22920,7 @@ var InviteServerTransaction = /*#__PURE__*/function (_EventEmitter5) { }, { key: "timer_L", value: function timer_L() { - debugist("Timer L expired for transaction ".concat(this.id)); + loggerist.debug("Timer L expired for transaction ".concat(this.id)); if (this.state === C.STATUS_ACCEPTED) { this.stateChanged(C.STATUS_TERMINATED); @@ -22882,7 +22932,7 @@ var InviteServerTransaction = /*#__PURE__*/function (_EventEmitter5) { value: function onTransportError() { if (!this.transportError) { this.transportError = true; - debugist("transport error occurred, deleting transaction ".concat(this.id)); + loggerist.debug("transport error occurred, deleting transaction ".concat(this.id)); if (this.resendProvisionalTimer !== null) { clearInterval(this.resendProvisionalTimer); @@ -23108,7 +23158,7 @@ module.exports = { InviteServerTransaction: InviteServerTransaction, checkTransaction: checkTransaction }; -},{"./Constants":2,"./SIPMessage":19,"./Timers":21,"debug":30,"events":29}],23:[function(require,module,exports){ +},{"./Constants":2,"./Logger":9,"./SIPMessage":20,"./Timers":22,"events":30}],24:[function(require,module,exports){ "use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -23117,15 +23167,13 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } -var Socket = require('./Socket'); - -var debug = require('debug')('JsSIP:Transport'); +var Logger = require('./Logger'); -var debugerror = require('debug')('JsSIP:ERROR:Transport'); +var Socket = require('./Socket'); var JsSIP_C = require('./Constants'); -debugerror.log = console.warn.bind(console); +var logger = new Logger('Transport'); /** * Constants */ @@ -23159,7 +23207,7 @@ module.exports = /*#__PURE__*/function () { _classCallCheck(this, Transport); - debug('new()'); + logger.debug('new()'); this.status = C.STATUS_DISCONNECTED; // Current socket. this.socket = null; // Socket collection. @@ -23174,7 +23222,7 @@ module.exports = /*#__PURE__*/function () { try { this.textDecoder = new TextDecoder('utf8'); } catch (error) { - debugerror("cannot use TextDecoder: ".concat(error)); + logger.warn("cannot use TextDecoder: ".concat(error)); } if (typeof sockets === 'undefined') { @@ -23211,13 +23259,13 @@ module.exports = /*#__PURE__*/function () { _createClass(Transport, [{ key: "connect", value: function connect() { - debug('connect()'); + logger.debug('connect()'); if (this.isConnected()) { - debug('Transport is already connected'); + logger.debug('Transport is already connected'); return; } else if (this.isConnecting()) { - debug('Transport is connecting'); + logger.debug('Transport is connecting'); return; } @@ -23241,7 +23289,7 @@ module.exports = /*#__PURE__*/function () { }, { key: "disconnect", value: function disconnect() { - debug('close()'); + logger.debug('close()'); this.close_requested = true; this.recover_attempts = 0; this.status = C.STATUS_DISCONNECTED; // Clear recovery_timer. @@ -23267,15 +23315,15 @@ module.exports = /*#__PURE__*/function () { }, { key: "send", value: function send(data) { - debug('send()'); + logger.debug('send()'); if (!this.isConnected()) { - debugerror('unable to send message, transport is not connected'); + logger.warn('unable to send message, transport is not connected'); return false; } var message = data.toString(); - debug("sending message:\n\n".concat(message, "\n")); + logger.debug("sending message:\n\n".concat(message, "\n")); return this.socket.send(message); } }, { @@ -23306,7 +23354,7 @@ module.exports = /*#__PURE__*/function () { k = this.recovery_options.max_interval; } - debug("reconnection attempt: ".concat(this.recover_attempts, ". next connection attempt in ").concat(k, " seconds")); + logger.debug("reconnection attempt: ".concat(this.recover_attempts, ". next connection attempt in ").concat(k, " seconds")); this.recovery_timer = setTimeout(function () { if (!_this.close_requested && !(_this.isConnected() || _this.isConnecting())) { // Get the next available socket with higher weight. @@ -23399,21 +23447,21 @@ module.exports = /*#__PURE__*/function () { value: function _onData(data) { // CRLF Keep Alive response from server. Ignore it. if (data === '\r\n') { - debug('received message with CRLF Keep Alive response'); + logger.debug('received message with CRLF Keep Alive response'); return; } // Binary message. else if (typeof data !== 'string') { try { if (this.textDecoder) data = this.textDecoder.decode(data);else data = String.fromCharCode.apply(null, new Uint8Array(data)); } catch (evt) { - debug('received binary message failed to be converted into string,' + ' message discarded'); + logger.debug('received binary message failed to be converted into string,' + ' message discarded'); return; } - debug("received binary message:\n\n".concat(data, "\n")); + logger.debug("received binary message:\n\n".concat(data, "\n")); } // Text message. else { - debug("received text message:\n\n".concat(data, "\n")); + logger.debug("received text message:\n\n".concat(data, "\n")); } this.ondata({ @@ -23440,7 +23488,7 @@ module.exports = /*#__PURE__*/function () { return Transport; }(); -},{"./Constants":2,"./Socket":20,"debug":30}],24:[function(require,module,exports){ +},{"./Constants":2,"./Logger":9,"./Socket":21}],25:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } @@ -23467,6 +23515,8 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g var EventEmitter = require('events').EventEmitter; +var Logger = require('./Logger'); + var JsSIP_C = require('./Constants'); var Registrator = require('./Registrator'); @@ -23493,11 +23543,7 @@ var sanityCheck = require('./sanityCheck'); var config = require('./Config'); -var debug = require('debug')('JsSIP:UA'); - -var debugerror = require('debug')('JsSIP:ERROR:UA'); - -debugerror.log = console.warn.bind(console); +var logger = new Logger('UA'); var C = { // UA status codes. STATUS_INIT: 0, @@ -23534,7 +23580,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { _classCallCheck(this, UA); - debug('new() [configuration:%o]', configuration); + logger.debug('new() [configuration:%o]', configuration); _this = _super.call(this); _this._cache = { credentials: {} @@ -23588,12 +23634,12 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { * Resume UA after being closed. */ value: function start() { - debug('start()'); + logger.debug('start()'); if (this._status === C.STATUS_INIT) { this._transport.connect(); } else if (this._status === C.STATUS_USER_CLOSED) { - debug('restarting UA'); // Disconnect. + logger.debug('restarting UA'); // Disconnect. if (this._closeTimer !== null) { clearTimeout(this._closeTimer); @@ -23607,9 +23653,9 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._transport.connect(); } else if (this._status === C.STATUS_READY) { - debug('UA is in READY status, not restarted'); + logger.debug('UA is in READY status, not restarted'); } else { - debug('ERROR: connection is down, Auto-Recovery system is trying to reconnect'); + logger.debug('ERROR: connection is down, Auto-Recovery system is trying to reconnect'); } // Set dynamic configuration. @@ -23622,7 +23668,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "register", value: function register() { - debug('register()'); + logger.debug('register()'); this._dynConfiguration.register = true; this._registrator.register(); @@ -23634,7 +23680,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "unregister", value: function unregister(options) { - debug('unregister()'); + logger.debug('unregister()'); this._dynConfiguration.register = false; this._registrator.unregister(options); @@ -23679,7 +23725,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "call", value: function call(target, options) { - debug('call()'); + logger.debug('call()'); var session = new RTCSession(this); session.connect(target, options); return session; @@ -23698,7 +23744,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "sendMessage", value: function sendMessage(target, body, options) { - debug('sendMessage()'); + logger.debug('sendMessage()'); var message = new Message(this); message.send(target, body, options); return message; @@ -23710,7 +23756,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { }, { key: "terminateSessions", value: function terminateSessions(options) { - debug('terminateSessions()'); + logger.debug('terminateSessions()'); for (var idx in this._sessions) { if (!this._sessions[idx].isEnded()) { @@ -23728,12 +23774,12 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { value: function stop() { var _this2 = this; - debug('stop()'); // Remove dynamic settings. + logger.debug('stop()'); // Remove dynamic settings. this._dynConfiguration = {}; if (this._status === C.STATUS_USER_CLOSED) { - debug('UA already closed'); + logger.debug('UA already closed'); return; } // Close registrator. @@ -23745,7 +23791,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { for (var session in this._sessions) { if (Object.prototype.hasOwnProperty.call(this._sessions, session)) { - debug("closing session ".concat(session)); + logger.debug("closing session ".concat(session)); try { this._sessions[session].terminate(); @@ -23805,7 +23851,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { return this._configuration.authorization_jwt; default: - debugerror('get() | cannot get "%s" parameter in runtime', parameter); + logger.warn('get() | cannot get "%s" parameter in runtime', parameter); return undefined; } } @@ -23857,7 +23903,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } default: - debugerror('set() | cannot set "%s" parameter in runtime', parameter); + logger.warn('set() | cannot set "%s" parameter in runtime', parameter); return false; } @@ -23986,7 +24032,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { var method = request.method; // Check that request URI points to us. if (request.ruri.user !== this._configuration.uri.user && request.ruri.user !== this._contact.uri.user) { - debug('Request-URI does not point to us'); + logger.debug('Request-URI does not point to us'); if (request.method !== JsSIP_C.ACK) { request.reply_sl(404); @@ -24069,7 +24115,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { session.init_incoming(request); } } else { - debugerror('INVITE received but WebRTC is not supported'); + logger.warn('INVITE received but WebRTC is not supported'); request.reply(488); } @@ -24086,7 +24132,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { if (session) { session.receiveRequest(request); } else { - debug('received CANCEL request for a non existent session'); + logger.debug('received CANCEL request for a non existent session'); } break; @@ -24123,7 +24169,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { if (session) { session.receiveRequest(request); } else { - debug('received NOTIFY request for a non existent subscription'); + logger.debug('received NOTIFY request for a non existent subscription'); request.reply(481, 'Subscription does not exist'); } } @@ -24227,7 +24273,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { this._transport.ondisconnect = onTransportDisconnect.bind(this); this._transport.ondata = onTransportData.bind(this); } catch (e) { - debugerror(e); + logger.warn(e); throw new Exceptions.ConfigurationError('sockets', this._configuration.sockets); } // Remove sockets instance from configuration object. @@ -24305,7 +24351,7 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { } } - debug('configuration parameters after validation:'); + logger.debug('configuration parameters after validation:'); for (var _parameter in this._configuration) { // Only show the user user configurable parameters. @@ -24313,17 +24359,17 @@ module.exports = /*#__PURE__*/function (_EventEmitter) { switch (_parameter) { case 'uri': case 'registrar_server': - debug("- ".concat(_parameter, ": ").concat(this._configuration[_parameter])); + logger.debug("- ".concat(_parameter, ": ").concat(this._configuration[_parameter])); break; case 'password': case 'ha1': case 'authorization_jwt': - debug("- ".concat(_parameter, ": NOT SHOWN")); + logger.debug("- ".concat(_parameter, ": NOT SHOWN")); break; default: - debug("- ".concat(_parameter, ": ").concat(JSON.stringify(this._configuration[_parameter]))); + logger.debug("- ".concat(_parameter, ": ").concat(JSON.stringify(this._configuration[_parameter]))); } } } @@ -24463,7 +24509,7 @@ function onTransportData(data) { } } } -},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Parser":11,"./RTCSession":12,"./Registrator":17,"./SIPMessage":19,"./Transactions":22,"./Transport":23,"./URI":25,"./Utils":26,"./sanityCheck":28,"debug":30,"events":29}],25:[function(require,module,exports){ +},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Logger":9,"./Message":10,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./SIPMessage":20,"./Transactions":23,"./Transport":24,"./URI":26,"./Utils":27,"./sanityCheck":29,"events":30}],26:[function(require,module,exports){ "use strict"; function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } @@ -24725,7 +24771,7 @@ module.exports = /*#__PURE__*/function () { return URI; }(); -},{"./Constants":2,"./Grammar":7,"./Utils":26}],26:[function(require,module,exports){ +},{"./Constants":2,"./Grammar":7,"./Utils":27}],27:[function(require,module,exports){ "use strict"; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } @@ -25258,7 +25304,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":25}],27:[function(require,module,exports){ +},{"./Constants":2,"./Grammar":7,"./URI":26}],28:[function(require,module,exports){ "use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -25267,19 +25313,17 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } -var Grammar = require('./Grammar'); - -var debug = require('debug')('JsSIP:WebSocketInterface'); +var Logger = require('./Logger'); -var debugerror = require('debug')('JsSIP:ERROR:WebSocketInterface'); +var Grammar = require('./Grammar'); -debugerror.log = console.warn.bind(console); +var logger = new Logger('WebSocketInterface'); module.exports = /*#__PURE__*/function () { function WebSocketInterface(url) { _classCallCheck(this, WebSocketInterface); - debug('new() [url:"%s"]', url); + logger.debug('new() [url:"%s"]', url); this._url = url; this._sip_uri = null; this._via_transport = null; @@ -25287,10 +25331,10 @@ module.exports = /*#__PURE__*/function () { var parsed_url = Grammar.parse(url, 'absoluteURI'); if (parsed_url === -1) { - debugerror("invalid WebSocket URI: ".concat(url)); + logger.warn("invalid WebSocket URI: ".concat(url)); throw new TypeError("Invalid argument: ".concat(url)); } else if (parsed_url.scheme !== 'wss' && parsed_url.scheme !== 'ws') { - debugerror("invalid WebSocket URI scheme: ".concat(parsed_url.scheme)); + logger.warn("invalid WebSocket URI scheme: ".concat(parsed_url.scheme)); throw new TypeError("Invalid argument: ".concat(url)); } else { this._sip_uri = "sip:".concat(parsed_url.host).concat(parsed_url.port ? ":".concat(parsed_url.port) : '', ";transport=ws"); @@ -25301,13 +25345,13 @@ module.exports = /*#__PURE__*/function () { _createClass(WebSocketInterface, [{ key: "connect", value: function connect() { - debug('connect()'); + logger.debug('connect()'); if (this.isConnected()) { - debug("WebSocket ".concat(this._url, " is already connected")); + logger.debug("WebSocket ".concat(this._url, " is already connected")); return; } else if (this.isConnecting()) { - debug("WebSocket ".concat(this._url, " is connecting")); + logger.debug("WebSocket ".concat(this._url, " is connecting")); return; } @@ -25315,7 +25359,7 @@ module.exports = /*#__PURE__*/function () { this.disconnect(); } - debug("connecting to WebSocket ".concat(this._url)); + logger.debug("connecting to WebSocket ".concat(this._url)); try { this._ws = new WebSocket(this._url, 'sip'); @@ -25331,7 +25375,7 @@ module.exports = /*#__PURE__*/function () { }, { key: "disconnect", value: function disconnect() { - debug('disconnect()'); + logger.debug('disconnect()'); if (this._ws) { // Unbind websocket event callbacks. @@ -25351,14 +25395,14 @@ module.exports = /*#__PURE__*/function () { }, { key: "send", value: function send(message) { - debug('send()'); + logger.debug('send()'); if (this.isConnected()) { this._ws.send(message); return true; } else { - debugerror('unable to send message, WebSocket is not open'); + logger.warn('unable to send message, WebSocket is not open'); return false; } } @@ -25379,7 +25423,7 @@ module.exports = /*#__PURE__*/function () { }, { key: "_onOpen", value: function _onOpen() { - debug("WebSocket ".concat(this._url, " connected")); + logger.debug("WebSocket ".concat(this._url, " connected")); this.onconnect(); } }, { @@ -25388,10 +25432,10 @@ module.exports = /*#__PURE__*/function () { var wasClean = _ref.wasClean, code = _ref.code, reason = _ref.reason; - debug("WebSocket ".concat(this._url, " closed")); + logger.debug("WebSocket ".concat(this._url, " closed")); if (wasClean === false) { - debug('WebSocket abrupt disconnection'); + logger.debug('WebSocket abrupt disconnection'); } this.ondisconnect(!wasClean, code, reason); @@ -25400,13 +25444,13 @@ module.exports = /*#__PURE__*/function () { key: "_onMessage", value: function _onMessage(_ref2) { var data = _ref2.data; - debug('received WebSocket message'); + logger.debug('received WebSocket message'); this.ondata(data); } }, { key: "_onError", value: function _onError(e) { - debugerror("WebSocket ".concat(this._url, " error: "), e); + logger.warn("WebSocket ".concat(this._url, " error: "), e); } }, { key: "via_transport", @@ -25430,7 +25474,7 @@ module.exports = /*#__PURE__*/function () { return WebSocketInterface; }(); -},{"./Grammar":7,"debug":30}],28:[function(require,module,exports){ +},{"./Grammar":7,"./Logger":9}],29:[function(require,module,exports){ "use strict"; function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } @@ -25439,14 +25483,15 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o = function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } +var Logger = require('./Logger'); + var JsSIP_C = require('./Constants'); var SIPMessage = require('./SIPMessage'); var Utils = require('./Utils'); -var debug = require('debug')('JsSIP:sanityCheck'); // Checks for requests and responses. - +var logger = new Logger('sanityCheck'); // Checks for requests and responses. var all = [minimumHeaders]; // Checks for requests. @@ -25620,7 +25665,7 @@ function rfc3261_8_2_2_2() { function rfc3261_8_1_3_3() { if (message.getHeaders('via').length > 1) { - debug('more than one Via header field present in the response, dropping the response'); + logger.debug('more than one Via header field present in the response, dropping the response'); return false; } } @@ -25630,7 +25675,7 @@ function rfc3261_18_3_response() { contentLength = message.getHeader('content-length'); if (len < contentLength) { - debug('message body length is lower than the value in Content-Length header field, dropping the response'); + logger.debug('message body length is lower than the value in Content-Length header field, dropping the response'); return false; } } // Sanity Check functions for requests and responses. @@ -25643,7 +25688,7 @@ function minimumHeaders() { var header = _mandatoryHeaders[_i]; if (!message.hasHeader(header)) { - debug("missing mandatory header field : ".concat(header, ", dropping the response")); + logger.debug("missing mandatory header field : ".concat(header, ", dropping the response")); return false; } } @@ -25682,7 +25727,7 @@ function reply(status_code) { response += '\r\n'; transport.send(response); } -},{"./Constants":2,"./SIPMessage":19,"./Utils":26,"debug":30}],29:[function(require,module,exports){ +},{"./Constants":2,"./Logger":9,"./SIPMessage":20,"./Utils":27}],30:[function(require,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -26207,7 +26252,7 @@ function functionBindPolyfill(context) { }; } -},{}],30:[function(require,module,exports){ +},{}],31:[function(require,module,exports){ (function (process){ /* eslint-env browser */ @@ -26475,7 +26520,7 @@ formatters.j = function (v) { }; }).call(this,require('_process')) -},{"./common":31,"_process":33}],31:[function(require,module,exports){ +},{"./common":32,"_process":34}],32:[function(require,module,exports){ /** * This is the common logic for both the Node.js and web browser @@ -26743,7 +26788,7 @@ function setup(env) { module.exports = setup; -},{"ms":32}],32:[function(require,module,exports){ +},{"ms":33}],33:[function(require,module,exports){ /** * Helpers. */ @@ -26907,7 +26952,7 @@ function plural(ms, msAbs, n, name) { return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : ''); } -},{}],33:[function(require,module,exports){ +},{}],34:[function(require,module,exports){ // shim for using process in browser var process = module.exports = {}; @@ -27093,7 +27138,7 @@ process.chdir = function (dir) { }; process.umask = function() { return 0; }; -},{}],34:[function(require,module,exports){ +},{}],35:[function(require,module,exports){ var grammar = module.exports = { v: [{ name: 'version', @@ -27589,7 +27634,7 @@ Object.keys(grammar).forEach(function (key) { }); }); -},{}],35:[function(require,module,exports){ +},{}],36:[function(require,module,exports){ var parser = require('./parser'); var writer = require('./writer'); @@ -27602,7 +27647,7 @@ exports.parseRemoteCandidates = parser.parseRemoteCandidates; exports.parseImageAttributes = parser.parseImageAttributes; exports.parseSimulcastStreamList = parser.parseSimulcastStreamList; -},{"./parser":36,"./writer":37}],36:[function(require,module,exports){ +},{"./parser":37,"./writer":38}],37:[function(require,module,exports){ var toIntIfInt = function (v) { return String(Number(v)) === v ? Number(v) : v; }; @@ -27728,7 +27773,7 @@ exports.parseSimulcastStreamList = function (str) { }); }; -},{"./grammar":34}],37:[function(require,module,exports){ +},{"./grammar":35}],38:[function(require,module,exports){ var grammar = require('./grammar'); // customized util.format - discards excess arguments and can void middle ones @@ -27844,7 +27889,7 @@ module.exports = function (session, opts) { return sdp.join('\r\n') + '\r\n'; }; -},{"./grammar":34}],38:[function(require,module,exports){ +},{"./grammar":35}],39:[function(require,module,exports){ module.exports={ "name": "jssip", "title": "JsSIP", diff --git a/dist/jssip.min.js b/dist/jssip.min.js index 59d4909..dbc188b 100644 --- a/dist/jssip.min.js +++ b/dist/jssip.min.js @@ -6,4 +6,4 @@ * License: MIT */ -!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).JsSIP=e()}}(function(){return function(){return function e(t,n,r){function s(o,l){if(!n[o]){if(!t[o]){var u="function"==typeof require&&require;if(!l&&u)return u(o,!0);if(i)return i(o,!0);var a=new Error("Cannot find module '"+o+"'");throw a.code="MODULE_NOT_FOUND",a}var c=n[o]={exports:{}};t[o][0].call(c.exports,function(e){return s(t[o][1][e]||e)},c,c.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;o=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,l=!0,u=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return l=e.done,e},e:function(e){u=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(u)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)return t}},connection_recovery_min_interval:function(e){if(i.isDecimal(e)){var t=Number(e);if(t>0)return t}},contact_uri:function(e){if("string"==typeof e){var t=l.parse(e,"SIP_URI");if(-1!==t)return t}},display_name:function(e){return e},instance_id:function(e){return/^uuid:/i.test(e)&&(e=e.substr(5)),-1===l.parse(e,"uuid")?void 0:e},no_answer_timeout:function(e){if(i.isDecimal(e)){var t=Number(e);if(t>0)return t}},session_timers:function(e){if("boolean"==typeof e)return e},session_timers_refresh_method:function(e){if("string"==typeof e&&((e=e.toUpperCase())===o.INVITE||e===o.UPDATE))return e},session_timers_force_refresher:function(e){if("boolean"==typeof e)return e},password:function(e){return String(e)},realm:function(e){return String(e)},ha1:function(e){return String(e)},register:function(e){if("boolean"==typeof e)return e},register_expires:function(e){if(i.isDecimal(e)){var t=Number(e);if(t>0)return t}},registrar_server:function(e){/^sip:/i.test(e)||(e="".concat(o.SIP,":").concat(e));var t=u.parse(e);return t?t.user?void 0:t:void 0},use_preloaded_route:function(e){if("boolean"==typeof e)return e}}};n.load=function(e,t){for(var n in h.mandatory){if(!t.hasOwnProperty(n))throw new c.ConfigurationError(n);var r=t[n],s=h.mandatory[n](r);if(void 0===s)throw new c.ConfigurationError(n,r);e[n]=s}for(var o in h.optional)if(t.hasOwnProperty(o)){var l=t[o];if(i.isEmpty(l))continue;var u=h.optional[o](l);if(void 0===u)throw new c.ConfigurationError(o,l);e[o]=u}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":20,"./URI":25,"./Utils":26}],2:[function(e,t,n){"use strict";var r=e("../package.json");t.exports={USER_AGENT:"".concat(r.title," ").concat(r.version),SIP:"sip",SIPS:"sips",causes:{CONNECTION_ERROR:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":38}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:h.STATUS_CONFIRMED;if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this._owner=t,this._ua=t._ua,this._uac_pending_reply=!1,this._uas_pending_reply=!1,!n.hasHeader("contact"))return{error:"unable to create a Dialog without Contact header field"};n instanceof i.IncomingResponse&&(s=n.status_code<200?h.STATUS_EARLY:h.STATUS_CONFIRMED);var o=n.parseHeader("contact");"UAS"===r?(this._id={call_id:n.call_id,local_tag:n.to_tag,remote_tag:n.from_tag,toString:function(){return this.call_id+this.local_tag+this.remote_tag}},this._state=s,this._remote_seqnum=n.cseq,this._local_uri=n.parseHeader("to").uri,this._remote_uri=n.parseHeader("from").uri,this._remote_target=o.uri,this._route_set=n.getHeaders("record-route"),this._ack_seqnum=this._remote_seqnum):"UAC"===r&&(this._id={call_id:n.call_id,local_tag:n.from_tag,remote_tag:n.to_tag,toString:function(){return this.call_id+this.local_tag+this.remote_tag}},this._state=s,this._local_seqnum=n.cseq,this._local_uri=n.parseHeader("from").uri,this._remote_uri=n.parseHeader("to").uri,this._remote_target=o.uri,this._route_set=n.getHeaders("record-route").reverse(),this._ack_seqnum=null),this._ua.newDialog(this),c("new ".concat(r," dialog created with status ").concat(this._state===h.STATUS_EARLY?"EARLY":"CONFIRMED"))}return s(e,null,[{key:"C",get:function(){return h}}]),s(e,[{key:"update",value:function(e,t){this._state=h.STATUS_CONFIRMED,c("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){c("dialog ".concat(this._id.toString()," deleted")),this._ua.destroyDialog(this)}},{key:"sendRequest",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=a.cloneArray(n.extraHeaders),s=a.cloneObject(n.eventHandlers),i=n.body||null,o=this._createRequest(e,r,i);return s.onAuthenticated=function(){t._local_seqnum+=1},new u(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===o.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===o.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=a.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===o.CANCEL||e===o.ACK?this._local_seqnum:this._local_seqnum+=1;return new i.OutgoingRequest(e,this._remote_target,this._ua,{cseq:r,call_id:this._id.call_id,from_uri:this._local_uri,from_tag:this._id.local_tag,to_uri:this._remote_uri,to_tag:this._id.remote_tag,route_set:this._route_set},t,n)}},{key:"_checkInDialogRequest",value:function(e){var t=this;if(this._remote_seqnum)if(e.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===o.INVITE||e.method===o.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==l.C.STATUS_ACCEPTED&&e.server_transaction.state!==l.C.STATUS_COMPLETED&&e.server_transaction.state!==l.C.STATUS_TERMINATED||(e.server_transaction.removeListener("stateChanged",n),t._uas_pending_reply=!1)})}e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===l.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===o.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===l.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}},{key:"id",get:function(){return this._id}},{key:"local_seqnum",get:function(){return this._local_seqnum},set:function(e){this._local_seqnum=e}},{key:"owner",get:function(){return this._owner}},{key:"uac_pending_reply",get:function(){return this._uac_pending_reply},set:function(e){this._uac_pending_reply=e}},{key:"uas_pending_reply",get:function(){return this._uas_pending_reply}}]),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":19,"./Transactions":22,"./Utils":26,debug:30}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200&&e.status_code<300?this._eventHandlers.onSuccessResponse(e):e.status_code>=300&&this._eventHandlers.onErrorResponse(e):(this._request.cseq=this._dialog.local_seqnum+=1,this._reattemptTimer=setTimeout(function(){t._dialog.owner.status!==o.C.STATUS_TERMINATED&&(t._reattempt=!0,t._request_sender.send())},1e3)):e.status_code>=200&&e.status_code<300?this._eventHandlers.onSuccessResponse(e):e.status_code>=300&&this._eventHandlers.onErrorResponse(e)}},{key:"request",get:function(){return this._request}}])&&r(t.prototype,n),a&&r(t,a),e}()},{"../Constants":2,"../RTCSession":12,"../RequestSender":18,"../Transactions":22}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&void 0!==arguments[2]?arguments[2]:null;if(this._algorithm=t.algorithm,this._realm=t.realm,this._nonce=t.nonce,this._opaque=t.opaque,this._stale=t.stale,this._algorithm){if("MD5"!==this._algorithm)return o('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'),!1}else this._algorithm="MD5";if(!this._nonce)return o("authenticate() | challenge without Digest nonce, authentication aborted"),!1;if(!this._realm)return o("authenticate() | challenge without Digest realm, authentication aborted"),!1;if(!this._credentials.password){if(!this._credentials.ha1)return o("authenticate() | no plain SIP password nor ha1 provided, authentication aborted"),!1;if(this._credentials.realm!==this._realm)return o('authenticate() | no plain SIP password, and stored `realm` does not match the given `realm`, cannot authenticate [stored:"%s", given:"%s"]',this._credentials.realm,this._realm),!1}if(t.qop)if(t.qop.indexOf("auth-int")>-1)this._qop="auth-int";else{if(!(t.qop.indexOf("auth")>-1))return o('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted'),!1;this._qop="auth"}else this._qop=null;this._method=n,this._uri=r,this._cnonce=u||s.createRandomToken(12),this._nc+=1;var a,c,h=Number(this._nc).toString(16);return this._ncHex="00000000".substr(0,8-h.length)+h,4294967296===this._nc&&(this._nc=1,this._ncHex="00000001"),this._credentials.password?this._ha1=s.calculateMD5("".concat(this._credentials.username,":").concat(this._realm,":").concat(this._credentials.password)):this._ha1=this._credentials.ha1,"auth"===this._qop?(a="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(a),i('authenticate() | using qop=auth [a2:"%s"]',a),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(c))):"auth-int"===this._qop?(a="".concat(this._method,":").concat(this._uri,":").concat(s.calculateMD5(l||"")),c=s.calculateMD5(a),i('authenticate() | using qop=auth-int [a2:"%s"]',a),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(c))):null===this._qop&&(a="".concat(this._method,":").concat(this._uri),c=s.calculateMD5(a),i('authenticate() | using qop=null [a2:"%s"]',a),this._response=s.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(c))),i("authenticate() | response generated"),!0}},{key:"toString",value:function(){var e=[];if(!this._response)throw new Error("response field does not exist, cannot generate Authorization header");return e.push("algorithm=".concat(this._algorithm)),e.push('username="'.concat(this._credentials.username,'"')),e.push('realm="'.concat(this._realm,'"')),e.push('nonce="'.concat(this._nonce,'"')),e.push('uri="'.concat(this._uri,'"')),e.push('response="'.concat(this._response,'"')),this._opaque&&e.push('opaque="'.concat(this._opaque,'"')),this._qop&&(e.push("qop=".concat(this._qop)),e.push('cnonce="'.concat(this._cnonce,'"')),e.push("nc=".concat(this._ncHex))),"Digest ".concat(e.join(", "))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Utils":26,debug:30}],6:[function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&c(e,t)}function o(e){var t=a();return function(){var n,s=h(e);if(t){var i=h(this).constructor;n=Reflect.construct(s,arguments,i)}else n=s.apply(this,arguments);return function(e,t){if(t&&("object"===r(t)||"function"==typeof t))return t;return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(this,n)}}function l(e){var t="function"==typeof Map?new Map:void 0;return(l=function(e){if(null===e||(n=e,-1===Function.toString.call(n).indexOf("[native code]")))return e;var n;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return u(e,arguments,h(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),c(r,e)})(e)}function u(e,t,n){return(u=a()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var s=new(Function.bind.apply(e,r));return n&&c(s,n.prototype),s}).apply(null,arguments)}function a(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}function c(e,t){return(c=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function h(e){return(h=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}var f=function(e){i(n,l(Error));var t=o(n);function n(e,r){var i;return s(this,n),(i=t.call(this)).code=1,i.name="CONFIGURATION_ERROR",i.parameter=e,i.value=r,i.message=i.value?"Invalid value ".concat(JSON.stringify(i.value),' for parameter "').concat(i.parameter,'"'):"Missing parameter: ".concat(i.parameter),i}return n}(),d=function(e){i(n,l(Error));var t=o(n);function n(e){var r;return s(this,n),(r=t.call(this)).code=2,r.name="INVALID_STATE_ERROR",r.status=e,r.message="Invalid status: ".concat(e),r}return n}(),_=function(e){i(n,l(Error));var t=o(n);function n(e){var r;return s(this,n),(r=t.call(this)).code=3,r.name="NOT_SUPPORTED_ERROR",r.message=e,r}return n}(),p=function(e){i(n,l(Error));var t=o(n);function n(e){var r;return s(this,n),(r=t.call(this)).code=4,r.name="NOT_READY_ERROR",r.message=e,r}return n}();t.exports={ConfigurationError:f,InvalidStateError:d,NotSupportedError:_,NotReadyError:p}},{}],7:[function(e,t,n){"use strict";t.exports=function(){function t(e){return'"'+e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g,escape)+'"'}var n={parse:function(n,r){var s={CRLF:c,DIGIT:h,ALPHA:f,HEXDIG:d,WSP:_,OCTET:p,DQUOTE:m,SP:v,HTAB:g,alphanum:y,reserved:T,unreserved:C,mark:S,escaped:E,LWS:A,SWS:b,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[a-f]")));return e},token:k,token_nodot:D,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&a('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&a('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&a('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&a('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&a('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&a('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&a('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&a('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&a('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&a('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&a('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&a('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&a('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&a('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&a('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&a('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:U,STAR:x,SLASH:P,EQUAL:M,LPAREN:q,RPAREN:L,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:G,COLON:W,LDQUOT:V,RDQUOT:B,comment:function e(){var t,n,r;var s;s=i;t=q();if(null!==t){for(n=[],null===(r=K())&&null===(r=$())&&(r=e());null!==r;)n.push(r),null===(r=K())&&null===(r=$())&&(r=e());null!==n&&null!==(r=L())?t=[t,n,r]:(t=null,i=s)}else t=null,i=s;return t},ctext:K,quoted_string:Y,quoted_string_clean:z,qdtext:J,quoted_pair:$,SIP_URI_noparams:X,SIP_URI:Q,uri_scheme:Z,uri_scheme_sips:ee,uri_scheme_sip:te,userinfo:ne,user:re,user_unreserved:se,password:ie,hostport:oe,host:le,hostname:ue,domainlabel:ae,toplabel:ce,IPv6reference:he,IPv6address:fe,h16:de,ls32:_e,IPv4address:pe,dec_octet:me,port:ve,uri_parameters:ge,uri_parameter:ye,transport_param:Te,user_param:Ce,method_param:Se,ttl_param:Ee,maddr_param:Ae,lr_param:be,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:De,hname:Ue,hvalue:xe,hnv_unreserved:Pe,Request_Response:function(){var e;null===(e=ht())&&(e=Me());return e},Request_Line:Me,Request_URI:qe,absoluteURI:Le,hier_part:He,net_path:Fe,abs_path:je,opaque_part:Ge,uric:We,uric_no_slash:Ve,path_segments:Be,segment:Ke,param:Ye,pchar:ze,scheme:Je,authority:$e,srvr:Xe,reg_name:Qe,query:Ze,SIP_Version:et,INVITEm:tt,ACKm:nt,OPTIONSm:rt,BYEm:st,CANCELm:it,REGISTERm:ot,SUBSCRIBEm:lt,NOTIFYm:ut,REFERm:at,Method:ct,Status_Line:ht,Status_Code:ft,extension_code:dt,Reason_Phrase:_t,Allow_Events:function(){var e,t,n,r,s,o;if(s=i,null!==(e=Lt())){for(t=[],o=i,null!==(n=j())&&null!==(r=Lt())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=Lt())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e},Call_ID:function(){var e,t,r,s,l,u;s=i,l=i,null!==(e=U())?(u=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&a('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=u),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=l)):(e=null,i=l);null!==e&&(c=s,e=void(jn=n.substring(i,c)));var c;null===e&&(i=s);return e},Contact:function(){var e,t,n,r,s,o,l;if(s=i,null===(e=x()))if(o=i,null!==(e=pt())){for(t=[],l=i,null!==(n=j())&&null!==(r=pt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=j())&&null!==(r=pt())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;null!==e&&(e=function(e){var t,n;for(n=jn.multi_header.length,t=0;tl&&(l=i,u=[]),u.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&a('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[0-9]")),e}function f(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[a-zA-Z]")),e}function d(){var e;return/^[0-9a-fA-F]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[0-9a-fA-F]")),e}function _(){var e;return null===(e=v())&&(e=g()),e}function p(){var e;return/^[\0-\xFF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&a('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&a('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&a('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&a('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&a('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&a('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&a('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&a('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&a('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&a('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&a('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&a('","'))))))))))),e}function C(){var e;return null===(e=y())&&(e=S()),e}function S(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&a('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&a('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&a('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&a('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&a('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&a('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&a('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&a('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&a('")"')))))))))),e}function E(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&a('"%"')),null!==e&&null!==(t=d())&&null!==(r=d())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=e.join("")),null===e&&(i=s),e}function A(){var e,t,n,r,s,o;for(r=i,s=i,o=i,e=[],t=_();null!==t;)e.push(t),t=_();if(null!==e&&null!==(t=c())?e=[e,t]:(e=null,i=o),null!==(e=null!==e?e:"")){if(null!==(n=_()))for(t=[];null!==n;)t.push(n),n=_();else t=null;null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return null!==e&&(e=" "),null===e&&(i=r),e}function b(){var e;return e=null!==(e=A())?e:""}function R(){var e,t,r,s,l;for(s=i,l=i,e=[],null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=v())&&(t=g());return null!==e?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=b())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=":"),null===e&&(i=s),e}function w(){var e,t,r,s,o,l,u,a;if(o=i,l=i,null!==(t=I()))for(e=[];null!==t;)e.push(t),t=I();else e=null;if(null!==e){for(t=[],u=i,r=[],s=A();null!==s;)r.push(s),s=A();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=u);null!==r;){for(t.push(r),u=i,r=[],s=A();null!==s;)r.push(s),s=A();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=u)}null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[!-~]")),null===e&&(e=O()),e}function O(){var e;return/^[\x80-\uFFFF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&a('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&a('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&a('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&a('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&a('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&a('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&a('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&a('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&a('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&a('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&a('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&a('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&a('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&a('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&a('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&a('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&a('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&a('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&a('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&a('"~"'))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function D(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&a('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&a('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&a('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&a('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&a('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&a('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&a('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&a('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&a('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&a('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&a('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&a('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&a('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&a('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&a('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&a('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&a('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&a('"~"')))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function U(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&a('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&a('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&a('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&a('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&a('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&a('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&a('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&a('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&a('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&a('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&a('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&a('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&a('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&a('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&a('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&a('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&a('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&a('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&a('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&a('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&a('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&a('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&a('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&a('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&a('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&a('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&a('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&a('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&a('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&a('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&a('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&a('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&a('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&a('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&a('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&a('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&a('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&a('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&a('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&a('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&a('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&a('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function x(){var e,t,r,s,l;return s=i,l=i,null!==(e=b())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&a('"*"')),null!==t&&null!==(r=b())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=b())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&a('"/"')),null!==t&&null!==(r=b())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="/"),null===e&&(i=s),e}function M(){var e,t,r,s,l;return s=i,l=i,null!==(e=b())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&a('"="')),null!==t&&null!==(r=b())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="="),null===e&&(i=s),e}function q(){var e,t,r,s,l;return s=i,l=i,null!==(e=b())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&a('"("')),null!==t&&null!==(r=b())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="("),null===e&&(i=s),e}function L(){var e,t,r,s,l;return s=i,l=i,null!==(e=b())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&a('")"')),null!==t&&null!==(r=b())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=")"),null===e&&(i=s),e}function H(){var e,t,r,s;return r=i,s=i,62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&a('">"')),null!==e&&null!==(t=b())?e=[e,t]:(e=null,i=s),null!==e&&(e=">"),null===e&&(i=r),e}function F(){var e,t,r,s;return r=i,s=i,null!==(e=b())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&a('"<"')),null!==t?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(e="<"),null===e&&(i=r),e}function j(){var e,t,r,s,l;return s=i,l=i,null!==(e=b())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&a('","')),null!==t&&null!==(r=b())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function G(){var e,t,r,s,l;return s=i,l=i,null!==(e=b())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&a('";"')),null!==t&&null!==(r=b())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=";"),null===e&&(i=s),e}function W(){var e,t,r,s,l;return s=i,l=i,null!==(e=b())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=b())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=":"),null===e&&(i=s),e}function V(){var e,t,n,r;return n=i,r=i,null!==(e=b())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function B(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=b())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function K(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[\\]-~]")),null===e&&null===(e=O())&&(e=A()))),e}function Y(){var e,t,r,s,o,l,u;if(o=i,l=i,null!==(e=b()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(s=$());null!==r&&null!==(s=m())?e=[e,t,r,s]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;return null!==e&&(u=o,e=n.substring(i,u)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,u,a;if(o=i,l=i,null!==(e=b()))if(null!==(t=m())){for(r=[],null===(s=J())&&(s=$());null!==s;)r.push(s),null===(s=J())&&(s=$());null!==r&&null!==(s=m())?e=[e,t,r,s]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;return null!==e&&(u=o,e=(a=n.substring(i,u).trim()).substring(1,a.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function J(){var e;return null===(e=A())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&a('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[\\]-~]")),null===e&&(e=O())))),e}function $(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&a('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&a("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&a("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&a("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function X(){var e,t,r,s,l,u;return l=i,u=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=u)):(e=null,i=u),null!==e&&(e=function(e){try{jn.uri=new Hn(jn.scheme,jn.user,jn.host,jn.port),delete jn.scheme,delete jn.user,delete jn.host,delete jn.host_type,delete jn.port}catch(e){jn=-1}}()),null===e&&(i=l),e}function Q(){var e,t,s,l,u,c,h,f;return h=i,f=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(u=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,u,c]:(e=null,i=f)):(e=null,i=f),null!==e&&(e=function(e){try{jn.uri=new Hn(jn.scheme,jn.user,jn.host,jn.port,jn.uri_params,jn.uri_headers),delete jn.scheme,delete jn.user,delete jn.host,delete jn.host_type,delete jn.port,delete jn.uri_params,"SIP_URI"===r&&(jn=jn.uri)}catch(e){jn=-1}}()),null===e&&(i=h),e}function Z(){var e;return null===(e=ee())&&(e=te()),e}function ee(){var e,t,r;return t=i,"sips"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&a('"sips"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function te(){var e,t,r;return t=i,"sip"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&a('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,u,c;return s=i,l=i,null!==(e=re())?(u=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=u),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&a('"@"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l)):(e=null,i=l),null!==e&&(c=s,e=void(jn.user=decodeURIComponent(n.substring(i-1,c)))),null===e&&(i=s),e}function re(){var e,t;if(null===(t=C())&&null===(t=E())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=C())&&null===(t=E())&&(t=se());else e=null;return e}function se(){var e;return 38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&a('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&a('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&a('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&a('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&a('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&a('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&a('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&a('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=C())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&a('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&a('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&a('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&a('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&a('","')))))));null!==t;)e.push(t),null===(t=C())&&null===(t=E())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&a('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&a('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&a('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&a('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&a('","')))))));return null!==e&&(s=r,e=void(jn.password=n.substring(i,s))),null===e&&(i=r),e}function oe(){var e,t,r,s,l;return s=i,null!==(e=le())?(l=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=ve())?t=[t,r]:(t=null,i=l),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),e}function le(){var e,t,r;return t=i,null===(e=ue())&&null===(e=pe())&&(e=he()),null!==e&&(r=t,jn.host=n.substring(i,r).toLowerCase(),e=jn.host),null===e&&(i=t),e}function ue(){var e,t,r,s,l,u,c;for(s=i,l=i,e=[],u=i,null!==(t=ae())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&a('"."')),null!==r?t=[t,r]:(t=null,i=u)):(t=null,i=u);null!==t;)e.push(t),u=i,null!==(t=ae())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&a('"."')),null!==r?t=[t,r]:(t=null,i=u)):(t=null,i=u);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&a('"."')),null!==(r=null!==r?r:"")?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(c=s,jn.host_type="domain",e=n.substring(i,c)),null===e&&(i=s),e}function ae(){var e,t,r,s;if(s=i,null!==(e=y())){for(t=[],null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&a('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&a('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&a('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&a('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function ce(){var e,t,r,s;if(s=i,null!==(e=f())){for(t=[],null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&a('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&a('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&a('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&a('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,u;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&a('"["')),null!==e&&null!==(t=fe())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&a('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(u=s,jn.host_type="IPv6",e=n.substring(i,u)),null===e&&(i=s),e}function fe(){var e,t,r,s,l,u,c,h,f,d,_,p,m,v,g,y,T;return v=i,g=i,null!==(e=de())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&a('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(u=":",i++):(u=null,0===o&&a('":"')),null!==u&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&a('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&a('":"')),null!==d&&null!==(_=de())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&a('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,u,c,h,f,d,_,p,m]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===n.substr(i,2)?(e="::",i+=2):(e=null,0===o&&a('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&a('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&a('":"')),null!==f&&null!==(d=de())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&a('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,u,c,h,f,d,_,p]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===n.substr(i,2)?(e="::",i+=2):(e=null,0===o&&a('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&a('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&a('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,u,c,h,f,d]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===n.substr(i,2)?(e="::",i+=2):(e=null,0===o&&a('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&a('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,u,c,h]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===n.substr(i,2)?(e="::",i+=2):(e=null,0===o&&a('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=_e())?e=[e,t,r,s,l,u]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===n.substr(i,2)?(e="::",i+=2):(e=null,0===o&&a('"::"')),null!==e&&null!==(t=de())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=_e())?e=[e,t,r,s]:(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===n.substr(i,2)?(e="::",i+=2):(e=null,0===o&&a('"::"')),null!==e&&null!==(t=_e())?e=[e,t]:(e=null,i=g),null===e&&(g=i,"::"===n.substr(i,2)?(e="::",i+=2):(e=null,0===o&&a('"::"')),null!==e&&null!==(t=de())?e=[e,t]:(e=null,i=g),null===e&&(g=i,null!==(e=de())?("::"===n.substr(i,2)?(t="::",i+=2):(t=null,0===o&&a('"::"')),null!==t&&null!==(r=de())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&a('":"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(u=":",i++):(u=null,0===o&&a('":"')),null!==u&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&a('":"')),null!==h&&null!==(f=de())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&a('":"')),null!==d&&null!==(_=_e())?e=[e,t,r,s,l,u,c,h,f,d,_]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=de())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=de())?t=[t,r]:(t=null,i=y),null!==(t=null!==t?t:"")?("::"===n.substr(i,2)?(r="::",i+=2):(r=null,0===o&&a('"::"')),null!==r&&null!==(s=de())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&a('":"')),null!==c&&null!==(h=de())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&a('":"')),null!==f&&null!==(d=_e())?e=[e,t,r,s,l,u,c,h,f,d]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=de())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=de())?t=[t,r]:(t=null,i=y),null!==(t=null!==t?t:"")?(y=i,58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=de())?r=[r,s]:(r=null,i=y),null!==(r=null!==r?r:"")?("::"===n.substr(i,2)?(s="::",i+=2):(s=null,0===o&&a('"::"')),null!==s&&null!==(l=de())?(58===n.charCodeAt(i)?(u=":",i++):(u=null,0===o&&a('":"')),null!==u&&null!==(c=de())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&a('":"')),null!==h&&null!==(f=_e())?e=[e,t,r,s,l,u,c,h,f]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=de())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=de())?t=[t,r]:(t=null,i=y),null!==(t=null!==t?t:"")?(y=i,58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=de())?r=[r,s]:(r=null,i=y),null!==(r=null!==r?r:"")?(y=i,58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&a('":"')),null!==s&&null!==(l=de())?s=[s,l]:(s=null,i=y),null!==(s=null!==s?s:"")?("::"===n.substr(i,2)?(l="::",i+=2):(l=null,0===o&&a('"::"')),null!==l&&null!==(u=de())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&a('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,u,c,h]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=de())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=de())?t=[t,r]:(t=null,i=y),null!==(t=null!==t?t:"")?(y=i,58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=de())?r=[r,s]:(r=null,i=y),null!==(r=null!==r?r:"")?(y=i,58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&a('":"')),null!==s&&null!==(l=de())?s=[s,l]:(s=null,i=y),null!==(s=null!==s?s:"")?(y=i,58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=de())?l=[l,u]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(u="::",i+=2):(u=null,0===o&&a('"::"')),null!==u&&null!==(c=_e())?e=[e,t,r,s,l,u,c]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=de())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=de())?t=[t,r]:(t=null,i=y),null!==(t=null!==t?t:"")?(y=i,58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=de())?r=[r,s]:(r=null,i=y),null!==(r=null!==r?r:"")?(y=i,58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&a('":"')),null!==s&&null!==(l=de())?s=[s,l]:(s=null,i=y),null!==(s=null!==s?s:"")?(y=i,58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=de())?l=[l,u]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(u=":",i++):(u=null,0===o&&a('":"')),null!==u&&null!==(c=de())?u=[u,c]:(u=null,i=y),null!==(u=null!==u?u:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&a('"::"')),null!==c&&null!==(h=de())?e=[e,t,r,s,l,u,c,h]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=de())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=de())?t=[t,r]:(t=null,i=y),null!==(t=null!==t?t:"")?(y=i,58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=de())?r=[r,s]:(r=null,i=y),null!==(r=null!==r?r:"")?(y=i,58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&a('":"')),null!==s&&null!==(l=de())?s=[s,l]:(s=null,i=y),null!==(s=null!==s?s:"")?(y=i,58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=de())?l=[l,u]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(u=":",i++):(u=null,0===o&&a('":"')),null!==u&&null!==(c=de())?u=[u,c]:(u=null,i=y),null!==(u=null!==u?u:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&a('":"')),null!==c&&null!==(h=de())?c=[c,h]:(c=null,i=y),null!==(c=null!==c?c:"")?("::"===n.substr(i,2)?(h="::",i+=2):(h=null,0===o&&a('"::"')),null!==h?e=[e,t,r,s,l,u,c,h]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g))))))))))))))),null!==e&&(T=v,jn.host_type="IPv6",e=n.substring(i,T)),null===e&&(i=v),e}function de(){var e,t,n,r,s;return s=i,null!==(e=d())&&null!==(t=null!==(t=d())?t:"")&&null!==(n=null!==(n=d())?n:"")&&null!==(r=null!==(r=d())?r:"")?e=[e,t,n,r]:(e=null,i=s),e}function _e(){var e,t,r,s;return s=i,null!==(e=de())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=de())?e=[e,t,r]:(e=null,i=s)):(e=null,i=s),null===e&&(e=pe()),e}function pe(){var e,t,r,s,l,u,c,h,f,d;return h=i,f=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&a('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&a('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(u=".",i++):(u=null,0===o&&a('"."')),null!==u&&null!==(c=me())?e=[e,t,r,s,l,u,c]:(e=null,i=f)):(e=null,i=f)):(e=null,i=f)):(e=null,i=f),null!==e&&(d=h,jn.host_type="IPv4",e=n.substring(i,d)),null===e&&(i=h),e}function me(){var e,t,r,s;return s=i,"25"===n.substr(i,2)?(e="25",i+=2):(e=null,0===o&&a('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&a("[0-5]")),null!==t?e=[e,t]:(e=null,i=s)):(e=null,i=s),null===e&&(s=i,50===n.charCodeAt(i)?(e="2",i++):(e=null,0===o&&a('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&a("[0-4]")),null!==t&&null!==(r=h())?e=[e,t,r]:(e=null,i=s)):(e=null,i=s),null===e&&(s=i,49===n.charCodeAt(i)?(e="1",i++):(e=null,0===o&&a('"1"')),null!==e&&null!==(t=h())&&null!==(r=h())?e=[e,t,r]:(e=null,i=s),null===e&&(s=i,/^[1-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[1-9]")),null!==e&&null!==(t=h())?e=[e,t]:(e=null,i=s),null===e&&(e=h())))),e}function ve(){var e,t,n,r,s,o,l,u;return o=i,l=i,null!==(e=null!==(e=h())?e:"")&&null!==(t=null!==(t=h())?t:"")&&null!==(n=null!==(n=h())?n:"")&&null!==(r=null!==(r=h())?r:"")&&null!==(s=null!==(s=h())?s:"")?e=[e,t,n,r,s]:(e=null,i=l),null!==e&&(u=e,u=parseInt(u.join("")),jn.port=u,e=u),null===e&&(i=o),e}function ge(){var e,t,r,s;for(e=[],s=i,59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&a('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);null!==t;)e.push(t),s=i,59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&a('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Ce())&&null===(e=Se())&&null===(e=Ee())&&null===(e=Ae())&&null===(e=be())&&(e=Re()),e}function Te(){var e,t,r,s,l;return r=i,s=i,"transport="===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&a('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&a('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&a('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&a('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&a('"tls"')),null===t&&(t=k())))),null!==t?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[1],jn.uri_params||(jn.uri_params={}),e=void(jn.uri_params.transport=l.toLowerCase())),null===e&&(i=r),e}function Ce(){var e,t,r,s,l;return r=i,s=i,"user="===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&a('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&a('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&a('"ip"')),null===t&&(t=k())),null!==t?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[1],jn.uri_params||(jn.uri_params={}),e=void(jn.uri_params.user=l.toLowerCase())),null===e&&(i=r),e}function Se(){var e,t,r,s,l;return r=i,s=i,"method="===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&a('"method="')),null!==e&&null!==(t=ct())?e=[e,t]:(e=null,i=s),null!==e&&(l=e[1],jn.uri_params||(jn.uri_params={}),e=void(jn.uri_params.method=l)),null===e&&(i=r),e}function Ee(){var e,t,r,s,l;return r=i,s=i,"ttl="===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&a('"ttl="')),null!==e&&null!==(t=bn())?e=[e,t]:(e=null,i=s),null!==e&&(l=e[1],jn.params||(jn.params={}),e=void(jn.params.ttl=l)),null===e&&(i=r),e}function Ae(){var e,t,r,s,l;return r=i,s=i,"maddr="===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&a('"maddr="')),null!==e&&null!==(t=le())?e=[e,t]:(e=null,i=s),null!==e&&(l=e[1],jn.uri_params||(jn.uri_params={}),e=void(jn.uri_params.maddr=l)),null===e&&(i=r),e}function be(){var e,t,r,s,l,u;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&a('"lr"')),null!==e?(u=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&a('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=u),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=l)):(e=null,i=l),null!==e&&(jn.uri_params||(jn.uri_params={}),e=void(jn.uri_params.lr=void 0)),null===e&&(i=s),e}function Re(){var e,t,r,s,l,u,c,h;return s=i,l=i,null!==(e=we())?(u=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&a('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=u),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=l)):(e=null,i=l),null!==e&&(c=e[0],h=e[1],jn.uri_params||(jn.uri_params={}),h=void 0===h?void 0:h[1],e=void(jn.uri_params[c.toLowerCase()]=h)),null===e&&(i=s),e}function we(){var e,t,n;if(n=i,null!==(t=Oe()))for(e=[];null!==t;)e.push(t),t=Oe();else e=null;return null!==e&&(e=e.join("")),null===e&&(i=n),e}function Ie(){var e,t,n;if(n=i,null!==(t=Oe()))for(e=[];null!==t;)e.push(t),t=Oe();else e=null;return null!==e&&(e=e.join("")),null===e&&(i=n),e}function Oe(){var e;return null===(e=Ne())&&null===(e=C())&&(e=E()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&a('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&a('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&a('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&a('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&a('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&a('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&a('"$"')))))))),e}function ke(){var e,t,r,s,l,u,c;if(u=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&a('"?"')),null!==e)if(null!==(t=De())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&a('"&"')),null!==s&&null!==(l=De())?s=[s,l]:(s=null,i=c);null!==s;)r.push(s),c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&a('"&"')),null!==s&&null!==(l=De())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=u)}else e=null,i=u;else e=null,i=u;return e}function De(){var e,t,r,s,l,u,c;return s=i,l=i,null!==(e=Ue())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&a('"="')),null!==t&&null!==(r=xe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(u=e[0],c=e[2],u=u.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[u]?jn.uri_headers[u].push(c):jn.uri_headers[u]=[c])),null===e&&(i=s),e}function Ue(){var e,t;if(null===(t=Pe())&&null===(t=C())&&(t=E()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=Pe())&&null===(t=C())&&(t=E());else e=null;return e}function xe(){var e,t;for(e=[],null===(t=Pe())&&null===(t=C())&&(t=E());null!==t;)e.push(t),null===(t=Pe())&&null===(t=C())&&(t=E());return e}function Pe(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&a('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&a('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&a('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&a('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&a('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&a('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&a('"$"')))))))),e}function Me(){var e,t,n,r,s,o;return o=i,null!==(e=ct())&&null!==(t=v())&&null!==(n=qe())&&null!==(r=v())&&null!==(s=et())?e=[e,t,n,r,s]:(e=null,i=o),e}function qe(){var e;return null===(e=Q())&&(e=Le()),e}function Le(){var e,t,r,s;return s=i,null!==(e=Je())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t?(null===(r=He())&&(r=Ge()),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s)):(e=null,i=s),e}function He(){var e,t,r,s,l;return s=i,null===(e=Fe())&&(e=je()),null!==e?(l=i,63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&a('"?"')),null!==t&&null!==(r=Ze())?t=[t,r]:(t=null,i=l),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),e}function Fe(){var e,t,r,s;return s=i,"//"===n.substr(i,2)?(e="//",i+=2):(e=null,0===o&&a('"//"')),null!==e&&null!==(t=$e())&&null!==(r=null!==(r=je())?r:"")?e=[e,t,r]:(e=null,i=s),e}function je(){var e,t,r;return r=i,47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&a('"/"')),null!==e&&null!==(t=Be())?e=[e,t]:(e=null,i=r),e}function Ge(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=We();null!==n;)t.push(n),n=We();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function We(){var e;return null===(e=T())&&null===(e=C())&&(e=E()),e}function Ve(){var e;return null===(e=C())&&null===(e=E())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&a('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&a('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&a('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&a('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&a('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&a('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&a('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&a('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&a('","'))))))))))),e}function Be(){var e,t,r,s,l,u;if(l=i,null!==(e=Ke())){for(t=[],u=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&a('"/"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=u);null!==r;)t.push(r),u=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&a('"/"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=u);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t,r,s,l,u;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],u=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&a('";"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=u);null!==r;)t.push(r),u=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&a('";"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=u);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=C())&&null===(e=E())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&a('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&a('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&a('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&a('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&a('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&a('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&a('","'))))))))),e}function Je(){var e,t,r,s,l,u;if(s=i,l=i,null!==(e=f())){for(t=[],null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&a('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&a('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&a('"."')))));null!==r;)t.push(r),null===(r=f())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&a('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&a('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&a('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(u=s,e=void(jn.scheme=n.substring(i,u))),null===e&&(i=s),e}function $e(){var e;return null===(e=Xe())&&(e=Qe()),e}function Xe(){var e,t,r,s;return r=i,s=i,null!==(e=ne())?(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&a('"@"')),null!==t?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==(e=null!==e?e:"")&&null!==(t=oe())?e=[e,t]:(e=null,i=r),e=null!==e?e:""}function Qe(){var e,t;if(null===(t=C())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&a('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&a('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&a('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&a('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&a('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&a('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&a('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=C())&&null===(t=E())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&a('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&a('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&a('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&a('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&a('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&a('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&a('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=We();null!==t;)e.push(t),t=We();return e}function et(){var e,t,r,s,l,u,c,f,d;if(c=i,f=i,"sip"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&a('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&a('"/"')),null!==t){if(null!==(s=h()))for(r=[];null!==s;)r.push(s),s=h();else r=null;if(null!==r)if(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&a('"."')),null!==s){if(null!==(u=h()))for(l=[];null!==u;)l.push(u),u=h();else l=null;null!==l?e=[e,t,r,s,l]:(e=null,i=f)}else e=null,i=f;else e=null,i=f}else e=null,i=f;else e=null,i=f;return null!==e&&(d=c,e=void(jn.sip_version=n.substring(i,d))),null===e&&(i=c),e}function tt(){var e;return"INVITE"===n.substr(i,6)?(e="INVITE",i+=6):(e=null,0===o&&a('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&a('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&a('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&a('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&a('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&a('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&a('"SUBSCRIBE"')),e}function ut(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&a('"NOTIFY"')),e}function at(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&a('"REFER"')),e}function ct(){var e,t,r;return t=i,null===(e=tt())&&null===(e=nt())&&null===(e=rt())&&null===(e=st())&&null===(e=it())&&null===(e=ot())&&null===(e=lt())&&null===(e=ut())&&null===(e=at())&&(e=k()),null!==e&&(r=t,jn.method=n.substring(i,r),e=jn.method),null===e&&(i=t),e}function ht(){var e,t,n,r,s,o;return o=i,null!==(e=et())&&null!==(t=v())&&null!==(n=ft())&&null!==(r=v())&&null!==(s=_t())?e=[e,t,n,r,s]:(e=null,i=o),e}function ft(){var e,t,n;return t=i,null!==(e=dt())&&(n=e,e=void(jn.status_code=parseInt(n.join("")))),null===e&&(i=t),e}function dt(){var e,t,n,r;return r=i,null!==(e=h())&&null!==(t=h())&&null!==(n=h())?e=[e,t,n]:(e=null,i=r),e}function _t(){var e,t,r,s;for(r=i,e=[],null===(t=T())&&null===(t=C())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=C())&&null===(t=E())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());return null!==e&&(s=r,e=void(jn.reason_phrase=n.substring(i,s))),null===e&&(i=r),e}function pt(){var e,t,n,r,s,o,l;if(s=i,o=i,null===(e=X())&&(e=mt()),null!==e){for(t=[],l=i,null!==(n=G())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=G())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;return null!==e&&(e=function(e){var t;jn.multi_header||(jn.multi_header=[]);try{t=new Fn(jn.uri,jn.display_name,jn.params),delete jn.uri,delete jn.display_name,delete jn.params}catch(e){t=null}jn.multi_header.push({possition:i,offset:e,parsed:t})}(s)),null===e&&(i=s),e}function mt(){var e,t,n,r,s;return s=i,null!==(e=null!==(e=vt())?e:"")&&null!==(t=F())&&null!==(n=Q())&&null!==(r=H())?e=[e,t,n,r]:(e=null,i=s),e}function vt(){var e,t,n,r,s,o,l,u;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=A())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=A())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;return null===e&&(e=z()),null!==e&&(u=e,e=void(jn.display_name="string"==typeof u?u:u[1].reduce(function(e,t){return e+t[0]+t[1]},u[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=Et()),e}function yt(){var e,t,r,s,l,u;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&a('"q"')),null!==e&&null!==(t=M())&&null!==(r=St())?e=[e,t,r]:(e=null,i=l),null!==e&&(u=e[2],jn.params||(jn.params={}),e=void(jn.params.q=u)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,u;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&a('"expires"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(u=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=u)),null===e&&(i=s),e}function Ct(){var e,t,n;if(n=i,null!==(t=h()))for(e=[];null!==t;)e.push(t),t=h();else e=null;return null!==e&&(e=parseInt(e.join(""))),null===e&&(i=n),e}function St(){var e,t,r,s,l,u,c,f,d;return u=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&a('"0"')),null!==e?(f=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&a('"."')),null!==t&&null!==(r=null!==(r=h())?r:"")&&null!==(s=null!==(s=h())?s:"")&&null!==(l=null!==(l=h())?l:"")?t=[t,r,s,l]:(t=null,i=f),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=c)):(e=null,i=c),null!==e&&(d=u,e=parseFloat(n.substring(i,d))),null===e&&(i=u),e}function Et(){var e,t,n,r,s,o,l,u;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=At())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],u=e[1],jn.params||(jn.params={}),u=void 0===u?void 0:u[1],e=void(jn.params[l.toLowerCase()]=u)),null===e&&(i=r),e}function At(){var e;return null===(e=k())&&null===(e=le())&&(e=Y()),e}function bt(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&a('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&a('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&a('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&a('"alert"')),null===e&&(e=k())))),e}function Rt(){var e;return null===(e=wt())&&(e=Et()),e}function wt(){var e,t,r,s;return s=i,"handling"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&a('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&a('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&a('"required"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s),e}function It(){var e,t,n,r,s,o,l,u;if(l=i,null!==(e=Ot()))if(null!==(t=P()))if(null!==(n=xt())){for(r=[],u=i,null!==(s=G())&&null!==(o=Pt())?s=[s,o]:(s=null,i=u);null!==s;)r.push(s),u=i,null!==(s=G())&&null!==(o=Pt())?s=[s,o]:(s=null,i=u);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&a('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&a('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&a('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&a('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&a('"application"')),null===e&&(e=Dt()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&a('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&a('"multipart"')),null===e&&(e=Dt())),e}function Dt(){var e;return null===(e=k())&&(e=Ut()),e}function Ut(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&a('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function xt(){var e;return null===(e=Dt())&&(e=k()),e}function Pt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=Y()),e}function qt(){var e,t,n,r;if(n=i,null!==(t=h()))for(e=[];null!==t;)e.push(t),t=h();else e=null;return null!==e&&(r=e,e=void(jn.value=parseInt(r.join("")))),null===e&&(i=n),e}function Lt(){var e,t,r,s,l,u;if(l=i,null!==(e=D())){for(t=[],u=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&a('"."')),null!==r&&null!==(s=D())?r=[r,s]:(r=null,i=u);null!==r;)t.push(r),u=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&a('"."')),null!==r&&null!==(s=D())?r=[r,s]:(r=null,i=u);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ht(){var e;return null===(e=Ft())&&(e=Et()),e}function Ft(){var e,t,r,s,l,u;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&a('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(u=e[2],e=void(jn.tag=u)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,u,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&a('"Digest"')),null!==e)if(null!==(t=A()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(u=Vt())?l=[l,u]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(u=Vt())?l=[l,u]:(l=null,i=h);null!==s?e=[e,t,r,s]:(e=null,i=c)}else e=null,i=c;else e=null,i=c;else e=null,i=c;return null===e&&(e=Gt()),e}function Gt(){var e,t,n,r,s,o,l,u;if(l=i,null!==(e=k()))if(null!==(t=A()))if(null!==(n=Wt())){for(r=[],u=i,null!==(s=j())&&null!==(o=Wt())?s=[s,o]:(s=null,i=u);null!==s;)r.push(s),u=i,null!==(s=j())&&null!==(o=Wt())?s=[s,o]:(s=null,i=u);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Wt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=Y()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Bt())&&null===(e=Yt())&&null===(e=Jt())&&null===(e=Xt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Wt()),e}function Bt(){var e,t,r,s;return s=i,"realm"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&a('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Kt())?e=[e,t,r]:(e=null,i=s),e}function Kt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Yt(){var e,t,r,s,l,u,c,h,f;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&a('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],f=i,null!==(c=v()))for(u=[];null!==c;)u.push(c),c=v();else u=null;for(null!==u&&null!==(c=zt())?u=[u,c]:(u=null,i=f);null!==u;){if(l.push(u),f=i,null!==(c=v()))for(u=[];null!==c;)u.push(c),c=v();else u=null;null!==u&&null!==(c=zt())?u=[u,c]:(u=null,i=f)}null!==l&&null!==(u=B())?e=[e,t,r,s,l,u]:(e=null,i=h)}else e=null,i=h;else e=null,i=h;else e=null,i=h;else e=null,i=h;return e}function zt(){var e;return null===(e=Le())&&(e=je()),e}function Jt(){var e,t,r,s;return s=i,"nonce"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&a('"nonce"')),null!==e&&null!==(t=M())&&null!==(r=$t())?e=[e,t,r]:(e=null,i=s),e}function $t(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Xt(){var e,t,r,s,l,u;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&a('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(u=e[2],e=void(jn.opaque=u)),null===e&&(i=s),e}function Qt(){var e,t,r,s,l;return s=i,"stale"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&a('"stale"')),null!==e&&null!==(t=M())?(l=i,"true"===n.substr(i,4).toLowerCase()?(r=n.substr(i,4),i+=4):(r=null,0===o&&a('"true"')),null!==r&&(r=void(jn.stale=!0)),null===r&&(i=l),null===r&&(l=i,"false"===n.substr(i,5).toLowerCase()?(r=n.substr(i,5),i+=5):(r=null,0===o&&a('"false"')),null!==r&&(r=void(jn.stale=!1)),null===r&&(i=l)),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s),e}function Zt(){var e,t,r,s,l,u;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&a('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&a('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&a('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(u=e[2],e=void(jn.algorithm=u.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,u,c,h,f,d;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&a('"qop"')),null!==e)if(null!==(t=M()))if(null!==(r=V())){if(f=i,null!==(s=tn())){for(l=[],d=i,44===n.charCodeAt(i)?(u=",",i++):(u=null,0===o&&a('","')),null!==u&&null!==(c=tn())?u=[u,c]:(u=null,i=d);null!==u;)l.push(u),d=i,44===n.charCodeAt(i)?(u=",",i++):(u=null,0===o&&a('","')),null!==u&&null!==(c=tn())?u=[u,c]:(u=null,i=d);null!==l?s=[s,l]:(s=null,i=f)}else s=null,i=f;null!==s&&null!==(l=B())?e=[e,t,r,s,l]:(e=null,i=h)}else e=null,i=h;else e=null,i=h;else e=null,i=h;return e}function tn(){var e,t,r;return t=i,"auth-int"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&a('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&a('"auth"')),null===e&&(e=k())),null!==e&&(r=e,jn.qop||(jn.qop=[]),e=void jn.qop.push(r.toLowerCase())),null===e&&(i=t),e}function nn(){var e,t,n,r,s,o,l;if(s=i,o=i,null!==(e=mt())){for(t=[],l=i,null!==(n=G())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=G())&&null!==(r=Et())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;return null!==e&&(e=function(e){var t;jn.multi_header||(jn.multi_header=[]);try{t=new Fn(jn.uri,jn.display_name,jn.params),delete jn.uri,delete jn.display_name,delete jn.params}catch(e){t=null}jn.multi_header.push({possition:i,offset:e,parsed:t})}(s)),null===e&&(i=s),e}function rn(){var e;return null===(e=sn())&&(e=Et()),e}function sn(){var e,t,r,s,l,u,c;if(l=i,u=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&a('"cause"')),null!==e)if(null!==(t=M())){if(null!==(s=h()))for(r=[];null!==s;)r.push(s),s=h();else r=null;null!==r?e=[e,t,r]:(e=null,i=u)}else e=null,i=u;else e=null,i=u;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=G())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=G())&&null!==(r=Et())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function ln(){var e,t,r;return t=i,"active"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&a('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&a('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&a('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function un(){var e,t,r,s,l,u,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&a('"reason"')),null!==e&&null!==(t=M())&&null!==(r=an())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(u=e[2])&&(jn.reason=u))),null===e&&(i=s),null===e&&(s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&a('"expires"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(h=e[2])&&(jn.expires=h))),null===e&&(i=s),null===e&&(s=i,l=i,"retry_after"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&a('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(c=e[2])&&(jn.retry_after=c))),null===e&&(i=s),null===e&&(e=Et()))),e}function an(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&a('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&a('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&a('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&a('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&a('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&a('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&a('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=Et()),e}function hn(){var e,t,n,r,s,o,l,u;if(l=i,null!==(e=yn()))if(null!==(t=A()))if(null!==(n=Sn())){for(r=[],u=i,null!==(s=G())&&null!==(o=fn())?s=[s,o]:(s=null,i=u);null!==s;)r.push(s),u=i,null!==(s=G())&&null!==(o=fn())?s=[s,o]:(s=null,i=u);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function fn(){var e;return null===(e=dn())&&null===(e=_n())&&null===(e=pn())&&null===(e=mn())&&null===(e=vn())&&(e=Et()),e}function dn(){var e,t,r,s,l,u;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&a('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=bn())?e=[e,t,r]:(e=null,i=l),null!==e&&(u=e[2],e=void(jn.ttl=u)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,u;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&a('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(u=e[2],e=void(jn.maddr=u)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,u;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&a('"received"')),null!==e&&null!==(t=M())?(null===(r=pe())&&(r=fe()),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(u=e[2],e=void(jn.received=u)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,u;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&a('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(u=e[2],e=void(jn.branch=u)),null===e&&(i=s),e}function vn(){var e,t,r,s,l;return s=i,"rport"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&a('"rport"')),null!==e?(l=i,null!==(t=M())&&null!==(r=gn())?t=[t,r]:(t=null,i=l),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),e}function gn(){var e,t,n,r,s,o,l,u;return o=i,l=i,null!==(e=null!==(e=h())?e:"")&&null!==(t=null!==(t=h())?t:"")&&null!==(n=null!==(n=h())?n:"")&&null!==(r=null!==(r=h())?r:"")&&null!==(s=null!==(s=h())?s:"")?e=[e,t,n,r,s]:(e=null,i=l),null!==e&&(u=e,e=void(jn.rport=parseInt(u.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=P())&&null!==(n=k())&&null!==(r=P())&&null!==(s=Cn())?e=[e,t,n,r,s]:(e=null,i=o),e}function Tn(){var e,t,r;return t=i,"sip"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&a('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Cn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&a('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&a('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&a('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&a('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function Sn(){var e,t,n,r,s;return r=i,null!==(e=En())?(s=i,null!==(t=W())&&null!==(n=An())?t=[t,n]:(t=null,i=s),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function En(){var e,t,r;return t=i,null===(e=pe())&&null===(e=he())&&(e=ue()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function An(){var e,t,n,r,s,o,l,u;return o=i,l=i,null!==(e=null!==(e=h())?e:"")&&null!==(t=null!==(t=h())?t:"")&&null!==(n=null!==(n=h())?n:"")&&null!==(r=null!==(r=h())?r:"")&&null!==(s=null!==(s=h())?s:"")?e=[e,t,n,r,s]:(e=null,i=l),null!==e&&(u=e,e=void(jn.port=parseInt(u.join("")))),null===e&&(i=o),e}function bn(){var e,t,n,r,s;return r=i,s=i,null!==(e=h())&&null!==(t=null!==(t=h())?t:"")&&null!==(n=null!==(n=h())?n:"")?e=[e,t,n]:(e=null,i=s),null!==e&&(e=parseInt(e.join(""))),null===e&&(i=r),e}function Rn(){var e,t,n;return t=i,null!==(e=Ct())&&(n=e,e=void(jn.expires=n)),null===e&&(i=t),e}function wn(){var e;return null===(e=In())&&(e=Et()),e}function In(){var e,t,r,s,l,u;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&a('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&a('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&a('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(u=e[2],e=void(jn.refresher=u.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=A());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=A());return e}function Nn(){var e,t,r,s,l,u,c,h,f,d,_,p;return d=i,_=i,null!==(e=Dn())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&a('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&a('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(u="-",i++):(u=null,0===o&&a('"-"')),null!==u&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&a('"-"')),null!==h&&null!==(f=Un())?e=[e,t,r,s,l,u,c,h,f]:(e=null,i=_)):(e=null,i=_)):(e=null,i=_)):(e=null,i=_)):(e=null,i=_),null!==e&&(p=d,e[0],e=void(jn=n.substring(i+5,p))),null===e&&(i=d),e}function kn(){var e,t,n,r,s;return s=i,null!==(e=d())&&null!==(t=d())&&null!==(n=d())&&null!==(r=d())?e=[e,t,n,r]:(e=null,i=s),e}function Dn(){var e,t,n;return n=i,null!==(e=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function Un(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function xn(){var e,t,r,s,l,u,c;return s=i,l=i,null!==(e=U())?(u=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&a('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=u),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=l)):(e=null,i=l),null!==e&&(c=s,e=void(jn.call_id=n.substring(i,c))),null===e&&(i=s),e}function Pn(){var e;return null===(e=Mn())&&null===(e=qn())&&null===(e=Ln())&&(e=Et()),e}function Mn(){var e,t,r,s,l,u;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&a('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(u=e[2],e=void(jn.to_tag=u)),null===e&&(i=s),e}function qn(){var e,t,r,s,l,u;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&a('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(u=e[2],e=void(jn.from_tag=u)),null===e&&(i=s),e}function Ln(){var e,t;return t=i,"early-only"===n.substr(i,10)?(e="early-only",i+=10):(e=null,0===o&&a('"early-only"')),null!==e&&(e=void(jn.early_only=!0)),null===e&&(i=t),e}var Hn=e("./URI"),Fn=e("./NameAddrHeader"),jn={};if(null===s[r]()||i!==n.length){var Gn=Math.max(i,l),Wn=Gn2&&void 0!==arguments[2]?arguments[2]:{},s=e;if(void 0===e||void 0===t)throw new TypeError("Not enough arguments");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(s));var i=h.cloneArray(r.extraHeaders),o=h.cloneObject(r.eventHandlers),l=r.contentType||"text/plain";for(var u in o)Object.prototype.hasOwnProperty.call(o,u)&&this.on(u,o[u]);i.push("Content-Type: ".concat(l)),this._request=new c.OutgoingRequest(a.MESSAGE,e,this._ua,null,i),t&&(this._request.body=t);var d=new f(this._ua,this._request,{onRequestTimeout:function(){n._onRequestTimeout()},onTransportError:function(){n._onTransportError()},onReceiveResponse:function(e){n._receiveResponse(e)}});this._newMessage("local",this._request),d.send()}},{key:"init_incoming",value:function(e){this._request=e,this._newMessage("remote",e),this._is_replied||(this._is_replied=!0,e.reply(200)),this._close()}},{key:"accept",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=h.cloneArray(e.extraHeaders),n=e.body;if("incoming"!==this._direction)throw new d.NotSupportedError('"accept" not supported for outgoing Message');if(this._is_replied)throw new Error("incoming Message already replied");this._is_replied=!0,this._request.reply(200,null,t,n)}},{key:"reject",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.status_code||480,n=e.reason_phrase,r=h.cloneArray(e.extraHeaders),s=e.body;if("incoming"!==this._direction)throw new d.NotSupportedError('"reject" not supported for outgoing Message');if(this._is_replied)throw new Error("incoming Message already replied");if(t<300||t>=700)throw new TypeError("Invalid status_code: ".concat(t));this._is_replied=!0,this._request.reply(t,n,r,s)}},{key:"_receiveResponse",value:function(e){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(e.status_code):break;case/^2[0-9]{2}$/.test(e.status_code):this._succeeded("remote",e);break;default:var t=h.sipErrorCause(e.status_code);this._failed("remote",e,t)}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,a.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,a.causes.CONNECTION_ERROR)}},{key:"_close",value:function(){this._closed=!0,this._ua.destroyMessage(this)}},{key:"_newMessage",value:function(e,t){"remote"===e?(this._direction="incoming",this._local_identity=t.to,this._remote_identity=t.from):"local"===e&&(this._direction="outgoing",this._local_identity=t.from,this._remote_identity=t.to),this._ua.newMessage(this,{originator:e,message:this,request:t})}},{key:"_failed",value:function(e,t,n){_("MESSAGE failed"),this._close(),_('emit "failed"'),this.emit("failed",{originator:e,response:t||null,cause:n})}},{key:"_succeeded",value:function(e,t){_("MESSAGE succeeded"),this._close(),_('emit "succeeded"'),this.emit("succeeded",{originator:e,response:t})}},{key:"direction",get:function(){return this._direction}},{key:"local_identity",get:function(){return this._local_identity}},{key:"remote_identity",get:function(){return this._remote_identity}}])&&s(t.prototype,n),r&&s(t,r),p}()},{"./Constants":2,"./Exceptions":6,"./RequestSender":18,"./SIPMessage":19,"./Utils":26,debug:30,events:29}],10:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}},{key:"uri",get:function(){return this._uri}},{key:"display_name",get:function(){return this._display_name},set:function(e){this._display_name=0===e?"0":e}}]),e}()},{"./Grammar":7,"./URI":25}],11:[function(e,t,n){"use strict";function r(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return s(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return s(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,l=!0,u=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return l=e.done,e},e:function(e){u=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(u)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:s}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,l=!0,u=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return l=e.done,e},e:function(e){u=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(u)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;R("connect()");var r=e,s=m.cloneObject(t.eventHandlers),i=m.cloneArray(t.extraHeaders),o=m.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,u=m.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==I.STATUS_NULL)throw new _.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new _.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&m.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=d.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=d.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=m.newTag();var f=t.anonymous||!1,p={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:f,outbound:!0}),f?(p.from_display_name="Anonymous",p.from_uri=new b("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(p.from_uri=new b("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(p.from_display_name=t.fromDisplayName),i.push("Contact: ".concat(this._contact)),i.push("Content-Type: application/sdp"),this._sessionTimers.enabled&&i.push("Session-Expires: ".concat(this._sessionTimers.defaultExpires).concat(this._ua.configuration.session_timers_force_refresher?";refresher=uac":"")),this._request=new g.InitialOutgoingInviteRequest(e,this._ua,p,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(u,a),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;R("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=I.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=m.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=I.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,d.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===I.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,d.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==I.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};R("answer()");var n=this._request,r=m.cloneArray(t.extraHeaders),i=m.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=m.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,a=t.rtcAnswerConstraints||null,c=m.cloneObject(t.rtcOfferConstraints),h=!1,f=!1,p=!1,v=!1;if(this._rtcAnswerConstraints=a,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new _.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==I.STATUS_WAITING_FOR_ANSWER)throw new _.InvalidStateError(this._status);if(this._sessionTimers.enabled&&m.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=d.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=d.SESSION_EXPIRES),this._status=I.STATUS_ANSWERED,this._createDialog(n,"UAS")){clearTimeout(this._timers.userNoAnswerTimer),r.unshift("Contact: ".concat(this._contact));var g=n.parseSDP();Array.isArray(g.media)||(g.media=[g.media]);var y,T=s(g.media);try{for(T.s();!(y=T.n()).done;){var C=y.value;"audio"===C.type&&(h=!0,C.direction&&"sendrecv"!==C.direction||(p=!0)),"video"===C.type&&(f=!0,C.direction&&"sendrecv"!==C.direction||(v=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var S,E=s(o.getAudioTracks());try{for(E.s();!(S=E.n()).done;){var A=S.value;o.removeTrack(A)}}catch(e){E.e(e)}finally{E.f()}}if(o&&!1===i.video){var b,O=s(o.getVideoTracks());try{for(O.s();!(b=O.n()).done;){var N=b.value;o.removeTrack(N)}}catch(e){O.e(e)}finally{O.f()}}o||void 0!==i.audio||(i.audio=p),o||void 0!==i.video||(i.video=v),o||h||c.offerToReceiveAudio||(i.audio=!1),o||f||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,u),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===I.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,d.causes.USER_DENIED_MEDIA_ACCESS),w('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===I.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};R('emit "sdp"'),e.emit("sdp",t);var r=new RTCSessionDescription({type:"offer",sdp:t.sdp});return e._connectionPromiseQueue=e._connectionPromiseQueue.then(function(){return e._connection.setRemoteDescription(r)}).catch(function(t){throw n.reply(488),e._failed("system",null,d.causes.WEBRTC_ERROR),w('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===I.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",a).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===I.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=I.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,d.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==I.STATUS_TERMINATED&&w(t)})}else n.reply(500,"Error creating dialog")}},{key:"terminate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};R("terminate()");var n,r=t.cause||d.causes.BYE,s=m.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===I.STATUS_TERMINATED)throw new _.InvalidStateError(this._status);switch(this._status){case I.STATUS_NULL:case I.STATUS_INVITE_SENT:case I.STATUS_1XX_RECEIVED:if(R("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||d.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===I.STATUS_NULL||this._status===I.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===I.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=I.STATUS_CANCELED,this._failed("local",null,d.causes.CANCELED);break;case I.STATUS_WAITING_FOR_ANSWER:case I.STATUS_ANSWERED:if(R("rejecting session"),(o=o||480)<300||o>=700)throw new TypeError("Invalid status_code: ".concat(o));this._request.reply(o,l,s,i),this._failed("local",null,d.causes.REJECTED);break;case I.STATUS_WAITING_FOR_ACK:case I.STATUS_CONFIRMED:if(R("terminating session"),l=t.reason_phrase||d.REASON_PHRASE[o]||"",o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));if(o&&s.push("Reason: SIP ;cause=".concat(o,'; text="').concat(l,'"')),this._status===I.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==p.C.STATUS_TERMINATED){var u=this._dialog;this.receiveRequest=function(t){t.method===d.ACK&&(e.sendRequest(d.BYE,{extraHeaders:s,body:i}),u.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===p.C.STATUS_TERMINATED&&(e.sendRequest(d.BYE,{extraHeaders:s,body:i}),u.terminate())}),this._ended("local",null,r),this._dialog=u,this._ua.newDialog(u)}else this.sendRequest(d.BYE,{extraHeaders:s,body:i}),this._ended("local",null,r)}}},{key:"sendDTMF",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};R("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||d.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==I.STATUS_CONFIRMED&&this._status!==I.STATUS_WAITING_FOR_ACK)throw new _.InvalidStateError(this._status);if(i!==d.DTMF_TRANSPORT.INFO&&i!==d.DTMF_TRANSPORT.RFC2833)throw new TypeError("invalid transportType: ".concat(i));if("number"==typeof e&&(e=e.toString()),!e||"string"!=typeof e||!e.match(/^[0-9A-DR#*,]+$/i))throw new TypeError("Invalid tones: ".concat(e));if(r&&!m.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rC.C.MAX_DURATION?(R('"duration" value is greater than the maximum allowed, setting it to '.concat(C.C.MAX_DURATION," milliseconds")),r=C.C.MAX_DURATION):r=Math.abs(r):r=C.C.DEFAULT_DURATION,t.duration=r,s&&!m.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var u=new C(this);t.eventHandlers={onFailed:function(){i._tones=null}},u.send(l,t),o=r+s}setTimeout(e.bind(this),o)}.call(this));else{var o=this._getDTMFRTPSender();o&&(e=o.toneBuffer+e,o.insertDTMF(e,r,s))}}},{key:"sendInfo",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(R("sendInfo()"),this._status!==I.STATUS_CONFIRMED&&this._status!==I.STATUS_WAITING_FOR_ACK)throw new _.InvalidStateError(this._status);new S(this).send(e,t,n)}},{key:"mute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!1};R("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};R("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(R("hold()"),this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:d.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(R("unhold()"),this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:d.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;R("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:d.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Media Renegotiation Failed"})}};return this._setLocalMediaStatus(),t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:s,rtcOfferConstraints:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:s,rtcOfferConstraints:r,extraHeaders:t.extraHeaders}),!0}},{key:"refer",value:function(e,t){var n=this;R("refer()");var r=e;if(this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new A(this);s.sendRefer(e,t);var i=s.id;return this._referSubscribers[i]=s,s.on("requestFailed",function(){delete n._referSubscribers[i]}),s.on("accepted",function(){delete n._referSubscribers[i]}),s.on("failed",function(){delete n._referSubscribers[i]}),s}},{key:"sendRequest",value:function(e,t){return R("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(R("receiveRequest()"),e.method===d.CANCEL)this._status!==I.STATUS_WAITING_FOR_ANSWER&&this._status!==I.STATUS_ANSWERED||(this._status=I.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,d.causes.CANCELED));else switch(e.method){case d.ACK:if(this._status!==I.STATUS_WAITING_FOR_ACK)return;if(this._status=I.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:d.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};R('emit "sdp"'),this.emit("sdp",n);var r=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._connection.setRemoteDescription(r)}).then(function(){t._is_confirmed||t._confirmed("remote",e)}).catch(function(e){t.terminate({cause:d.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),w('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case d.BYE:this._status===I.STATUS_CONFIRMED||this._status===I.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,d.causes.BYE)):this._status===I.STATUS_INVITE_RECEIVED||this._status===I.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,d.causes.BYE)):e.reply(403,"Wrong Status");break;case d.INVITE:this._status===I.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case d.INFO:if(this._status===I.STATUS_1XX_RECEIVED||this._status===I.STATUS_WAITING_FOR_ANSWER||this._status===I.STATUS_ANSWERED||this._status===I.STATUS_WAITING_FOR_ACK||this._status===I.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new C(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case d.UPDATE:this._status===I.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case d.REFER:this._status===I.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case d.NOTIFY:this._status===I.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){w("onTransportError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:d.causes.CONNECTION_ERROR,cause:d.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){w("onRequestTimeout()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:d.causes.REQUEST_TIMEOUT,cause:d.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){w("onDialogError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:d.causes.DIALOG_ERROR,cause:d.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){R("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){R("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(R("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(R("_isReadyToReOffer() | session not established yet"),!1):(R("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(R("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(R("close() | closing local MediaStream"),m.closeMediaStream(this._localMediaStream)),this._status!==I.STATUS_TERMINATED){if(this._status=I.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){w("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=v.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===I.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),nv.T2&&(n=v.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===I.STATUS_WAITING_FOR_ACK&&(R("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(d.BYE),e._ended("remote",null,d.causes.NO_ACK))},v.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:d.causes.RTP_TIMEOUT,status_code:408,reason_phrase:d.causes.RTP_TIMEOUT})}),R('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(R("createLocalDescription()"),"offer"!==e&&"answer"!==e)throw new Error('createLocalDescription() | invalid type "'.concat(e,'"'));var r=this._connection;return this._rtcReady=!1,Promise.resolve().then(function(){return"offer"===e?r.createOffer(t).catch(function(e){return w('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return w('emit "peerconnection:createanswerfailed" [error:%o]',e),n.emit("peerconnection:createanswerfailed",e),Promise.reject(e)})}).then(function(e){return r.setLocalDescription(e).catch(function(e){return n._rtcReady=!0,w('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',e),n.emit("peerconnection:setlocaldescriptionfailed",e),Promise.reject(e)})}).then(function(){if(!("complete"!==r.iceGatheringState||t&&t.iceRestart)){n._rtcReady=!0;var s={originator:"local",type:e,sdp:r.localDescription.sdp};return R('emit "sdp"'),n.emit("sdp",s),Promise.resolve(s.sdp)}return new Promise(function(t){var s,i,o=!1,l=function(){r.removeEventListener("icecandidate",s),r.removeEventListener("icegatheringstatechange",i),o=!0,n._rtcReady=!0;var l={originator:"local",type:e,sdp:r.localDescription.sdp};R('emit "sdp"'),n.emit("sdp",l),t(l.sdp)};r.addEventListener("icecandidate",s=function(e){var t=e.candidate;t?n.emit("icecandidate",{candidate:t,ready:l}):o||l()}),r.addEventListener("icegatheringstatechange",i=function(){"complete"!==r.iceGatheringState||o||l()})})})}},{key:"_createDialog",value:function(e,t,n){var r="UAS"===t?e.to_tag:e.from_tag,s="UAS"===t?e.from_tag:e.to_tag,i=e.call_id+r+s,o=this._earlyDialogs[i];if(n)return!!o||((o=new y(this,e,t,y.C.STATUS_EARLY)).error?(R(o.error),this._failed("remote",e,d.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[i]=o,!0));if(this._from_tag=e.from_tag,this._to_tag=e.to_tag,o)return o.update(e,t),this._dialog=o,delete this._earlyDialogs[i],!0;var l=new y(this,e,t);return l.error?(R(l.error),this._failed("remote",e,d.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;R("receiveReinvite()");var n=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0,r={request:e,callback:void 0,reject:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};s=!0;var n=t.status_code||403,r=t.reason_phrase||"",i=m.cloneArray(t.extraHeaders);if(this._status!==I.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("reinvite",r),!s){if(this._late_sdp=!1,!e.body)return this._late_sdp=!0,this._remoteHold&&(this._remoteHold=!1,this._onunhold("remote")),void(this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._createLocalDescription("offer",t._rtcOfferConstraints)}).then(function(e){i.call(t,e)}).catch(function(){e.reply(500)}));if("application/sdp"!==n)return R("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==I.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){w(e)})}function i(t){var n=this,s=["Contact: ".concat(this._contact)];this._handleSessionTimersInIncomingRequest(e,s),this._late_sdp&&(t=this._mangleOffer(t)),e.reply(200,null,s,t,function(){n._status=I.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;R("receiveUpdate()");var n=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0,r={request:e,callback:void 0,reject:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};s=!0;var n=t.status_code||403,r=t.reason_phrase||"",i=m.cloneArray(t.extraHeaders);if(this._status!==I.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return R("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==I.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){w(e)})}else i.call(this,null);function i(t){var n=["Contact: ".concat(this._contact)];this._handleSessionTimersInIncomingRequest(e,n),e.reply(200,null,n,t),"function"==typeof r.callback&&r.callback()}}},{key:"_processInDialogSdpOffer",value:function(e){var t=this;R("_processInDialogSdpOffer()");var n,r=e.parseSDP(),i=!1,o=s(r.media);try{for(o.s();!(n=o.n()).done;){var l=n.value;if(-1!==O.indexOf(l.type)){var u=l.direction||r.direction||"sendrecv";if("sendonly"!==u&&"inactive"!==u){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var a={originator:"remote",type:"offer",sdp:e.body};R('emit "sdp"'),this.emit("sdp",a);var c=new RTCSessionDescription({type:"offer",sdp:a.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===I.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),w('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===I.STATUS_TERMINATED)throw new Error("terminated");!0===t._remoteHold&&!1===i?(t._remoteHold=!1,t._onunhold("remote")):!1===t._remoteHold&&!0===i&&(t._remoteHold=!0,t._onhold("remote"))}).then(function(){if(t._status===I.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),w('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){w("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(R("receiveRefer()"),!e.refer_to)return R("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==d.SIP)return R("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var r=new E(this,e.cseq);R('emit "refer"'),this.emit("refer",{request:e,accept:function(s,i){(function(t){var s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;var i=new n(this._ua);if(i.on("progress",function(e){var t=e.response;r.notify(t.status_code,t.reason_phrase)}),i.on("accepted",function(e){var t=e.response;r.notify(t.status_code,t.reason_phrase)}),i.on("_failed",function(e){var t=e.message,n=e.cause;t?r.notify(t.status_code,t.reason_phrase):r.notify(487,n)}),e.refer_to.uri.hasHeader("replaces")){var o=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));s.extraHeaders=m.cloneArray(s.extraHeaders),s.extraHeaders.push("Replaces: ".concat(o))}i.connect(e.refer_to.uri.toAor(),s,t)}).call(t,s,i)},reject:function(){(function(){r.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(R("receiveNotify()"),e.event||e.reply(400),e.event.event){case"refer":var t,n;if(e.event.params&&e.event.params.id)t=e.event.params.id,n=this._referSubscribers[t];else{if(1!==Object.keys(this._referSubscribers).length)return void e.reply(400,"Missing event id parameter");n=this._referSubscribers[Object.keys(this._referSubscribers)[0]]}if(!n)return void e.reply(481,"Subscription does not exist");n.receiveNotify(e),e.reply(200);break;default:e.reply(489)}}},{key:"_receiveReplaces",value:function(e){var t=this;R("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(r){(function(t){var r=this;if(this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;var s=new n(this._ua);s.on("confirmed",function(){r.terminate()}),s.init_incoming(e,t)}).call(t,r)},reject:function(){(function(){R("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new T(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===I.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,d.causes.USER_DENIED_MEDIA_ACCESS),w('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===I.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,d.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===I.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=I.STATUS_INVITE_SENT,R('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==I.STATUS_TERMINATED&&w(e)})}},{key:"_getDTMFRTPSender",value:function(){var e=this._connection.getSenders().find(function(e){return e.track&&"audio"===e.track.kind});if(e&&e.dtmf)return e.dtmf;w("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(R("receiveInviteResponse()"),this._dialog&&e.status_code>=200&&e.status_code<=299){if(this._dialog.id.call_id===e.call_id&&this._dialog.id.local_tag===e.from_tag&&this._dialog.id.remote_tag===e.to_tag)return void this.sendRequest(d.ACK);var n=new y(this,e,"UAC");return void 0!==n.error?void R(n.error):(this.sendRequest(d.ACK),void this.sendRequest(d.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===I.STATUS_INVITE_SENT||this._status===I.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=I.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){R("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=I.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};R('emit "sdp"'),this.emit("sdp",r);var s=new RTCSessionDescription({type:"answer",sdp:r.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._connection.setRemoteDescription(s)}).then(function(){return t._progress("remote",e)}).catch(function(e){w('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=I.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,d.causes.MISSING_SDP),this._failed("remote",e,d.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};R('emit "sdp"'),this.emit("sdp",i);var o=new RTCSessionDescription({type:"answer",sdp:i.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if("stable"===t._connection.signalingState)return t._connection.createOffer(t._rtcOfferConstraints).then(function(e){return t._connection.setLocalDescription(e)}).catch(function(n){t._acceptAndTerminate(e,500,n.toString()),t._failed("local",e,d.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(d.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,d.causes.BAD_MEDIA_DESCRIPTION),w('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=m.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};R("sendReinvite()");var n=m.cloneArray(t.extraHeaders),r=m.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=!1;function o(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),n.push("Content-Type: application/sdp"),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return e._createLocalDescription("offer",s)}).then(function(t){var s={originator:"local",type:"offer",sdp:t=e._mangleOffer(t)};R('emit "sdp"'),e.emit("sdp",s),e.sendRequest(d.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===I.STATUS_TERMINATED)return;if(this.sendRequest(d.ACK),i)return;if(this._handleSessionTimersInIncomingResponse(e),!e.body)return void o.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void o.call(this);var n={originator:"remote",type:"answer",sdp:e.body};R('emit "sdp"'),this.emit("sdp",n);var s=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._connection.setRemoteDescription(s)}).then(function(){r.succeeded&&r.succeeded(e)}).catch(function(e){o.call(t),w('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}).call(e,t),i=!0},onErrorResponse:function(t){o.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){o()})}},{key:"_sendUpdate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};R("sendUpdate()");var n=m.cloneArray(t.extraHeaders),r=m.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==I.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void u.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void u.call(this);var n={originator:"remote",type:"answer",sdp:e.body};R('emit "sdp"'),this.emit("sdp",n);var s=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._connection.setRemoteDescription(s)}).then(function(){r.succeeded&&r.succeeded(e)}).catch(function(e){u.call(t),w('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function u(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),i?(n.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return e._createLocalDescription("offer",s)}).then(function(t){var r={originator:"local",type:"offer",sdp:t=e._mangleOffer(t)};R('emit "sdp"'),e.emit("sdp",r),e.sendRequest(d.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){u.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){u.call(e)})):this.sendRequest(d.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){u.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){R("acceptAndTerminate()");var r=[];t&&(n=n||d.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(d.ACK),this.sendRequest(d.BYE,{extraHeaders:r})),this._status=I.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=f.parse(e),this._localHold&&!this._remoteHold){R("mangleOffer() | me on hold, mangling offer");var t,n=s(e.media);try{for(n.s();!(t=n.n()).done;){var r=t.value;-1!==O.indexOf(r.type)&&(r.direction?"sendrecv"===r.direction?r.direction="sendonly":"recvonly"===r.direction&&(r.direction="inactive"):r.direction="sendonly")}}catch(e){n.e(e)}finally{n.f()}}else if(this._localHold&&this._remoteHold){R("mangleOffer() | both on hold, mangling offer");var i,o=s(e.media);try{for(o.s();!(i=o.n()).done;){var l=i.value;-1!==O.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){R("mangleOffer() | remote on hold, mangling offer");var u,a=s(e.media);try{for(a.s();!(u=a.n()).done;){var c=u.value;-1!==O.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){a.e(e)}finally{a.f()}}return f.write(e)}},{key:"_setLocalMediaStatus",value:function(){var e=!0,t=!0;(this._localHold||this._remoteHold)&&(e=!1,t=!1),this._audioMuted&&(e=!1),this._videoMuted&&(t=!1),this._toggleMuteAudio(!e),this._toggleMuteVideo(!t)}},{key:"_handleSessionTimersInIncomingRequest",value:function(e,t){var n;this._sessionTimers.enabled&&(e.session_expires&&e.session_expires>=d.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,n=e.session_expires_refresher||"uas"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,n="uas"),t.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(n)),this._sessionTimers.refresher="uas"===n,this._runSessionTimer())}},{key:"_handleSessionTimersInIncomingResponse",value:function(e){var t;this._sessionTimers.enabled&&(e.session_expires&&e.session_expires>=d.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==I.STATUS_TERMINATED&&(R("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===d.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==I.STATUS_TERMINATED&&(w("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:d.causes.REQUEST_TIMEOUT,status_code:408,reason_phrase:"Session Timer Expired"}))},1100*t)}},{key:"_toggleMuteAudio",value:function(e){var t,n=s(this._connection.getSenders().filter(function(e){return e.track&&"audio"===e.track.kind}));try{for(n.s();!(t=n.n()).done;){t.value.track.enabled=!e}}catch(e){n.e(e)}finally{n.f()}}},{key:"_toggleMuteVideo",value:function(e){var t,n=s(this._connection.getSenders().filter(function(e){return e.track&&"video"===e.track.kind}));try{for(n.s();!(t=n.n()).done;){t.value.track.enabled=!e}}catch(e){n.e(e)}finally{n.f()}}},{key:"_newRTCSession",value:function(e,t){R("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){R("session connecting"),R('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){R("session progress"),R('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){R("session accepted"),this._start_time=new Date,R('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){R("session confirmed"),this._is_confirmed=!0,R('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){R("session ended"),this._end_time=new Date,this._close(),R('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){R("session failed"),R('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),R('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){R("session onhold"),this._setLocalMediaStatus(),R('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){R("session onunhold"),this._setLocalMediaStatus(),R('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;R("session onmute"),this._setLocalMediaStatus(),R('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;R("session onunmute"),this._setLocalMediaStatus(),R('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}},{key:"C",get:function(){return I}},{key:"causes",get:function(){return d.causes}},{key:"id",get:function(){return this._id}},{key:"connection",get:function(){return this._connection}},{key:"contact",get:function(){return this._contact}},{key:"direction",get:function(){return this._direction}},{key:"local_identity",get:function(){return this._local_identity}},{key:"remote_identity",get:function(){return this._remote_identity}},{key:"start_time",get:function(){return this._start_time}},{key:"end_time",get:function(){return this._end_time}},{key:"data",get:function(){return this._data},set:function(e){this._data=e}},{key:"status",get:function(){return this._status}}]),n}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":13,"./RTCSession/Info":14,"./RTCSession/ReferNotifier":15,"./RTCSession/ReferSubscriber":16,"./RequestSender":18,"./SIPMessage":19,"./Timers":21,"./Transactions":22,"./URI":25,"./Utils":26,debug:30,events:29,"sdp-transform":35}],13:[function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function s(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:{};if(void 0===e)throw new TypeError("Not enough arguments");if(this._direction="outgoing",this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);var r=h.cloneArray(n.extraHeaders);if(this.eventHandlers=h.cloneObject(n.eventHandlers),"string"==typeof e)e=e.toUpperCase();else{if("number"!=typeof e)throw new TypeError("Invalid tone: ".concat(e));e=e.toString()}if(!e.match(/^[0-9A-DR#*]$/))throw new TypeError("Invalid tone: ".concat(e));this._tone=e,this._duration=n.duration,r.push("Content-Type: application/dtmf-relay");var s="Signal=".concat(this._tone,"\r\n");s+="Duration=".concat(this._duration),this._session.newDTMF({originator:"local",dtmf:this,request:this._request}),this._session.sendRequest(a.INFO,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t.emit("succeeded",{originator:"remote",response:e})},onErrorResponse:function(e){t.eventHandlers.onFailed&&t.eventHandlers.onFailed(),t.emit("failed",{originator:"remote",response:e})},onRequestTimeout:function(){t._session.onRequestTimeout()},onTransportError:function(){t._session.onTransportError()},onDialogError:function(){t._session.onDialogError()}},body:s})}},{key:"init_incoming",value:function(e){var t=/^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*/,n=/^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*/;if(this._direction="incoming",this._request=e,e.reply(200),e.body){var r=e.body.split("\n");r.length>=1&&t.test(r[0])&&(this._tone=r[0].replace(t,"$2")),r.length>=2&&n.test(r[1])&&(this._duration=parseInt(r[1].replace(n,"$2"),10))}this._duration||(this._duration=d.DEFAULT_DURATION),this._tone?this._session.newDTMF({originator:"remote",dtmf:this,request:e}):f("invalid INFO DTMF received, discarded")}},{key:"tone",get:function(){return this._tone}},{key:"duration",get:function(){return this._duration}}])&&s(t.prototype,n),r&&s(t,r),_}(),t.exports.C=d},{"../Constants":2,"../Exceptions":6,"../Utils":26,debug:30,events:29}],14:[function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function s(e,t){for(var n=0;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(a.INFO,{extraHeaders:s,eventHandlers:{onSuccessResponse:function(e){n.emit("succeeded",{originator:"remote",response:e})},onErrorResponse:function(e){n.emit("failed",{originator:"remote",response:e})},onTransportError:function(){n._session.onTransportError()},onRequestTimeout:function(){n._session.onRequestTimeout()},onDialogError:function(){n._session.onDialogError()}},body:t})}},{key:"init_incoming",value:function(e){this._direction="incoming",this.request=e,e.reply(200),this._contentType=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0,this._body=e.body,this._session.newInfo({originator:"remote",info:this,request:e})}},{key:"contentType",get:function(){return this._contentType}},{key:"body",get:function(){return this._body}}])&&s(t.prototype,n),r&&s(t,r),f}()},{"../Constants":2,"../Exceptions":6,"../Utils":26,debug:30,events:29}],15:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),this._session.sendRequest(s.NOTIFY,{extraHeaders:["Event: ".concat(o.event_type,";id=").concat(this._id),"Subscription-State: ".concat(n),"Content-Type: ".concat(o.body_type)],body:"SIP/2.0 ".concat(e," ").concat(t),eventHandlers:{onErrorResponse:function(){this._active=!1}}}))}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"../Constants":2,debug:30}],16:[function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function s(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:{};f("sendRefer()");var r=h.cloneArray(n.extraHeaders),s=h.cloneObject(n.eventHandlers);for(var i in s)Object.prototype.hasOwnProperty.call(s,i)&&this.on(i,s[i]);var o=null;n.replaces&&(o=n.replaces._request.call_id,o+=";to-tag=".concat(n.replaces._to_tag),o+=";from-tag=".concat(n.replaces._from_tag),o=encodeURIComponent(o));var l="Refer-To: <".concat(e).concat(o?"?Replaces=".concat(o):"",">");r.push(l);var u="Referred-By: <".concat(this._session._ua._configuration.uri._scheme,":").concat(this._session._ua._configuration.uri._user,"@").concat(this._session._ua._configuration.uri._host,">");r.push(u),r.push("Contact: ".concat(this._session.contact));var c=this._session.sendRequest(a.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,a.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,a.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,a.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,a.causes.DIALOG_ERROR)}}});this._id=c.cseq}},{key:"receiveNotify",value:function(e){if(f("receiveNotify()"),e.body){var t=c.parse(e.body.trim(),"Status_Line");if(-1!==t)switch(!0){case/^100$/.test(t.status_code):this.emit("trying",{request:e,status_line:t});break;case/^1[0-9]{2}$/.test(t.status_code):this.emit("progress",{request:e,status_line:t});break;case/^2[0-9]{2}$/.test(t.status_code):this.emit("accepted",{request:e,status_line:t});break;default:this.emit("failed",{request:e,status_line:t})}else f('receiveNotify() | error parsing NOTIFY body: "'.concat(e.body,'"'))}}},{key:"_requestSucceeded",value:function(e){f("REFER succeeded"),f('emit "requestSucceeded"'),this.emit("requestSucceeded",{response:e})}},{key:"_requestFailed",value:function(e,t){f("REFER failed"),f('emit "requestFailed"'),this.emit("requestFailed",{response:e||null,cause:t})}},{key:"id",get:function(){return this._id}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Grammar":7,"../Utils":26,debug:30,events:29}],17:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,a;return t=e,(n=[{key:"setExtraHeaders",value:function(e){Array.isArray(e)||(e=[]),this._extraHeaders=e.slice()}},{key:"setExtraContactParams",value:function(e){for(var t in e instanceof Object||(e={}),this._extraContactParams="",e)if(Object.prototype.hasOwnProperty.call(e,t)){var n=e[t];this._extraContactParams+=";".concat(t),n&&(this._extraContactParams+="=".concat(n))}}},{key:"register",value:function(){var e=this;if(this._registering)u("Register request in progress...");else{var t=this._extraHeaders.slice();t.push("Contact: ".concat(this._contact,";expires=").concat(this._expires).concat(this._extraContactParams)),t.push("Expires: ".concat(this._expires));var n=new o.OutgoingRequest(i.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},t),r=new l(this._ua,n,{onRequestTimeout:function(){e._registrationFailure(null,i.causes.REQUEST_TIMEOUT)},onTransportError:function(){e._registrationFailure(null,i.causes.CONNECTION_ERROR)},onAuthenticated:function(){e._cseq+=1},onReceiveResponse:function(t){if(t.cseq===e._cseq)switch(null!==e._registrationTimer&&(clearTimeout(e._registrationTimer),e._registrationTimer=null),!0){case/^1[0-9]{2}$/.test(t.status_code):break;case/^2[0-9]{2}$/.test(t.status_code):if(e._registering=!1,!t.hasHeader("Contact")){u("no Contact header in response to REGISTER, response ignored");break}var n=t.headers.Contact.reduce(function(e,t){return e.concat(t.parsed)},[]).find(function(t){return t.uri.user===e._ua.contact.uri.user});if(!n){u("no Contact header pointing to us, response ignored");break}var r=n.getParam("expires");!r&&t.hasHeader("expires")&&(r=t.getHeader("expires")),r||(r=e._expires),(r=Number(r))<10&&(r=10);var o=r>64?1e3*r/2+Math.floor(1e3*(r/2-32)*Math.random()):1e3*r-5e3;e._registrationTimer=setTimeout(function(){e._registrationTimer=null,0===e._ua.listeners("registrationExpiring").length?e.register():e._ua.emit("registrationExpiring")},o),n.hasParam("temp-gruu")&&(e._ua.contact.temp_gruu=n.getParam("temp-gruu").replace(/"/g,"")),n.hasParam("pub-gruu")&&(e._ua.contact.pub_gruu=n.getParam("pub-gruu").replace(/"/g,"")),e._registered||(e._registered=!0,e._ua.registered({response:t}));break;case/^423$/.test(t.status_code):t.hasHeader("min-expires")?(e._expires=Number(t.getHeader("min-expires")),e._expires<10&&(e._expires=10),e.register()):(u("423 response received for REGISTER without Min-Expires"),e._registrationFailure(t,i.causes.SIP_FAILURE_CODE));break;default:var l=s.sipErrorCause(t.status_code);e._registrationFailure(t,l)}}});this._registering=!0,r.send()}}},{key:"unregister",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this._registered){this._registered=!1,null!==this._registrationTimer&&(clearTimeout(this._registrationTimer),this._registrationTimer=null);var n=this._extraHeaders.slice();t.all?n.push("Contact: *".concat(this._extraContactParams)):n.push("Contact: ".concat(this._contact,";expires=0").concat(this._extraContactParams)),n.push("Expires: 0");var r=new o.OutgoingRequest(i.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},n);new l(this._ua,r,{onRequestTimeout:function(){e._unregistered(null,i.causes.REQUEST_TIMEOUT)},onTransportError:function(){e._unregistered(null,i.causes.CONNECTION_ERROR)},onAuthenticated:function(){e._cseq+=1},onReceiveResponse:function(t){switch(!0){case/^1[0-9]{2}$/.test(t.status_code):break;case/^2[0-9]{2}$/.test(t.status_code):e._unregistered(t);break;default:var n=s.sipErrorCause(t.status_code);e._unregistered(t,n)}}}).send()}else u("already unregistered")}},{key:"close",value:function(){this._registered&&this.unregister()}},{key:"onTransportClosed",value:function(){this._registering=!1,null!==this._registrationTimer&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),this._registered&&(this._registered=!1,this._ua.unregistered({}))}},{key:"_registrationFailure",value:function(e,t){this._registering=!1,this._ua.registrationFailed({response:e||null,cause:t}),this._registered&&(this._registered=!1,this._ua.unregistered({response:e||null,cause:t}))}},{key:"_unregistered",value:function(e,t){this._registering=!1,this._registered=!1,this._ua.unregistered({response:e||null,cause:t||null})}},{key:"registered",get:function(){return this._registered}}])&&r(t.prototype,n),a&&r(t,a),e}()},{"./Constants":2,"./RequestSender":18,"./SIPMessage":19,"./Utils":26,debug:30}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:s}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,o=!0,l=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return o=e.done,e},e:function(e){l=!0,i=e},f:function(){try{o||null==n.return||n.return()}finally{if(l)throw i}}}}function a(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",_.MAX_FORWARDS);var l=s.to_uri||n,u=s.to_tag?{tag:s.to_tag}:null,a=void 0!==s.to_display_name?s.to_display_name:null;this.to=new m(l,a,u),this.setHeader("to",this.to.toString());var h,f=s.from_uri||r.configuration.uri,d={tag:s.from_tag||p.newTag()};h=void 0!==s.from_display_name?s.from_display_name:r.configuration.display_name?r.configuration.display_name:null,this.from=new m(f,h,d),this.setHeader("from",this.from.toString());var v=s.call_id||r.configuration.jssip_id+p.createRandomToken(15);this.call_id=v,this.setHeader("call-id",v);var g=s.cseq||Math.floor(1e4*Math.random());this.cseq=g,this.setHeader("cseq","".concat(g," ").concat(t))}return f(e,[{key:"setHeader",value:function(e,t){for(var n=new RegExp("^\\s*".concat(e,"\\s*:"),"i"),r=0;r1&&void 0!==arguments[1]?arguments[1]:0;if(e=p.headerize(e),this.headers[e]){if(!(t>=this.headers[e].length)){var n=this.headers[e][t],r=n.raw;if(n.parsed)return n.parsed;var s=v.parse(r,e.replace(/-/g,"_"));return-1===s?(this.headers[e].splice(t,1),void g('error parsing "'.concat(e,'" header field with value "').concat(r,'"'))):(n.parsed=s,s)}g('not so many "'.concat(e,'" headers present'))}else g('header "'.concat(e,'" not present'))}},{key:"s",value:function(e,t){return this.parseHeader(e,t)}},{key:"setHeader",value:function(e,t){var n={raw:t};this.headers[p.headerize(e)]=[n]}},{key:"parseSDP",value:function(e){return!e&&this.sdp?this.sdp:(this.sdp=d.parse(this.body||""),this.sdp)}},{key:"toString",value:function(){return this.data}}]),e}(),S=function(e){s(n,C);var t=o(n);function n(e){var r;return c(this,n),(r=t.call(this)).ua=e,r.headers={},r.ruri=null,r.transport=null,r.server_transaction=null,r}return f(n,[{key:"reply",value:function(e,t,n,r,s,i){var o=[],l=this.getHeader("To");if(t=t||null,!(e=e||null)||e<100||e>699)throw new TypeError("Invalid status_code: ".concat(e));if(t&&"string"!=typeof t&&!(t instanceof String))throw new TypeError("Invalid reason_phrase: ".concat(t));t=t||_.REASON_PHRASE[e]||"",n=p.cloneArray(n);var a="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===_.INVITE&&e>100&&e<=200){var c,h=u(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var f=c.value;a+="Record-Route: ".concat(f,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var d,m=u(this.getHeaders("via"));try{for(m.s();!(d=m.n()).done;){var v=d.value;a+="Via: ".concat(v,"\r\n")}}catch(e){m.e(e)}finally{m.f()}!this.to_tag&&e>100?l+=";tag=".concat(p.newTag()):this.to_tag&&!this.s("to").hasParam("tag")&&(l+=";tag=".concat(this.to_tag)),a+="To: ".concat(l,"\r\n"),a+="From: ".concat(this.getHeader("From"),"\r\n"),a+="Call-ID: ".concat(this.call_id,"\r\n"),a+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=u(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;a+="".concat(T.trim(),"\r\n")}}catch(e){y.e(e)}finally{y.f()}switch(this.method){case _.INVITE:this.ua.configuration.session_timers&&o.push("timer"),(this.ua.contact.pub_gruu||this.ua.contact.temp_gruu)&&o.push("gruu"),o.push("ice","replaces");break;case _.UPDATE:this.ua.configuration.session_timers&&o.push("timer"),r&&o.push("ice"),o.push("replaces")}if(o.push("outbound"),this.method===_.OPTIONS?(a+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"),a+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")):405===e?a+="Allow: ".concat(_.ALLOWED_METHODS,"\r\n"):415===e&&(a+="Accept: ".concat(_.ACCEPTED_BODY_TYPES,"\r\n")),a+="Supported: ".concat(o,"\r\n"),r){var C=p.str_utf8_length(r);a+="Content-Type: application/sdp\r\n",a+="Content-Length: ".concat(C,"\r\n\r\n"),a+=r}else a+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,a,s,i)}},{key:"reply_sl",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=this.getHeaders("via");if(!e||e<100||e>699)throw new TypeError("Invalid status_code: ".concat(e));if(t&&"string"!=typeof t&&!(t instanceof String))throw new TypeError("Invalid reason_phrase: ".concat(t));t=t||_.REASON_PHRASE[e]||"";var r,s="SIP/2.0 ".concat(e," ").concat(t,"\r\n"),i=u(n);try{for(i.s();!(r=i.n()).done;){var o=r.value;s+="Via: ".concat(o,"\r\n")}}catch(e){i.e(e)}finally{i.f()}var l=this.getHeader("To");!this.to_tag&&e>100?l+=";tag=".concat(p.newTag()):this.to_tag&&!this.s("to").hasParam("tag")&&(l+=";tag=".concat(this.to_tag)),s+="To: ".concat(l,"\r\n"),s+="From: ".concat(this.getHeader("From"),"\r\n"),s+="Call-ID: ".concat(this.call_id,"\r\n"),s+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n"),s+="Content-Length: ".concat(0,"\r\n\r\n"),this.transport.send(s)}}]),n}(),E=function(e){s(n,C);var t=o(n);function n(){var e;return c(this,n),(e=t.call(this)).headers={},e.status_code=null,e.reason_phrase=null,e}return n}();t.exports={OutgoingRequest:y,InitialOutgoingInviteRequest:T,IncomingRequest:S,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":26,debug:30,"sdp-transform":35}],20:[function(e,t,n){"use strict";var r=e("./Utils"),s=e("./Grammar"),i=e("debug")("JsSIP:ERROR:Socket");i.log=console.warn.bind(console),n.isSocket=function(e){if(Array.isArray(e))return!1;if(void 0===e)return i("undefined JsSIP.Socket instance"),!1;try{if(!r.isString(e.url))throw i("missing or invalid JsSIP.Socket url property"),new Error;if(!r.isString(e.via_transport))throw i("missing or invalid JsSIP.Socket via_transport property"),new Error;if(-1===s.parse(e.sip_uri,"SIP_URI"))throw i("missing or invalid JsSIP.Socket sip_uri property"),new Error}catch(e){return!1}try{["connect","disconnect","send"].forEach(function(t){if(!r.isFunction(e[t]))throw i("missing or invalid JsSIP.Socket method: ".concat(t)),new Error})}catch(e){return!1}return!0}},{"./Grammar":7,"./Utils":26,debug:30}],21:[function(e,t,n){"use strict";var r=500;t.exports={T1:r,T2:4e3,T4:5e3,TIMER_B:32e3,TIMER_D:0,TIMER_F:32e3,TIMER_H:32e3,TIMER_I:0,TIMER_J:0,TIMER_K:0,TIMER_L:32e3,TIMER_M:32e3,PROVISIONAL_RESPONSE_INTERVAL:6e4}},{}],22:[function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case C.STATUS_CALLING:this.stateChanged(C.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case C.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case C.STATUS_CALLING:case C.STATUS_PROCEEDING:this.stateChanged(C.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},p.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case C.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case C.STATUS_CALLING:case C.STATUS_PROCEEDING:this.stateChanged(C.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case C.STATUS_COMPLETED:this.sendACK(e)}}},{key:"C",get:function(){return C}}]),n}(),A=function(e){l(n,f);var t=a(n);function n(e,r,i,o){var l;s(this,n),(l=t.call(this)).id="z9hG4bK".concat(Math.floor(1e7*Math.random())),l.transport=r,l.request=i,l.eventHandlers=o;var u="SIP/2.0/".concat(r.via_transport);return u+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",u),l}return o(n,[{key:"send",value:function(){this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){g("transport error occurred for transaction ".concat(this.id)),this.eventHandlers.onTransportError()}},{key:"C",get:function(){return C}}]),n}(),b=function(e){l(n,f);var t=a(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=C.NON_INVITE_SERVER,o.id=i.via_branch,o.ua=e,o.transport=r,o.request=i,o.last_response="",i.server_transaction=c(o),o.state=C.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"stateChanged",value:function(e){this.state=e,this.emit("stateChanged")}},{key:"timer_J",value:function(){y("Timer J expired for transaction ".concat(this.id)),this.stateChanged(C.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,y("transport error occurred, deleting transaction ".concat(this.id)),clearTimeout(this.J),this.stateChanged(C.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case C.STATUS_TRYING:this.stateChanged(C.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case C.STATUS_PROCEEDING:this.last_response=t,this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=200&&e<=699)switch(this.state){case C.STATUS_TRYING:case C.STATUS_PROCEEDING:this.stateChanged(C.STATUS_COMPLETED),this.last_response=t,this.J=setTimeout(function(){s.timer_J()},p.TIMER_J),this.transport.send(t)?n&&n():(this.onTransportError(),r&&r());break;case C.STATUS_COMPLETED:}}},{key:"C",get:function(){return C}}]),n}(),R=function(e){l(n,f);var t=a(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=C.INVITE_SERVER,o.id=i.via_branch,o.ua=e,o.transport=r,o.request=i,o.last_response="",i.server_transaction=c(o),o.state=C.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"stateChanged",value:function(e){this.state=e,this.emit("stateChanged")}},{key:"timer_H",value:function(){T("Timer H expired for transaction ".concat(this.id)),this.state===C.STATUS_COMPLETED&&T("ACK not received, dialog will be terminated"),this.stateChanged(C.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(C.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){T("Timer L expired for transaction ".concat(this.id)),this.state===C.STATUS_ACCEPTED&&(this.stateChanged(C.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,T("transport error occurred, deleting transaction ".concat(this.id)),null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),clearTimeout(this.L),clearTimeout(this.H),clearTimeout(this.I),this.stateChanged(C.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"resend_provisional",value:function(){this.transport.send(this.last_response)||this.onTransportError()}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(e>=100&&e<=199)switch(this.state){case C.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===C.STATUS_PROCEEDING)null===this.resendProvisionalTimer&&(this.resendProvisionalTimer=setInterval(function(){s.resend_provisional()},p.PROVISIONAL_RESPONSE_INTERVAL));else if(e>=200&&e<=299)switch(this.state){case C.STATUS_PROCEEDING:this.stateChanged(C.STATUS_ACCEPTED),this.last_response=t,this.L=setTimeout(function(){s.timer_L()},p.TIMER_L),null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null);case C.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case C.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(C.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},p.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}},{key:"C",get:function(){return C}}]),n}();t.exports={C:C,NonInviteClientTransaction:S,InviteClientTransaction:E,AckClientTransaction:A,NonInviteServerTransaction:b,InviteServerTransaction:R,checkTransaction:function(e,t){var n,r=e._transactions;switch(t.method){case d.INVITE:if(n=r.ist[t.via_branch]){switch(n.state){case C.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case C.STATUS_ACCEPTED:}return!0}break;case d.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===C.STATUS_ACCEPTED)return!1;if(n.state===C.STATUS_COMPLETED)return n.state=C.STATUS_CONFIRMED,n.I=setTimeout(function(){n.timer_I()},p.TIMER_I),!0;break;case d.CANCEL:return(n=r.ist[t.via_branch])?(t.reply_sl(200),n.state!==C.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case C.STATUS_TRYING:break;case C.STATUS_PROCEEDING:case C.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./SIPMessage":19,"./Timers":21,debug:30,events:29}],23:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:u.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i("new()"),this.status=u.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){o("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!s.isSocket(e.socket))throw new TypeError("Invalid argument. invalid 'JsSIP.Socket' instance");if(e.weight&&!Number(e.weight))throw new TypeError("Invalid argument. 'weight' attribute is not a number");this.sockets.push({socket:e.socket,weight:e.weight||0,status:u.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,l;return t=e,(n=[{key:"connect",value:function(){i("connect()"),this.isConnected()?i("Transport is already connected"):this.isConnecting()?i("Transport is connecting"):(this.close_requested=!1,this.status=u.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){i("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=u.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(i("send()"),!this.isConnected())return o("unable to send message, transport is not connected"),!1;var t=e.toString();return i("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===u.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===u.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),i("reconnection attempt: ".concat(this.recover_attempts,". next connection attempt in ").concat(t," seconds")),this.recovery_timer=setTimeout(function(){e.close_requested||e.isConnected()||e.isConnecting()||(e._getSocket(),e.connect())},1e3*t)}},{key:"_getSocket",value:function(){var e=[];if(this.sockets.forEach(function(t){t.status!==u.SOCKET_STATUS_ERROR&&(0===e.length?e.push(t):t.weight>e[0].weight?e=[t]:t.weight===e[0].weight&&e.push(t))}),0===e.length)return this.sockets.forEach(function(e){e.status=u.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=u.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=u.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=u.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void i("received binary message failed to be converted into string, message discarded")}i("received binary message:\n\n".concat(e,"\n"))}else i("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else i("received message with CRLF Keep Alive response")}},{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}}])&&r(t.prototype,n),l&&r(t,l),e}()},{"./Constants":2,"./Socket":20,debug:30}],24:[function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function s(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];for(var s in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,s)&&(-1!==r.indexOf(s)?Object.defineProperty(this._configuration,s,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,s,{writable:!1,configurable:!1}));for(var i in A("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(E.settings,i))switch(i){case"uri":case"registrar_server":A("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":A("- ".concat(i,": NOT SHOWN"));break;default:A("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}},{key:"C",get:function(){return R}},{key:"status",get:function(){return this._status}},{key:"contact",get:function(){return this._contact}},{key:"configuration",get:function(){return this._configuration}},{key:"transport",get:function(){return this._transport}}]),n}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Parser":11,"./RTCSession":12,"./Registrator":17,"./SIPMessage":19,"./Transactions":22,"./Transport":23,"./URI":25,"./Utils":26,"./sanityCheck":28,debug:30,events:29}],25:[function(e,t,n){"use strict";function r(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return s(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return s(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,l=!0,u=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return l=e.done,e},e:function(e){u=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(u)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},o=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var u in this._parameters={},this._headers={},this._scheme=t||l.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,u)&&this.setParam(u,i[u]);for(var a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.setHeader(a,o[a])}return o(e,null,[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}]),o(e,[{key:"setParam",value:function(e,t){e&&(this._parameters[e.toLowerCase()]=null==t?null:t.toString())}},{key:"getParam",value:function(e){if(e)return this._parameters[e.toLowerCase()]}},{key:"hasParam",value:function(e){if(e)return!!this._parameters.hasOwnProperty(e.toLowerCase())}},{key:"deleteParam",value:function(e){if(e=e.toLowerCase(),this._parameters.hasOwnProperty(e)){var t=this._parameters[e];return delete this._parameters[e],t}}},{key:"clearParams",value:function(){this._parameters={}}},{key:"setHeader",value:function(e,t){this._headers[u.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[u.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(u.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=u.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(u.escapeUser(this._user),"@")),t+=this._host,(this._port||0===this._port)&&(t+=":".concat(this._port)),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,n)&&(t+=";".concat(n),null!==this._parameters[n]&&(t+="=".concat(this._parameters[n])));for(var s in this._headers)if(Object.prototype.hasOwnProperty.call(this._headers,s)){var i,o=r(this._headers[s]);try{for(o.s();!(i=o.n()).done;){var l=i.value;e.push("".concat(s,"=").concat(l))}}catch(e){o.e(e)}finally{o.f()}}return e.length>0&&(t+="?".concat(e.join("&"))),t}},{key:"toAor",value:function(e){var t="".concat(this._scheme,":");return this._user&&(t+="".concat(u.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}},{key:"scheme",get:function(){return this._scheme},set:function(e){this._scheme=e.toLowerCase()}},{key:"user",get:function(){return this._user},set:function(e){this._user=e}},{key:"host",get:function(){return this._host},set:function(e){this._host=e.toLowerCase()}},{key:"port",get:function(){return this._port},set:function(e){this._port=0===e?e:parseInt(e,10)||null}}]),e}()},{"./Constants":2,"./Grammar":7,"./Utils":26}],26:[function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function s(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return i(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return i(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,s=function(){};return{s:s,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:s}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,l=!0,u=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return l=e.done,e},e:function(e){u=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(u)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>32-t}function n(e,t){var n=2147483648&e,r=2147483648&t,s=1073741824&e,i=1073741824&t,o=(1073741823&e)+(1073741823&t);return s&i?2147483648^o^n^r:s|i?1073741824&o?3221225472^o^n^r:1073741824^o^n^r:o^n^r}function r(e,r,s,i,o,l,u){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),u)),n(t(e,l),r)}function s(e,r,s,i,o,l,u){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),u)),n(t(e,l),r)}function i(e,r,s,i,o,l,u){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),u)),n(t(e,l),r)}function o(e,r,s,i,o,l,u){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),u)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var u,a,c,h,f,d,_,p,m,v;for(u=function(e){for(var t,n=e.length,r=n+8,s=16*((r-r%64)/64+1),i=new Array(s-1),o=0,l=0;l>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&r<2048?(t+=String.fromCharCode(r>>6|192),t+=String.fromCharCode(63&r|128)):(t+=String.fromCharCode(r>>12|224),t+=String.fromCharCode(r>>6&63|128),t+=String.fromCharCode(63&r|128))}return t}(e)),_=1732584193,p=4023233417,m=2562383102,v=271733878,a=0;a1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":25}],27:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,l=!0,u=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return l=e.done,e},e:function(e){u=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(u)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)return h("more than one Via header field present in the response, dropping the response"),!1},function(){var e=c.str_utf8_length(i.body),t=i.getHeader("content-length");if(e0&&l.length>i){l.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",u.name,u.message)}}else l=o[t]=n,++e._eventsCount;return e}function f(){if(!this.fired)switch(this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length){case 0:return this.listener.call(this.target);case 1:return this.listener.call(this.target,arguments[0]);case 2:return this.listener.call(this.target,arguments[0],arguments[1]);case 3:return this.listener.call(this.target,arguments[0],arguments[1],arguments[2]);default:for(var e=new Array(arguments.length),t=0;t1&&(t=arguments[1]),t instanceof Error)throw t;var u=new Error('Unhandled "error" event. ('+t+")");throw u.context=t,u}if(!(n=o[e]))return!1;var a="function"==typeof n;switch(r=arguments.length){case 1:!function(e,t,n){if(t)e.call(n);else for(var r=e.length,s=m(e,r),i=0;i=0;o--)if(n[o]===t||n[o].listener===t){l=n[o].listener,i=o;break}if(i<0)return this;0===i?n.shift():function(e,t){for(var n=t,r=n+1,s=e.length;r=0;i--)this.removeListener(e,t[i]);return this},o.prototype.listeners=function(e){return _(this,e,!0)},o.prototype.rawListeners=function(e){return _(this,e,!1)},o.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):p.call(e,t)},o.prototype.listenerCount=p,o.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]}},{}],30:[function(e,t,n){(function(r){n.log=function(...e){return"object"==typeof console&&console.log&&console.log(...e)},n.formatArgs=function(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+t.exports.humanize(this.diff),!this.useColors)return;const n="color: "+this.color;e.splice(1,0,n,"color: inherit");let r=0,s=0;e[0].replace(/%[a-zA-Z%]/g,e=>{"%%"!==e&&(r++,"%c"===e&&(s=r))}),e.splice(s,0,n)},n.save=function(e){try{e?n.storage.setItem("debug",e):n.storage.removeItem("debug")}catch(e){}},n.load=function(){let e;try{e=n.storage.getItem("debug")}catch(e){}!e&&void 0!==r&&"env"in r&&(e=r.env.DEBUG);return e},n.useColors=function(){if("undefined"!=typeof window&&window.process&&("renderer"===window.process.type||window.process.__nwjs))return!0;if("undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},n.storage=function(){try{return localStorage}catch(e){}}(),n.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.exports=e("./common")(n);const{formatters:s}=t.exports;s.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}).call(this,e("_process"))},{"./common":31,_process:33}],31:[function(e,t,n){t.exports=function(t){function n(e){let t=0;for(let n=0;n{if("%%"===t)return t;l++;const i=r.formatters[s];if("function"==typeof i){const r=e[l];t=i.call(n,r),e.splice(l,1),l--}return t}),r.formatArgs.call(n,e),(n.log||r.log).apply(n,e)}return o.namespace=e,o.enabled=r.enabled(e),o.useColors=r.useColors(),o.color=n(e),o.destroy=s,o.extend=i,"function"==typeof r.init&&r.init(o),r.instances.push(o),o}function s(){const e=r.instances.indexOf(this);return-1!==e&&(r.instances.splice(e,1),!0)}function i(e,t){const n=r(this.namespace+(void 0===t?":":t)+e);return n.log=this.log,n}function o(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return r.debug=r,r.default=r,r.coerce=function(e){return e instanceof Error?e.stack||e.message:e},r.disable=function(){const e=[...r.names.map(o),...r.skips.map(o).map(e=>"-"+e)].join(",");return r.enable(""),e},r.enable=function(e){let t;r.save(e),r.names=[],r.skips=[];const n=("string"==typeof e?e:"").split(/[\s,]+/),s=n.length;for(t=0;t{r[e]=t[e]}),r.instances=[],r.names=[],r.skips=[],r.formatters={},r.selectColor=n,r.enable(r.load()),r}},{ms:32}],32:[function(e,t,n){var r=1e3,s=60*r,i=60*s,o=24*i,l=7*o,u=365.25*o;function a(e,t,n,r){var s=t>=1.5*n;return Math.round(e/n)+" "+r+(s?"s":"")}t.exports=function(e,t){t=t||{};var n=typeof e;if("string"===n&&e.length>0)return function(e){if((e=String(e)).length>100)return;var t=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(!t)return;var n=parseFloat(t[1]);switch((t[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return n*u;case"weeks":case"week":case"w":return n*l;case"days":case"day":case"d":return n*o;case"hours":case"hour":case"hrs":case"hr":case"h":return n*i;case"minutes":case"minute":case"mins":case"min":case"m":return n*s;case"seconds":case"second":case"secs":case"sec":case"s":return n*r;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return n;default:return}}(e);if("number"===n&&isFinite(e))return t.long?function(e){var t=Math.abs(e);if(t>=o)return a(e,t,o,"day");if(t>=i)return a(e,t,i,"hour");if(t>=s)return a(e,t,s,"minute");if(t>=r)return a(e,t,r,"second");return e+" ms"}(e):function(e){var t=Math.abs(e);if(t>=o)return Math.round(e/o)+"d";if(t>=i)return Math.round(e/i)+"h";if(t>=s)return Math.round(e/s)+"m";if(t>=r)return Math.round(e/r)+"s";return e+"ms"}(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))}},{}],33:[function(e,t,n){var r,s,i=t.exports={};function o(){throw new Error("setTimeout has not been defined")}function l(){throw new Error("clearTimeout has not been defined")}function u(e){if(r===setTimeout)return setTimeout(e,0);if((r===o||!r)&&setTimeout)return r=setTimeout,setTimeout(e,0);try{return r(e,0)}catch(t){try{return r.call(null,e,0)}catch(t){return r.call(this,e,0)}}}!function(){try{r="function"==typeof setTimeout?setTimeout:o}catch(e){r=o}try{s="function"==typeof clearTimeout?clearTimeout:l}catch(e){s=l}}();var a,c=[],h=!1,f=-1;function d(){h&&a&&(h=!1,a.length?c=a.concat(c):f=-1,c.length&&_())}function _(){if(!h){var e=u(d);h=!0;for(var t=c.length;t;){for(a=c,c=[];++f1)for(var n=1;n1&&(e[n[0]]=void 0),e};n.parseParams=function(e){return e.split(/;\s?/).reduce(l,{})},n.parseFmtpConfig=n.parseParams,n.parsePayloads=function(e){return e.toString().split(" ").map(Number)},n.parseRemoteCandidates=function(e){for(var t=[],n=e.split(" ").map(r),s=0;s=r)return e;var s=n[t];switch(t+=1,e){case"%%":return"%";case"%s":return String(s);case"%d":return Number(s);case"%v":return""}})}.apply(null,r)},o=["v","o","s","i","u","e","p","c","b","t","r","z","a"],l=["i","c","b","a"];t.exports=function(e,t){t=t||{},null==e.version&&(e.version=0),null==e.name&&(e.name=" "),e.media.forEach(function(e){null==e.payloads&&(e.payloads="")});var n=t.outerOrder||o,s=t.innerOrder||l,u=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?u.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){u.push(i(t,n,e))})})}),e.media.forEach(function(e){u.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?u.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){u.push(i(t,n,e))})})})}),u.join("\r\n")+"\r\n"}},{"./grammar":34}],38:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (https://github.com/ibc)"],types:"lib/JsSIP.d.ts",main:"lib-es5/JsSIP.js",keywords:["sip","websocket","webrtc","node","browser","library"],license:"MIT",repository:{type:"git",url:"https://github.com/versatica/JsSIP.git"},bugs:{url:"https://github.com/versatica/JsSIP/issues"},dependencies:{"@types/debug":"^4.1.5","@types/node":"^14.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","ansi-colors":"^3.2.4",browserify:"^16.5.1",eslint:"^5.16.0","fancy-log":"^1.3.3",gulp:"^4.0.2","gulp-babel":"^8.0.0","gulp-eslint":"^5.0.0","gulp-expect-file":"^1.0.2","gulp-header":"^2.0.9","gulp-nodeunit-runner":"^0.2.2","gulp-plumber":"^1.2.1","gulp-rename":"^1.4.0","gulp-uglify-es":"^1.0.4",pegjs:"^0.7.0","vinyl-buffer":"^1.0.1","vinyl-source-stream":"^2.0.0"},scripts:{lint:"gulp lint",test:"gulp test",prepublishOnly:"gulp babel"}}},{}]},{},[8])(8)}); \ No newline at end of file +!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).JsSIP=e()}}(function(){return function(){return function e(t,n,r){function s(o,l){if(!n[o]){if(!t[o]){var u="function"==typeof require&&require;if(!l&&u)return u(o,!0);if(i)return i(o,!0);var a=new Error("Cannot find module '"+o+"'");throw a.code="MODULE_NOT_FOUND",a}var c=n[o]={exports:{}};t[o][0].call(c.exports,function(e){return s(t[o][1][e]||e)},c,c.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;o=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,l=!0,u=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return l=e.done,e},e:function(e){u=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(u)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0)return t}},connection_recovery_min_interval:function(e){if(i.isDecimal(e)){var t=Number(e);if(t>0)return t}},contact_uri:function(e){if("string"==typeof e){var t=l.parse(e,"SIP_URI");if(-1!==t)return t}},display_name:function(e){return e},instance_id:function(e){return/^uuid:/i.test(e)&&(e=e.substr(5)),-1===l.parse(e,"uuid")?void 0:e},no_answer_timeout:function(e){if(i.isDecimal(e)){var t=Number(e);if(t>0)return t}},session_timers:function(e){if("boolean"==typeof e)return e},session_timers_refresh_method:function(e){if("string"==typeof e&&((e=e.toUpperCase())===o.INVITE||e===o.UPDATE))return e},session_timers_force_refresher:function(e){if("boolean"==typeof e)return e},password:function(e){return String(e)},realm:function(e){return String(e)},ha1:function(e){return String(e)},register:function(e){if("boolean"==typeof e)return e},register_expires:function(e){if(i.isDecimal(e)){var t=Number(e);if(t>0)return t}},registrar_server:function(e){/^sip:/i.test(e)||(e="".concat(o.SIP,":").concat(e));var t=u.parse(e);return t?t.user?void 0:t:void 0},use_preloaded_route:function(e){if("boolean"==typeof e)return e}}};n.load=function(e,t){for(var n in h.mandatory){if(!t.hasOwnProperty(n))throw new c.ConfigurationError(n);var r=t[n],s=h.mandatory[n](r);if(void 0===s)throw new c.ConfigurationError(n,r);e[n]=s}for(var o in h.optional)if(t.hasOwnProperty(o)){var l=t[o];if(i.isEmpty(l))continue;var u=h.optional[o](l);if(void 0===u)throw new c.ConfigurationError(o,l);e[o]=u}}},{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":21,"./URI":26,"./Utils":27}],2:[function(e,t,n){"use strict";var r=e("../package.json");t.exports={USER_AGENT:"".concat(r.title," ").concat(r.version),SIP:"sip",SIPS:"sips",causes:{CONNECTION_ERROR:"Connection Error",REQUEST_TIMEOUT:"Request Timeout",SIP_FAILURE_CODE:"SIP Failure Code",INTERNAL_ERROR:"Internal Error",BUSY:"Busy",REJECTED:"Rejected",REDIRECTED:"Redirected",UNAVAILABLE:"Unavailable",NOT_FOUND:"Not Found",ADDRESS_INCOMPLETE:"Address Incomplete",INCOMPATIBLE_SDP:"Incompatible SDP",MISSING_SDP:"Missing SDP",AUTHENTICATION_ERROR:"Authentication Error",BYE:"Terminated",WEBRTC_ERROR:"WebRTC Error",CANCELED:"Canceled",NO_ANSWER:"No Answer",EXPIRES:"Expires",NO_ACK:"No ACK",DIALOG_ERROR:"Dialog Error",USER_DENIED_MEDIA_ACCESS:"User Denied Media Access",BAD_MEDIA_DESCRIPTION:"Bad Media Description",RTP_TIMEOUT:"RTP Timeout"},SIP_ERROR_CAUSES:{REDIRECTED:[300,301,302,305,380],BUSY:[486,600],REJECTED:[403,603],NOT_FOUND:[404,604],UNAVAILABLE:[480,410,408,430],ADDRESS_INCOMPLETE:[484,424],INCOMPATIBLE_SDP:[488,606],AUTHENTICATION_ERROR:[401,407]},ACK:"ACK",BYE:"BYE",CANCEL:"CANCEL",INFO:"INFO",INVITE:"INVITE",MESSAGE:"MESSAGE",NOTIFY:"NOTIFY",OPTIONS:"OPTIONS",REGISTER:"REGISTER",REFER:"REFER",UPDATE:"UPDATE",SUBSCRIBE:"SUBSCRIBE",DTMF_TRANSPORT:{INFO:"INFO",RFC2833:"RFC2833"},REASON_PHRASE:{100:"Trying",180:"Ringing",181:"Call Is Being Forwarded",182:"Queued",183:"Session Progress",199:"Early Dialog Terminated",200:"OK",202:"Accepted",204:"No Notification",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",305:"Use Proxy",380:"Alternative Service",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",410:"Gone",412:"Conditional Request Failed",413:"Request Entity Too Large",414:"Request-URI Too Long",415:"Unsupported Media Type",416:"Unsupported URI Scheme",417:"Unknown Resource-Priority",420:"Bad Extension",421:"Extension Required",422:"Session Interval Too Small",423:"Interval Too Brief",424:"Bad Location Information",428:"Use Identity Header",429:"Provide Referrer Identity",430:"Flow Failed",433:"Anonymity Disallowed",436:"Bad Identity-Info",437:"Unsupported Certificate",438:"Invalid Identity Header",439:"First Hop Lacks Outbound Support",440:"Max-Breadth Exceeded",469:"Bad Info Package",470:"Consent Needed",478:"Unresolvable Destination",480:"Temporarily Unavailable",481:"Call/Transaction Does Not Exist",482:"Loop Detected",483:"Too Many Hops",484:"Address Incomplete",485:"Ambiguous",486:"Busy Here",487:"Request Terminated",488:"Not Acceptable Here",489:"Bad Event",491:"Request Pending",493:"Undecipherable",494:"Security Agreement Required",500:"JsSIP Internal Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Server Time-out",505:"Version Not Supported",513:"Message Too Large",580:"Precondition Failure",600:"Busy Everywhere",603:"Decline",604:"Does Not Exist Anywhere",606:"Not Acceptable"},ALLOWED_METHODS:"INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY",ACCEPTED_BODY_TYPES:"application/sdp, application/dtmf-relay",MAX_FORWARDS:69,SESSION_EXPIRES:90,MIN_SESSION_EXPIRES:60,CONNECTION_RECOVERY_MAX_INTERVAL:30,CONNECTION_RECOVERY_MIN_INTERVAL:2}},{"../package.json":39}],3:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:d.STATUS_CONFIRMED;if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this._owner=t,this._ua=t._ua,this._uac_pending_reply=!1,this._uas_pending_reply=!1,!n.hasHeader("contact"))return{error:"unable to create a Dialog without Contact header field"};n instanceof o.IncomingResponse&&(s=n.status_code<200?d.STATUS_EARLY:d.STATUS_CONFIRMED);var i=n.parseHeader("contact");"UAS"===r?(this._id={call_id:n.call_id,local_tag:n.to_tag,remote_tag:n.from_tag,toString:function(){return this.call_id+this.local_tag+this.remote_tag}},this._state=s,this._remote_seqnum=n.cseq,this._local_uri=n.parseHeader("to").uri,this._remote_uri=n.parseHeader("from").uri,this._remote_target=i.uri,this._route_set=n.getHeaders("record-route"),this._ack_seqnum=this._remote_seqnum):"UAC"===r&&(this._id={call_id:n.call_id,local_tag:n.from_tag,remote_tag:n.to_tag,toString:function(){return this.call_id+this.local_tag+this.remote_tag}},this._state=s,this._local_seqnum=n.cseq,this._local_uri=n.parseHeader("from").uri,this._remote_uri=n.parseHeader("to").uri,this._remote_target=i.uri,this._route_set=n.getHeaders("record-route").reverse(),this._ack_seqnum=null),this._ua.newDialog(this),h.debug("new ".concat(r," dialog created with status ").concat(this._state===d.STATUS_EARLY?"EARLY":"CONFIRMED"))}return s(e,null,[{key:"C",get:function(){return d}}]),s(e,[{key:"update",value:function(e,t){this._state=d.STATUS_CONFIRMED,h.debug("dialog ".concat(this._id.toString()," changed to CONFIRMED state")),"UAC"===t&&(this._route_set=e.getHeaders("record-route").reverse())}},{key:"terminate",value:function(){h.debug("dialog ".concat(this._id.toString()," deleted")),this._ua.destroyDialog(this)}},{key:"sendRequest",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=c.cloneArray(n.extraHeaders),s=c.cloneObject(n.eventHandlers),i=n.body||null,o=this._createRequest(e,r,i);return s.onAuthenticated=function(){t._local_seqnum+=1},new a(this,o,s).send(),o}},{key:"receiveRequest",value:function(e){this._checkInDialogRequest(e)&&(e.method===l.ACK&&null!==this._ack_seqnum?this._ack_seqnum=null:e.method===l.INVITE&&(this._ack_seqnum=e.cseq),this._owner.receiveRequest(e))}},{key:"_createRequest",value:function(e,t,n){t=c.cloneArray(t),this._local_seqnum||(this._local_seqnum=Math.floor(1e4*Math.random()));var r=e===l.CANCEL||e===l.ACK?this._local_seqnum:this._local_seqnum+=1;return new o.OutgoingRequest(e,this._remote_target,this._ua,{cseq:r,call_id:this._id.call_id,from_uri:this._local_uri,from_tag:this._id.local_tag,to_uri:this._remote_uri,to_tag:this._id.remote_tag,route_set:this._route_set},t,n)}},{key:"_checkInDialogRequest",value:function(e){var t=this;if(this._remote_seqnum)if(e.cseqthis._remote_seqnum&&(this._remote_seqnum=e.cseq);else this._remote_seqnum=e.cseq;if(e.method===l.INVITE||e.method===l.UPDATE&&e.body){if(!0===this._uac_pending_reply)e.reply(491);else{if(!0===this._uas_pending_reply){var n=1+(10*Math.random()|0);return e.reply(500,null,["Retry-After:".concat(n)]),!1}this._uas_pending_reply=!0;e.server_transaction.on("stateChanged",function n(){e.server_transaction.state!==u.C.STATUS_ACCEPTED&&e.server_transaction.state!==u.C.STATUS_COMPLETED&&e.server_transaction.state!==u.C.STATUS_TERMINATED||(e.server_transaction.removeListener("stateChanged",n),t._uas_pending_reply=!1)})}e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===u.C.STATUS_ACCEPTED&&(t._remote_target=e.parseHeader("contact").uri)})}else e.method===l.NOTIFY&&e.hasHeader("contact")&&e.server_transaction.on("stateChanged",function(){e.server_transaction.state===u.C.STATUS_COMPLETED&&(t._remote_target=e.parseHeader("contact").uri)});return!0}},{key:"id",get:function(){return this._id}},{key:"local_seqnum",get:function(){return this._local_seqnum},set:function(e){this._local_seqnum=e}},{key:"owner",get:function(){return this._owner}},{key:"uac_pending_reply",get:function(){return this._uac_pending_reply},set:function(e){this._uac_pending_reply=e}},{key:"uas_pending_reply",get:function(){return this._uas_pending_reply}}]),e}()},{"./Constants":2,"./Dialog/RequestSender":4,"./Logger":9,"./SIPMessage":20,"./Transactions":23,"./Utils":27}],4:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200&&e.status_code<300?this._eventHandlers.onSuccessResponse(e):e.status_code>=300&&this._eventHandlers.onErrorResponse(e):(this._request.cseq=this._dialog.local_seqnum+=1,this._reattemptTimer=setTimeout(function(){t._dialog.owner.status!==o.C.STATUS_TERMINATED&&(t._reattempt=!0,t._request_sender.send())},1e3)):e.status_code>=200&&e.status_code<300?this._eventHandlers.onSuccessResponse(e):e.status_code>=300&&this._eventHandlers.onErrorResponse(e)}},{key:"request",get:function(){return this._request}}])&&r(t.prototype,n),a&&r(t,a),e}()},{"../Constants":2,"../RTCSession":13,"../RequestSender":19,"../Transactions":23}],5:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n2&&void 0!==arguments[2]?arguments[2]:null;if(this._algorithm=t.algorithm,this._realm=t.realm,this._nonce=t.nonce,this._opaque=t.opaque,this._stale=t.stale,this._algorithm){if("MD5"!==this._algorithm)return o.warn('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'),!1}else this._algorithm="MD5";if(!this._nonce)return o.warn("authenticate() | challenge without Digest nonce, authentication aborted"),!1;if(!this._realm)return o.warn("authenticate() | challenge without Digest realm, authentication aborted"),!1;if(!this._credentials.password){if(!this._credentials.ha1)return o.warn("authenticate() | no plain SIP password nor ha1 provided, authentication aborted"),!1;if(this._credentials.realm!==this._realm)return o.warn('authenticate() | no plain SIP password, and stored `realm` does not match the given `realm`, cannot authenticate [stored:"%s", given:"%s"]',this._credentials.realm,this._realm),!1}if(t.qop)if(t.qop.indexOf("auth-int")>-1)this._qop="auth-int";else{if(!(t.qop.indexOf("auth")>-1))return o.warn('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted'),!1;this._qop="auth"}else this._qop=null;this._method=n,this._uri=r,this._cnonce=l||i.createRandomToken(12),this._nc+=1;var u,a,c=Number(this._nc).toString(16);return this._ncHex="00000000".substr(0,8-c.length)+c,4294967296===this._nc&&(this._nc=1,this._ncHex="00000001"),this._credentials.password?this._ha1=i.calculateMD5("".concat(this._credentials.username,":").concat(this._realm,":").concat(this._credentials.password)):this._ha1=this._credentials.ha1,"auth"===this._qop?(u="".concat(this._method,":").concat(this._uri),a=i.calculateMD5(u),o.debug('authenticate() | using qop=auth [a2:"%s"]',u),this._response=i.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth:").concat(a))):"auth-int"===this._qop?(u="".concat(this._method,":").concat(this._uri,":").concat(i.calculateMD5(s||"")),a=i.calculateMD5(u),o.debug('authenticate() | using qop=auth-int [a2:"%s"]',u),this._response=i.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(this._ncHex,":").concat(this._cnonce,":auth-int:").concat(a))):null===this._qop&&(u="".concat(this._method,":").concat(this._uri),a=i.calculateMD5(u),o.debug('authenticate() | using qop=null [a2:"%s"]',u),this._response=i.calculateMD5("".concat(this._ha1,":").concat(this._nonce,":").concat(a))),o.debug("authenticate() | response generated"),!0}},{key:"toString",value:function(){var e=[];if(!this._response)throw new Error("response field does not exist, cannot generate Authorization header");return e.push("algorithm=".concat(this._algorithm)),e.push('username="'.concat(this._credentials.username,'"')),e.push('realm="'.concat(this._realm,'"')),e.push('nonce="'.concat(this._nonce,'"')),e.push('uri="'.concat(this._uri,'"')),e.push('response="'.concat(this._response,'"')),this._opaque&&e.push('opaque="'.concat(this._opaque,'"')),this._qop&&(e.push("qop=".concat(this._qop)),e.push('cnonce="'.concat(this._cnonce,'"')),e.push("nc=".concat(this._ncHex))),"Digest ".concat(e.join(", "))}}])&&r(t.prototype,n),s&&r(t,s),e}()},{"./Logger":9,"./Utils":27}],6:[function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&c(e,t)}function o(e){var t=a();return function(){var n,s=h(e);if(t){var i=h(this).constructor;n=Reflect.construct(s,arguments,i)}else n=s.apply(this,arguments);return function(e,t){if(t&&("object"===r(t)||"function"==typeof t))return t;return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(this,n)}}function l(e){var t="function"==typeof Map?new Map:void 0;return(l=function(e){if(null===e||(n=e,-1===Function.toString.call(n).indexOf("[native code]")))return e;var n;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return u(e,arguments,h(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),c(r,e)})(e)}function u(e,t,n){return(u=a()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var s=new(Function.bind.apply(e,r));return n&&c(s,n.prototype),s}).apply(null,arguments)}function a(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}function c(e,t){return(c=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function h(e){return(h=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}var d=function(e){i(n,l(Error));var t=o(n);function n(e,r){var i;return s(this,n),(i=t.call(this)).code=1,i.name="CONFIGURATION_ERROR",i.parameter=e,i.value=r,i.message=i.value?"Invalid value ".concat(JSON.stringify(i.value),' for parameter "').concat(i.parameter,'"'):"Missing parameter: ".concat(i.parameter),i}return n}(),f=function(e){i(n,l(Error));var t=o(n);function n(e){var r;return s(this,n),(r=t.call(this)).code=2,r.name="INVALID_STATE_ERROR",r.status=e,r.message="Invalid status: ".concat(e),r}return n}(),_=function(e){i(n,l(Error));var t=o(n);function n(e){var r;return s(this,n),(r=t.call(this)).code=3,r.name="NOT_SUPPORTED_ERROR",r.message=e,r}return n}(),p=function(e){i(n,l(Error));var t=o(n);function n(e){var r;return s(this,n),(r=t.call(this)).code=4,r.name="NOT_READY_ERROR",r.message=e,r}return n}();t.exports={ConfigurationError:d,InvalidStateError:f,NotSupportedError:_,NotReadyError:p}},{}],7:[function(e,t,n){"use strict";t.exports=function(){function t(e){return'"'+e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g,escape)+'"'}var n={parse:function(n,r){var s={CRLF:c,DIGIT:h,ALPHA:d,HEXDIG:f,WSP:_,OCTET:p,DQUOTE:m,SP:v,HTAB:g,alphanum:y,reserved:T,unreserved:C,mark:b,escaped:S,LWS:E,SWS:A,HCOLON:R,TEXT_UTF8_TRIM:w,TEXT_UTF8char:I,UTF8_NONASCII:O,UTF8_CONT:N,LHEX:function(){var e;null===(e=h())&&(/^[a-f]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[a-f]")));return e},token:k,token_nodot:D,separators:function(){var e;40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&a('"("'));null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&a('")"')),null===e&&(60===n.charCodeAt(i)?(e="<",i++):(e=null,0===o&&a('"<"')),null===e&&(62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&a('">"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&a('"@"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&a('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&a('";"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&a('":"')),null===e&&(92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&a('"\\\\"')),null===e&&null===(e=m())&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&a('"/"')),null===e&&(91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&a('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&a('"]"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&a('"?"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&a('"="')),null===e&&(123===n.charCodeAt(i)?(e="{",i++):(e=null,0===o&&a('"{"')),null===e&&(125===n.charCodeAt(i)?(e="}",i++):(e=null,0===o&&a('"}"')),null===e&&null===(e=v())&&(e=g()))))))))))))))));return e},word:U,STAR:x,SLASH:P,EQUAL:M,LPAREN:L,RPAREN:q,RAQUOT:H,LAQUOT:F,COMMA:j,SEMI:G,COLON:W,LDQUOT:V,RDQUOT:B,comment:function e(){var t,n,r;var s;s=i;t=L();if(null!==t){for(n=[],null===(r=K())&&null===(r=X())&&(r=e());null!==r;)n.push(r),null===(r=K())&&null===(r=X())&&(r=e());null!==n&&null!==(r=q())?t=[t,n,r]:(t=null,i=s)}else t=null,i=s;return t},ctext:K,quoted_string:Y,quoted_string_clean:z,qdtext:$,quoted_pair:X,SIP_URI_noparams:J,SIP_URI:Q,uri_scheme:Z,uri_scheme_sips:ee,uri_scheme_sip:te,userinfo:ne,user:re,user_unreserved:se,password:ie,hostport:oe,host:le,hostname:ue,domainlabel:ae,toplabel:ce,IPv6reference:he,IPv6address:de,h16:fe,ls32:_e,IPv4address:pe,dec_octet:me,port:ve,uri_parameters:ge,uri_parameter:ye,transport_param:Te,user_param:Ce,method_param:be,ttl_param:Se,maddr_param:Ee,lr_param:Ae,other_param:Re,pname:we,pvalue:Ie,paramchar:Oe,param_unreserved:Ne,headers:ke,header:De,hname:Ue,hvalue:xe,hnv_unreserved:Pe,Request_Response:function(){var e;null===(e=ht())&&(e=Me());return e},Request_Line:Me,Request_URI:Le,absoluteURI:qe,hier_part:He,net_path:Fe,abs_path:je,opaque_part:Ge,uric:We,uric_no_slash:Ve,path_segments:Be,segment:Ke,param:Ye,pchar:ze,scheme:$e,authority:Xe,srvr:Je,reg_name:Qe,query:Ze,SIP_Version:et,INVITEm:tt,ACKm:nt,OPTIONSm:rt,BYEm:st,CANCELm:it,REGISTERm:ot,SUBSCRIBEm:lt,NOTIFYm:ut,REFERm:at,Method:ct,Status_Line:ht,Status_Code:dt,extension_code:ft,Reason_Phrase:_t,Allow_Events:function(){var e,t,n,r,s,o;if(s=i,null!==(e=qt())){for(t=[],o=i,null!==(n=j())&&null!==(r=qt())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=j())&&null!==(r=qt())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e},Call_ID:function(){var e,t,r,s,l,u;s=i,l=i,null!==(e=U())?(u=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&a('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=u),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=l)):(e=null,i=l);null!==e&&(c=s,e=void(jn=n.substring(i,c)));var c;null===e&&(i=s);return e},Contact:function(){var e,t,n,r,s,o,l;if(s=i,null===(e=x()))if(o=i,null!==(e=pt())){for(t=[],l=i,null!==(n=j())&&null!==(r=pt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=j())&&null!==(r=pt())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;null!==e&&(e=function(e){var t,n;for(n=jn.multi_header.length,t=0;tl&&(l=i,u=[]),u.push(e))}function c(){var e;return"\r\n"===n.substr(i,2)?(e="\r\n",i+=2):(e=null,0===o&&a('"\\r\\n"')),e}function h(){var e;return/^[0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[0-9]")),e}function d(){var e;return/^[a-zA-Z]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[a-zA-Z]")),e}function f(){var e;return/^[0-9a-fA-F]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[0-9a-fA-F]")),e}function _(){var e;return null===(e=v())&&(e=g()),e}function p(){var e;return/^[\0-\xFF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[\\0-\\xFF]")),e}function m(){var e;return/^["]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a('["]')),e}function v(){var e;return 32===n.charCodeAt(i)?(e=" ",i++):(e=null,0===o&&a('" "')),e}function g(){var e;return 9===n.charCodeAt(i)?(e="\t",i++):(e=null,0===o&&a('"\\t"')),e}function y(){var e;return/^[a-zA-Z0-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[a-zA-Z0-9]")),e}function T(){var e;return 59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&a('";"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&a('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&a('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&a('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&a('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&a('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&a('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&a('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&a('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&a('","'))))))))))),e}function C(){var e;return null===(e=y())&&(e=b()),e}function b(){var e;return 45===n.charCodeAt(i)?(e="-",i++):(e=null,0===o&&a('"-"')),null===e&&(95===n.charCodeAt(i)?(e="_",i++):(e=null,0===o&&a('"_"')),null===e&&(46===n.charCodeAt(i)?(e=".",i++):(e=null,0===o&&a('"."')),null===e&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&a('"!"')),null===e&&(126===n.charCodeAt(i)?(e="~",i++):(e=null,0===o&&a('"~"')),null===e&&(42===n.charCodeAt(i)?(e="*",i++):(e=null,0===o&&a('"*"')),null===e&&(39===n.charCodeAt(i)?(e="'",i++):(e=null,0===o&&a('"\'"')),null===e&&(40===n.charCodeAt(i)?(e="(",i++):(e=null,0===o&&a('"("')),null===e&&(41===n.charCodeAt(i)?(e=")",i++):(e=null,0===o&&a('")"')))))))))),e}function S(){var e,t,r,s,l;return s=i,l=i,37===n.charCodeAt(i)?(e="%",i++):(e=null,0===o&&a('"%"')),null!==e&&null!==(t=f())&&null!==(r=f())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=e.join("")),null===e&&(i=s),e}function E(){var e,t,n,r,s,o;for(r=i,s=i,o=i,e=[],t=_();null!==t;)e.push(t),t=_();if(null!==e&&null!==(t=c())?e=[e,t]:(e=null,i=o),null!==(e=null!==e?e:"")){if(null!==(n=_()))for(t=[];null!==n;)t.push(n),n=_();else t=null;null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return null!==e&&(e=" "),null===e&&(i=r),e}function A(){var e;return e=null!==(e=E())?e:""}function R(){var e,t,r,s,l;for(s=i,l=i,e=[],null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=v())&&(t=g());return null!==e?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=":"),null===e&&(i=s),e}function w(){var e,t,r,s,o,l,u,a;if(o=i,l=i,null!==(t=I()))for(e=[];null!==t;)e.push(t),t=I();else e=null;if(null!==e){for(t=[],u=i,r=[],s=E();null!==s;)r.push(s),s=E();for(null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=u);null!==r;){for(t.push(r),u=i,r=[],s=E();null!==s;)r.push(s),s=E();null!==r&&null!==(s=I())?r=[r,s]:(r=null,i=u)}null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(a=o,e=n.substring(i,a)),null===e&&(i=o),e}function I(){var e;return/^[!-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[!-~]")),null===e&&(e=O()),e}function O(){var e;return/^[\x80-\uFFFF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[\\x80-\\uFFFF]")),e}function N(){var e;return/^[\x80-\xBF]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[\\x80-\\xBF]")),e}function k(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&a('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&a('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&a('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&a('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&a('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&a('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&a('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&a('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&a('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&a('"~"')))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&a('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&a('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&a('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&a('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&a('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&a('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&a('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&a('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&a('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&a('"~"'))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function D(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&a('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&a('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&a('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&a('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&a('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&a('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&a('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&a('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&a('"~"'))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&a('"-"')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&a('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&a('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&a('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&a('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&a('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&a('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&a('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&a('"~"')))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function U(){var e,t,r,s;if(r=i,null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&a('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&a('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&a('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&a('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&a('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&a('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&a('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&a('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&a('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&a('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&a('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&a('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&a('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&a('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&a('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&a('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&a('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&a('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&a('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&a('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&a('"}"')))))))))))))))))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=y())&&(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&a('"-"')),null===t&&(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&a('"."')),null===t&&(33===n.charCodeAt(i)?(t="!",i++):(t=null,0===o&&a('"!"')),null===t&&(37===n.charCodeAt(i)?(t="%",i++):(t=null,0===o&&a('"%"')),null===t&&(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&a('"*"')),null===t&&(95===n.charCodeAt(i)?(t="_",i++):(t=null,0===o&&a('"_"')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&a('"+"')),null===t&&(96===n.charCodeAt(i)?(t="`",i++):(t=null,0===o&&a('"`"')),null===t&&(39===n.charCodeAt(i)?(t="'",i++):(t=null,0===o&&a('"\'"')),null===t&&(126===n.charCodeAt(i)?(t="~",i++):(t=null,0===o&&a('"~"')),null===t&&(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&a('"("')),null===t&&(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&a('")"')),null===t&&(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&a('"<"')),null===t&&(62===n.charCodeAt(i)?(t=">",i++):(t=null,0===o&&a('">"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null===t&&(92===n.charCodeAt(i)?(t="\\",i++):(t=null,0===o&&a('"\\\\"')),null===t&&null===(t=m())&&(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&a('"/"')),null===t&&(91===n.charCodeAt(i)?(t="[",i++):(t=null,0===o&&a('"["')),null===t&&(93===n.charCodeAt(i)?(t="]",i++):(t=null,0===o&&a('"]"')),null===t&&(63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&a('"?"')),null===t&&(123===n.charCodeAt(i)?(t="{",i++):(t=null,0===o&&a('"{"')),null===t&&(125===n.charCodeAt(i)?(t="}",i++):(t=null,0===o&&a('"}"'))))))))))))))))))))))));else e=null;return null!==e&&(s=r,e=n.substring(i,s)),null===e&&(i=r),e}function x(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(42===n.charCodeAt(i)?(t="*",i++):(t=null,0===o&&a('"*"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="*"),null===e&&(i=s),e}function P(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&a('"/"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="/"),null===e&&(i=s),e}function M(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&a('"="')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="="),null===e&&(i=s),e}function L(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(40===n.charCodeAt(i)?(t="(",i++):(t=null,0===o&&a('"("')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e="("),null===e&&(i=s),e}function q(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(41===n.charCodeAt(i)?(t=")",i++):(t=null,0===o&&a('")"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=")"),null===e&&(i=s),e}function H(){var e,t,r,s;return r=i,s=i,62===n.charCodeAt(i)?(e=">",i++):(e=null,0===o&&a('">"')),null!==e&&null!==(t=A())?e=[e,t]:(e=null,i=s),null!==e&&(e=">"),null===e&&(i=r),e}function F(){var e,t,r,s;return r=i,s=i,null!==(e=A())?(60===n.charCodeAt(i)?(t="<",i++):(t=null,0===o&&a('"<"')),null!==t?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(e="<"),null===e&&(i=r),e}function j(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&a('","')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=","),null===e&&(i=s),e}function G(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&a('";"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=";"),null===e&&(i=s),e}function W(){var e,t,r,s,l;return s=i,l=i,null!==(e=A())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=A())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(e=":"),null===e&&(i=s),e}function V(){var e,t,n,r;return n=i,r=i,null!==(e=A())&&null!==(t=m())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function B(){var e,t,n,r;return n=i,r=i,null!==(e=m())&&null!==(t=A())?e=[e,t]:(e=null,i=r),null!==e&&(e='"'),null===e&&(i=n),e}function K(){var e;return/^[!-']/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[!-']")),null===e&&(/^[*-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[*-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[\\]-~]")),null===e&&null===(e=O())&&(e=E()))),e}function Y(){var e,t,r,s,o,l,u;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=$())&&(s=X());null!==s;)r.push(s),null===(s=$())&&(s=X());null!==r&&null!==(s=m())?e=[e,t,r,s]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;return null!==e&&(u=o,e=n.substring(i,u)),null===e&&(i=o),e}function z(){var e,t,r,s,o,l,u,a;if(o=i,l=i,null!==(e=A()))if(null!==(t=m())){for(r=[],null===(s=$())&&(s=X());null!==s;)r.push(s),null===(s=$())&&(s=X());null!==r&&null!==(s=m())?e=[e,t,r,s]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;return null!==e&&(u=o,e=(a=n.substring(i,u).trim()).substring(1,a.length-1).replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g,"$1")),null===e&&(i=o),e}function $(){var e;return null===(e=E())&&(33===n.charCodeAt(i)?(e="!",i++):(e=null,0===o&&a('"!"')),null===e&&(/^[#-[]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[#-[]")),null===e&&(/^[\]-~]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[\\]-~]")),null===e&&(e=O())))),e}function X(){var e,t,r;return r=i,92===n.charCodeAt(i)?(e="\\",i++):(e=null,0===o&&a('"\\\\"')),null!==e?(/^[\0-\t]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&a("[\\0-\\t]")),null===t&&(/^[\x0B-\f]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&a("[\\x0B-\\f]")),null===t&&(/^[\x0E-]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&a("[\\x0E-]")))),null!==t?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function J(){var e,t,r,s,l,u;return l=i,u=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=null!==(r=ne())?r:"")&&null!==(s=oe())?e=[e,t,r,s]:(e=null,i=u)):(e=null,i=u),null!==e&&(e=function(e){try{jn.uri=new Hn(jn.scheme,jn.user,jn.host,jn.port),delete jn.scheme,delete jn.user,delete jn.host,delete jn.host_type,delete jn.port}catch(e){jn=-1}}()),null===e&&(i=l),e}function Q(){var e,t,s,l,u,c,h,d;return h=i,d=i,null!==(e=Z())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(s=null!==(s=ne())?s:"")&&null!==(l=oe())&&null!==(u=ge())&&null!==(c=null!==(c=ke())?c:"")?e=[e,t,s,l,u,c]:(e=null,i=d)):(e=null,i=d),null!==e&&(e=function(e){try{jn.uri=new Hn(jn.scheme,jn.user,jn.host,jn.port,jn.uri_params,jn.uri_headers),delete jn.scheme,delete jn.user,delete jn.host,delete jn.host_type,delete jn.port,delete jn.uri_params,"SIP_URI"===r&&(jn=jn.uri)}catch(e){jn=-1}}()),null===e&&(i=h),e}function Z(){var e;return null===(e=ee())&&(e=te()),e}function ee(){var e,t,r;return t=i,"sips"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&a('"sips"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function te(){var e,t,r;return t=i,"sip"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&a('"sip"')),null!==e&&(r=e,e=void(jn.scheme=r.toLowerCase())),null===e&&(i=t),e}function ne(){var e,t,r,s,l,u,c;return s=i,l=i,null!==(e=re())?(u=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=ie())?t=[t,r]:(t=null,i=u),null!==(t=null!==t?t:"")?(64===n.charCodeAt(i)?(r="@",i++):(r=null,0===o&&a('"@"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l)):(e=null,i=l),null!==e&&(c=s,e=void(jn.user=decodeURIComponent(n.substring(i-1,c)))),null===e&&(i=s),e}function re(){var e,t;if(null===(t=C())&&null===(t=S())&&(t=se()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=C())&&null===(t=S())&&(t=se());else e=null;return e}function se(){var e;return 38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&a('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&a('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&a('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&a('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&a('","')),null===e&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&a('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&a('"?"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&a('"/"'))))))))),e}function ie(){var e,t,r,s;for(r=i,e=[],null===(t=C())&&null===(t=S())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&a('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&a('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&a('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&a('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&a('","')))))));null!==t;)e.push(t),null===(t=C())&&null===(t=S())&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&a('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&a('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&a('"+"')),null===t&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&a('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&a('","')))))));return null!==e&&(s=r,e=void(jn.password=n.substring(i,s))),null===e&&(i=r),e}function oe(){var e,t,r,s,l;return s=i,null!==(e=le())?(l=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=ve())?t=[t,r]:(t=null,i=l),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),e}function le(){var e,t,r;return t=i,null===(e=ue())&&null===(e=pe())&&(e=he()),null!==e&&(r=t,jn.host=n.substring(i,r).toLowerCase(),e=jn.host),null===e&&(i=t),e}function ue(){var e,t,r,s,l,u,c;for(s=i,l=i,e=[],u=i,null!==(t=ae())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&a('"."')),null!==r?t=[t,r]:(t=null,i=u)):(t=null,i=u);null!==t;)e.push(t),u=i,null!==(t=ae())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&a('"."')),null!==r?t=[t,r]:(t=null,i=u)):(t=null,i=u);return null!==e&&null!==(t=ce())?(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&a('"."')),null!==(r=null!==r?r:"")?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(c=s,jn.host_type="domain",e=n.substring(i,c)),null===e&&(i=s),e}function ae(){var e,t,r,s;if(s=i,null!==(e=y())){for(t=[],null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&a('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&a('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&a('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&a('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function ce(){var e,t,r,s;if(s=i,null!==(e=d())){for(t=[],null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&a('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&a('"_"'))));null!==r;)t.push(r),null===(r=y())&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&a('"-"')),null===r&&(95===n.charCodeAt(i)?(r="_",i++):(r=null,0===o&&a('"_"'))));null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function he(){var e,t,r,s,l,u;return s=i,l=i,91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&a('"["')),null!==e&&null!==(t=de())?(93===n.charCodeAt(i)?(r="]",i++):(r=null,0===o&&a('"]"')),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(u=s,jn.host_type="IPv6",e=n.substring(i,u)),null===e&&(i=s),e}function de(){var e,t,r,s,l,u,c,h,d,f,_,p,m,v,g,y,T;return v=i,g=i,null!==(e=fe())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&a('":"')),null!==s&&null!==(l=fe())?(58===n.charCodeAt(i)?(u=":",i++):(u=null,0===o&&a('":"')),null!==u&&null!==(c=fe())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&a('":"')),null!==h&&null!==(d=fe())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&a('":"')),null!==f&&null!==(_=fe())?(58===n.charCodeAt(i)?(p=":",i++):(p=null,0===o&&a('":"')),null!==p&&null!==(m=_e())?e=[e,t,r,s,l,u,c,h,d,f,_,p,m]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===n.substr(i,2)?(e="::",i+=2):(e=null,0===o&&a('"::"')),null!==e&&null!==(t=fe())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=fe())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=fe())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&a('":"')),null!==c&&null!==(h=fe())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&a('":"')),null!==d&&null!==(f=fe())?(58===n.charCodeAt(i)?(_=":",i++):(_=null,0===o&&a('":"')),null!==_&&null!==(p=_e())?e=[e,t,r,s,l,u,c,h,d,f,_,p]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===n.substr(i,2)?(e="::",i+=2):(e=null,0===o&&a('"::"')),null!==e&&null!==(t=fe())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=fe())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=fe())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&a('":"')),null!==c&&null!==(h=fe())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&a('":"')),null!==d&&null!==(f=_e())?e=[e,t,r,s,l,u,c,h,d,f]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===n.substr(i,2)?(e="::",i+=2):(e=null,0===o&&a('"::"')),null!==e&&null!==(t=fe())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=fe())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=fe())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&a('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,u,c,h]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===n.substr(i,2)?(e="::",i+=2):(e=null,0===o&&a('"::"')),null!==e&&null!==(t=fe())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=fe())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=_e())?e=[e,t,r,s,l,u]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===n.substr(i,2)?(e="::",i+=2):(e=null,0===o&&a('"::"')),null!==e&&null!==(t=fe())?(58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=_e())?e=[e,t,r,s]:(e=null,i=g)):(e=null,i=g),null===e&&(g=i,"::"===n.substr(i,2)?(e="::",i+=2):(e=null,0===o&&a('"::"')),null!==e&&null!==(t=_e())?e=[e,t]:(e=null,i=g),null===e&&(g=i,"::"===n.substr(i,2)?(e="::",i+=2):(e=null,0===o&&a('"::"')),null!==e&&null!==(t=fe())?e=[e,t]:(e=null,i=g),null===e&&(g=i,null!==(e=fe())?("::"===n.substr(i,2)?(t="::",i+=2):(t=null,0===o&&a('"::"')),null!==t&&null!==(r=fe())?(58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&a('":"')),null!==s&&null!==(l=fe())?(58===n.charCodeAt(i)?(u=":",i++):(u=null,0===o&&a('":"')),null!==u&&null!==(c=fe())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&a('":"')),null!==h&&null!==(d=fe())?(58===n.charCodeAt(i)?(f=":",i++):(f=null,0===o&&a('":"')),null!==f&&null!==(_=_e())?e=[e,t,r,s,l,u,c,h,d,f,_]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=fe())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?t=[t,r]:(t=null,i=y),null!==(t=null!==t?t:"")?("::"===n.substr(i,2)?(r="::",i+=2):(r=null,0===o&&a('"::"')),null!==r&&null!==(s=fe())?(58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=fe())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&a('":"')),null!==c&&null!==(h=fe())?(58===n.charCodeAt(i)?(d=":",i++):(d=null,0===o&&a('":"')),null!==d&&null!==(f=_e())?e=[e,t,r,s,l,u,c,h,d,f]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=fe())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?t=[t,r]:(t=null,i=y),null!==(t=null!==t?t:"")?(y=i,58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=fe())?r=[r,s]:(r=null,i=y),null!==(r=null!==r?r:"")?("::"===n.substr(i,2)?(s="::",i+=2):(s=null,0===o&&a('"::"')),null!==s&&null!==(l=fe())?(58===n.charCodeAt(i)?(u=":",i++):(u=null,0===o&&a('":"')),null!==u&&null!==(c=fe())?(58===n.charCodeAt(i)?(h=":",i++):(h=null,0===o&&a('":"')),null!==h&&null!==(d=_e())?e=[e,t,r,s,l,u,c,h,d]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=fe())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?t=[t,r]:(t=null,i=y),null!==(t=null!==t?t:"")?(y=i,58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=fe())?r=[r,s]:(r=null,i=y),null!==(r=null!==r?r:"")?(y=i,58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&a('":"')),null!==s&&null!==(l=fe())?s=[s,l]:(s=null,i=y),null!==(s=null!==s?s:"")?("::"===n.substr(i,2)?(l="::",i+=2):(l=null,0===o&&a('"::"')),null!==l&&null!==(u=fe())?(58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&a('":"')),null!==c&&null!==(h=_e())?e=[e,t,r,s,l,u,c,h]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=fe())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?t=[t,r]:(t=null,i=y),null!==(t=null!==t?t:"")?(y=i,58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=fe())?r=[r,s]:(r=null,i=y),null!==(r=null!==r?r:"")?(y=i,58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&a('":"')),null!==s&&null!==(l=fe())?s=[s,l]:(s=null,i=y),null!==(s=null!==s?s:"")?(y=i,58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=fe())?l=[l,u]:(l=null,i=y),null!==(l=null!==l?l:"")?("::"===n.substr(i,2)?(u="::",i+=2):(u=null,0===o&&a('"::"')),null!==u&&null!==(c=_e())?e=[e,t,r,s,l,u,c]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=fe())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?t=[t,r]:(t=null,i=y),null!==(t=null!==t?t:"")?(y=i,58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=fe())?r=[r,s]:(r=null,i=y),null!==(r=null!==r?r:"")?(y=i,58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&a('":"')),null!==s&&null!==(l=fe())?s=[s,l]:(s=null,i=y),null!==(s=null!==s?s:"")?(y=i,58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=fe())?l=[l,u]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(u=":",i++):(u=null,0===o&&a('":"')),null!==u&&null!==(c=fe())?u=[u,c]:(u=null,i=y),null!==(u=null!==u?u:"")?("::"===n.substr(i,2)?(c="::",i+=2):(c=null,0===o&&a('"::"')),null!==c&&null!==(h=fe())?e=[e,t,r,s,l,u,c,h]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g),null===e&&(g=i,null!==(e=fe())?(y=i,58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?t=[t,r]:(t=null,i=y),null!==(t=null!==t?t:"")?(y=i,58===n.charCodeAt(i)?(r=":",i++):(r=null,0===o&&a('":"')),null!==r&&null!==(s=fe())?r=[r,s]:(r=null,i=y),null!==(r=null!==r?r:"")?(y=i,58===n.charCodeAt(i)?(s=":",i++):(s=null,0===o&&a('":"')),null!==s&&null!==(l=fe())?s=[s,l]:(s=null,i=y),null!==(s=null!==s?s:"")?(y=i,58===n.charCodeAt(i)?(l=":",i++):(l=null,0===o&&a('":"')),null!==l&&null!==(u=fe())?l=[l,u]:(l=null,i=y),null!==(l=null!==l?l:"")?(y=i,58===n.charCodeAt(i)?(u=":",i++):(u=null,0===o&&a('":"')),null!==u&&null!==(c=fe())?u=[u,c]:(u=null,i=y),null!==(u=null!==u?u:"")?(y=i,58===n.charCodeAt(i)?(c=":",i++):(c=null,0===o&&a('":"')),null!==c&&null!==(h=fe())?c=[c,h]:(c=null,i=y),null!==(c=null!==c?c:"")?("::"===n.substr(i,2)?(h="::",i+=2):(h=null,0===o&&a('"::"')),null!==h?e=[e,t,r,s,l,u,c,h]:(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g)):(e=null,i=g))))))))))))))),null!==e&&(T=v,jn.host_type="IPv6",e=n.substring(i,T)),null===e&&(i=v),e}function fe(){var e,t,n,r,s;return s=i,null!==(e=f())&&null!==(t=null!==(t=f())?t:"")&&null!==(n=null!==(n=f())?n:"")&&null!==(r=null!==(r=f())?r:"")?e=[e,t,n,r]:(e=null,i=s),e}function _e(){var e,t,r,s;return s=i,null!==(e=fe())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t&&null!==(r=fe())?e=[e,t,r]:(e=null,i=s)):(e=null,i=s),null===e&&(e=pe()),e}function pe(){var e,t,r,s,l,u,c,h,d,f;return h=i,d=i,null!==(e=me())?(46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&a('"."')),null!==t&&null!==(r=me())?(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&a('"."')),null!==s&&null!==(l=me())?(46===n.charCodeAt(i)?(u=".",i++):(u=null,0===o&&a('"."')),null!==u&&null!==(c=me())?e=[e,t,r,s,l,u,c]:(e=null,i=d)):(e=null,i=d)):(e=null,i=d)):(e=null,i=d),null!==e&&(f=h,jn.host_type="IPv4",e=n.substring(i,f)),null===e&&(i=h),e}function me(){var e,t,r,s;return s=i,"25"===n.substr(i,2)?(e="25",i+=2):(e=null,0===o&&a('"25"')),null!==e?(/^[0-5]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&a("[0-5]")),null!==t?e=[e,t]:(e=null,i=s)):(e=null,i=s),null===e&&(s=i,50===n.charCodeAt(i)?(e="2",i++):(e=null,0===o&&a('"2"')),null!==e?(/^[0-4]/.test(n.charAt(i))?(t=n.charAt(i),i++):(t=null,0===o&&a("[0-4]")),null!==t&&null!==(r=h())?e=[e,t,r]:(e=null,i=s)):(e=null,i=s),null===e&&(s=i,49===n.charCodeAt(i)?(e="1",i++):(e=null,0===o&&a('"1"')),null!==e&&null!==(t=h())&&null!==(r=h())?e=[e,t,r]:(e=null,i=s),null===e&&(s=i,/^[1-9]/.test(n.charAt(i))?(e=n.charAt(i),i++):(e=null,0===o&&a("[1-9]")),null!==e&&null!==(t=h())?e=[e,t]:(e=null,i=s),null===e&&(e=h())))),e}function ve(){var e,t,n,r,s,o,l,u;return o=i,l=i,null!==(e=null!==(e=h())?e:"")&&null!==(t=null!==(t=h())?t:"")&&null!==(n=null!==(n=h())?n:"")&&null!==(r=null!==(r=h())?r:"")&&null!==(s=null!==(s=h())?s:"")?e=[e,t,n,r,s]:(e=null,i=l),null!==e&&(u=e,u=parseInt(u.join("")),jn.port=u,e=u),null===e&&(i=o),e}function ge(){var e,t,r,s;for(e=[],s=i,59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&a('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);null!==t;)e.push(t),s=i,59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&a('";"')),null!==t&&null!==(r=ye())?t=[t,r]:(t=null,i=s);return e}function ye(){var e;return null===(e=Te())&&null===(e=Ce())&&null===(e=be())&&null===(e=Se())&&null===(e=Ee())&&null===(e=Ae())&&(e=Re()),e}function Te(){var e,t,r,s,l;return r=i,s=i,"transport="===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&a('"transport="')),null!==e?("udp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&a('"udp"')),null===t&&("tcp"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&a('"tcp"')),null===t&&("sctp"===n.substr(i,4).toLowerCase()?(t=n.substr(i,4),i+=4):(t=null,0===o&&a('"sctp"')),null===t&&("tls"===n.substr(i,3).toLowerCase()?(t=n.substr(i,3),i+=3):(t=null,0===o&&a('"tls"')),null===t&&(t=k())))),null!==t?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[1],jn.uri_params||(jn.uri_params={}),e=void(jn.uri_params.transport=l.toLowerCase())),null===e&&(i=r),e}function Ce(){var e,t,r,s,l;return r=i,s=i,"user="===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&a('"user="')),null!==e?("phone"===n.substr(i,5).toLowerCase()?(t=n.substr(i,5),i+=5):(t=null,0===o&&a('"phone"')),null===t&&("ip"===n.substr(i,2).toLowerCase()?(t=n.substr(i,2),i+=2):(t=null,0===o&&a('"ip"')),null===t&&(t=k())),null!==t?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[1],jn.uri_params||(jn.uri_params={}),e=void(jn.uri_params.user=l.toLowerCase())),null===e&&(i=r),e}function be(){var e,t,r,s,l;return r=i,s=i,"method="===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&a('"method="')),null!==e&&null!==(t=ct())?e=[e,t]:(e=null,i=s),null!==e&&(l=e[1],jn.uri_params||(jn.uri_params={}),e=void(jn.uri_params.method=l)),null===e&&(i=r),e}function Se(){var e,t,r,s,l;return r=i,s=i,"ttl="===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&a('"ttl="')),null!==e&&null!==(t=An())?e=[e,t]:(e=null,i=s),null!==e&&(l=e[1],jn.params||(jn.params={}),e=void(jn.params.ttl=l)),null===e&&(i=r),e}function Ee(){var e,t,r,s,l;return r=i,s=i,"maddr="===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&a('"maddr="')),null!==e&&null!==(t=le())?e=[e,t]:(e=null,i=s),null!==e&&(l=e[1],jn.uri_params||(jn.uri_params={}),e=void(jn.uri_params.maddr=l)),null===e&&(i=r),e}function Ae(){var e,t,r,s,l,u;return s=i,l=i,"lr"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&a('"lr"')),null!==e?(u=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&a('"="')),null!==t&&null!==(r=k())?t=[t,r]:(t=null,i=u),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=l)):(e=null,i=l),null!==e&&(jn.uri_params||(jn.uri_params={}),e=void(jn.uri_params.lr=void 0)),null===e&&(i=s),e}function Re(){var e,t,r,s,l,u,c,h;return s=i,l=i,null!==(e=we())?(u=i,61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&a('"="')),null!==t&&null!==(r=Ie())?t=[t,r]:(t=null,i=u),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=l)):(e=null,i=l),null!==e&&(c=e[0],h=e[1],jn.uri_params||(jn.uri_params={}),h=void 0===h?void 0:h[1],e=void(jn.uri_params[c.toLowerCase()]=h)),null===e&&(i=s),e}function we(){var e,t,n;if(n=i,null!==(t=Oe()))for(e=[];null!==t;)e.push(t),t=Oe();else e=null;return null!==e&&(e=e.join("")),null===e&&(i=n),e}function Ie(){var e,t,n;if(n=i,null!==(t=Oe()))for(e=[];null!==t;)e.push(t),t=Oe();else e=null;return null!==e&&(e=e.join("")),null===e&&(i=n),e}function Oe(){var e;return null===(e=Ne())&&null===(e=C())&&(e=S()),e}function Ne(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&a('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&a('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&a('"/"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&a('":"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&a('"&"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&a('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&a('"$"')))))))),e}function ke(){var e,t,r,s,l,u,c;if(u=i,63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&a('"?"')),null!==e)if(null!==(t=De())){for(r=[],c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&a('"&"')),null!==s&&null!==(l=De())?s=[s,l]:(s=null,i=c);null!==s;)r.push(s),c=i,38===n.charCodeAt(i)?(s="&",i++):(s=null,0===o&&a('"&"')),null!==s&&null!==(l=De())?s=[s,l]:(s=null,i=c);null!==r?e=[e,t,r]:(e=null,i=u)}else e=null,i=u;else e=null,i=u;return e}function De(){var e,t,r,s,l,u,c;return s=i,l=i,null!==(e=Ue())?(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&a('"="')),null!==t&&null!==(r=xe())?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(u=e[0],c=e[2],u=u.join("").toLowerCase(),c=c.join(""),jn.uri_headers||(jn.uri_headers={}),e=void(jn.uri_headers[u]?jn.uri_headers[u].push(c):jn.uri_headers[u]=[c])),null===e&&(i=s),e}function Ue(){var e,t;if(null===(t=Pe())&&null===(t=C())&&(t=S()),null!==t)for(e=[];null!==t;)e.push(t),null===(t=Pe())&&null===(t=C())&&(t=S());else e=null;return e}function xe(){var e,t;for(e=[],null===(t=Pe())&&null===(t=C())&&(t=S());null!==t;)e.push(t),null===(t=Pe())&&null===(t=C())&&(t=S());return e}function Pe(){var e;return 91===n.charCodeAt(i)?(e="[",i++):(e=null,0===o&&a('"["')),null===e&&(93===n.charCodeAt(i)?(e="]",i++):(e=null,0===o&&a('"]"')),null===e&&(47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&a('"/"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&a('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&a('":"')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&a('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&a('"$"')))))))),e}function Me(){var e,t,n,r,s,o;return o=i,null!==(e=ct())&&null!==(t=v())&&null!==(n=Le())&&null!==(r=v())&&null!==(s=et())?e=[e,t,n,r,s]:(e=null,i=o),e}function Le(){var e;return null===(e=Q())&&(e=qe()),e}function qe(){var e,t,r,s;return s=i,null!==(e=$e())?(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null!==t?(null===(r=He())&&(r=Ge()),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s)):(e=null,i=s),e}function He(){var e,t,r,s,l;return s=i,null===(e=Fe())&&(e=je()),null!==e?(l=i,63===n.charCodeAt(i)?(t="?",i++):(t=null,0===o&&a('"?"')),null!==t&&null!==(r=Ze())?t=[t,r]:(t=null,i=l),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),e}function Fe(){var e,t,r,s;return s=i,"//"===n.substr(i,2)?(e="//",i+=2):(e=null,0===o&&a('"//"')),null!==e&&null!==(t=Xe())&&null!==(r=null!==(r=je())?r:"")?e=[e,t,r]:(e=null,i=s),e}function je(){var e,t,r;return r=i,47===n.charCodeAt(i)?(e="/",i++):(e=null,0===o&&a('"/"')),null!==e&&null!==(t=Be())?e=[e,t]:(e=null,i=r),e}function Ge(){var e,t,n,r;if(r=i,null!==(e=Ve())){for(t=[],n=We();null!==n;)t.push(n),n=We();null!==t?e=[e,t]:(e=null,i=r)}else e=null,i=r;return e}function We(){var e;return null===(e=T())&&null===(e=C())&&(e=S()),e}function Ve(){var e;return null===(e=C())&&null===(e=S())&&(59===n.charCodeAt(i)?(e=";",i++):(e=null,0===o&&a('";"')),null===e&&(63===n.charCodeAt(i)?(e="?",i++):(e=null,0===o&&a('"?"')),null===e&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&a('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&a('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&a('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&a('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&a('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&a('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&a('","'))))))))))),e}function Be(){var e,t,r,s,l,u;if(l=i,null!==(e=Ke())){for(t=[],u=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&a('"/"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=u);null!==r;)t.push(r),u=i,47===n.charCodeAt(i)?(r="/",i++):(r=null,0===o&&a('"/"')),null!==r&&null!==(s=Ke())?r=[r,s]:(r=null,i=u);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ke(){var e,t,r,s,l,u;for(l=i,e=[],t=ze();null!==t;)e.push(t),t=ze();if(null!==e){for(t=[],u=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&a('";"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=u);null!==r;)t.push(r),u=i,59===n.charCodeAt(i)?(r=";",i++):(r=null,0===o&&a('";"')),null!==r&&null!==(s=Ye())?r=[r,s]:(r=null,i=u);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ye(){var e,t;for(e=[],t=ze();null!==t;)e.push(t),t=ze();return e}function ze(){var e;return null===(e=C())&&null===(e=S())&&(58===n.charCodeAt(i)?(e=":",i++):(e=null,0===o&&a('":"')),null===e&&(64===n.charCodeAt(i)?(e="@",i++):(e=null,0===o&&a('"@"')),null===e&&(38===n.charCodeAt(i)?(e="&",i++):(e=null,0===o&&a('"&"')),null===e&&(61===n.charCodeAt(i)?(e="=",i++):(e=null,0===o&&a('"="')),null===e&&(43===n.charCodeAt(i)?(e="+",i++):(e=null,0===o&&a('"+"')),null===e&&(36===n.charCodeAt(i)?(e="$",i++):(e=null,0===o&&a('"$"')),null===e&&(44===n.charCodeAt(i)?(e=",",i++):(e=null,0===o&&a('","'))))))))),e}function $e(){var e,t,r,s,l,u;if(s=i,l=i,null!==(e=d())){for(t=[],null===(r=d())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&a('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&a('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&a('"."')))));null!==r;)t.push(r),null===(r=d())&&null===(r=h())&&(43===n.charCodeAt(i)?(r="+",i++):(r=null,0===o&&a('"+"')),null===r&&(45===n.charCodeAt(i)?(r="-",i++):(r=null,0===o&&a('"-"')),null===r&&(46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&a('"."')))));null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return null!==e&&(u=s,e=void(jn.scheme=n.substring(i,u))),null===e&&(i=s),e}function Xe(){var e;return null===(e=Je())&&(e=Qe()),e}function Je(){var e,t,r,s;return r=i,s=i,null!==(e=ne())?(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&a('"@"')),null!==t?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==(e=null!==e?e:"")&&null!==(t=oe())?e=[e,t]:(e=null,i=r),e=null!==e?e:""}function Qe(){var e,t;if(null===(t=C())&&null===(t=S())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&a('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&a('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&a('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&a('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&a('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&a('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&a('"+"')))))))))),null!==t)for(e=[];null!==t;)e.push(t),null===(t=C())&&null===(t=S())&&(36===n.charCodeAt(i)?(t="$",i++):(t=null,0===o&&a('"$"')),null===t&&(44===n.charCodeAt(i)?(t=",",i++):(t=null,0===o&&a('","')),null===t&&(59===n.charCodeAt(i)?(t=";",i++):(t=null,0===o&&a('";"')),null===t&&(58===n.charCodeAt(i)?(t=":",i++):(t=null,0===o&&a('":"')),null===t&&(64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&a('"@"')),null===t&&(38===n.charCodeAt(i)?(t="&",i++):(t=null,0===o&&a('"&"')),null===t&&(61===n.charCodeAt(i)?(t="=",i++):(t=null,0===o&&a('"="')),null===t&&(43===n.charCodeAt(i)?(t="+",i++):(t=null,0===o&&a('"+"'))))))))));else e=null;return e}function Ze(){var e,t;for(e=[],t=We();null!==t;)e.push(t),t=We();return e}function et(){var e,t,r,s,l,u,c,d,f;if(c=i,d=i,"sip"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&a('"SIP"')),null!==e)if(47===n.charCodeAt(i)?(t="/",i++):(t=null,0===o&&a('"/"')),null!==t){if(null!==(s=h()))for(r=[];null!==s;)r.push(s),s=h();else r=null;if(null!==r)if(46===n.charCodeAt(i)?(s=".",i++):(s=null,0===o&&a('"."')),null!==s){if(null!==(u=h()))for(l=[];null!==u;)l.push(u),u=h();else l=null;null!==l?e=[e,t,r,s,l]:(e=null,i=d)}else e=null,i=d;else e=null,i=d}else e=null,i=d;else e=null,i=d;return null!==e&&(f=c,e=void(jn.sip_version=n.substring(i,f))),null===e&&(i=c),e}function tt(){var e;return"INVITE"===n.substr(i,6)?(e="INVITE",i+=6):(e=null,0===o&&a('"INVITE"')),e}function nt(){var e;return"ACK"===n.substr(i,3)?(e="ACK",i+=3):(e=null,0===o&&a('"ACK"')),e}function rt(){var e;return"OPTIONS"===n.substr(i,7)?(e="OPTIONS",i+=7):(e=null,0===o&&a('"OPTIONS"')),e}function st(){var e;return"BYE"===n.substr(i,3)?(e="BYE",i+=3):(e=null,0===o&&a('"BYE"')),e}function it(){var e;return"CANCEL"===n.substr(i,6)?(e="CANCEL",i+=6):(e=null,0===o&&a('"CANCEL"')),e}function ot(){var e;return"REGISTER"===n.substr(i,8)?(e="REGISTER",i+=8):(e=null,0===o&&a('"REGISTER"')),e}function lt(){var e;return"SUBSCRIBE"===n.substr(i,9)?(e="SUBSCRIBE",i+=9):(e=null,0===o&&a('"SUBSCRIBE"')),e}function ut(){var e;return"NOTIFY"===n.substr(i,6)?(e="NOTIFY",i+=6):(e=null,0===o&&a('"NOTIFY"')),e}function at(){var e;return"REFER"===n.substr(i,5)?(e="REFER",i+=5):(e=null,0===o&&a('"REFER"')),e}function ct(){var e,t,r;return t=i,null===(e=tt())&&null===(e=nt())&&null===(e=rt())&&null===(e=st())&&null===(e=it())&&null===(e=ot())&&null===(e=lt())&&null===(e=ut())&&null===(e=at())&&(e=k()),null!==e&&(r=t,jn.method=n.substring(i,r),e=jn.method),null===e&&(i=t),e}function ht(){var e,t,n,r,s,o;return o=i,null!==(e=et())&&null!==(t=v())&&null!==(n=dt())&&null!==(r=v())&&null!==(s=_t())?e=[e,t,n,r,s]:(e=null,i=o),e}function dt(){var e,t,n;return t=i,null!==(e=ft())&&(n=e,e=void(jn.status_code=parseInt(n.join("")))),null===e&&(i=t),e}function ft(){var e,t,n,r;return r=i,null!==(e=h())&&null!==(t=h())&&null!==(n=h())?e=[e,t,n]:(e=null,i=r),e}function _t(){var e,t,r,s;for(r=i,e=[],null===(t=T())&&null===(t=C())&&null===(t=S())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());null!==t;)e.push(t),null===(t=T())&&null===(t=C())&&null===(t=S())&&null===(t=O())&&null===(t=N())&&null===(t=v())&&(t=g());return null!==e&&(s=r,e=void(jn.reason_phrase=n.substring(i,s))),null===e&&(i=r),e}function pt(){var e,t,n,r,s,o,l;if(s=i,o=i,null===(e=J())&&(e=mt()),null!==e){for(t=[],l=i,null!==(n=G())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=G())&&null!==(r=gt())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;return null!==e&&(e=function(e){var t;jn.multi_header||(jn.multi_header=[]);try{t=new Fn(jn.uri,jn.display_name,jn.params),delete jn.uri,delete jn.display_name,delete jn.params}catch(e){t=null}jn.multi_header.push({possition:i,offset:e,parsed:t})}(s)),null===e&&(i=s),e}function mt(){var e,t,n,r,s;return s=i,null!==(e=null!==(e=vt())?e:"")&&null!==(t=F())&&null!==(n=Q())&&null!==(r=H())?e=[e,t,n,r]:(e=null,i=s),e}function vt(){var e,t,n,r,s,o,l,u;if(s=i,o=i,null!==(e=k())){for(t=[],l=i,null!==(n=E())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=E())&&null!==(r=k())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;return null===e&&(e=z()),null!==e&&(u=e,e=void(jn.display_name="string"==typeof u?u:u[1].reduce(function(e,t){return e+t[0]+t[1]},u[0]))),null===e&&(i=s),e}function gt(){var e;return null===(e=yt())&&null===(e=Tt())&&(e=St()),e}function yt(){var e,t,r,s,l,u;return s=i,l=i,"q"===n.substr(i,1).toLowerCase()?(e=n.substr(i,1),i++):(e=null,0===o&&a('"q"')),null!==e&&null!==(t=M())&&null!==(r=bt())?e=[e,t,r]:(e=null,i=l),null!==e&&(u=e[2],jn.params||(jn.params={}),e=void(jn.params.q=u)),null===e&&(i=s),e}function Tt(){var e,t,r,s,l,u;return s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&a('"expires"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(u=e[2],jn.params||(jn.params={}),e=void(jn.params.expires=u)),null===e&&(i=s),e}function Ct(){var e,t,n;if(n=i,null!==(t=h()))for(e=[];null!==t;)e.push(t),t=h();else e=null;return null!==e&&(e=parseInt(e.join(""))),null===e&&(i=n),e}function bt(){var e,t,r,s,l,u,c,d,f;return u=i,c=i,48===n.charCodeAt(i)?(e="0",i++):(e=null,0===o&&a('"0"')),null!==e?(d=i,46===n.charCodeAt(i)?(t=".",i++):(t=null,0===o&&a('"."')),null!==t&&null!==(r=null!==(r=h())?r:"")&&null!==(s=null!==(s=h())?s:"")&&null!==(l=null!==(l=h())?l:"")?t=[t,r,s,l]:(t=null,i=d),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=c)):(e=null,i=c),null!==e&&(f=u,e=parseFloat(n.substring(i,f))),null===e&&(i=u),e}function St(){var e,t,n,r,s,o,l,u;return r=i,s=i,null!==(e=k())?(o=i,null!==(t=M())&&null!==(n=Et())?t=[t,n]:(t=null,i=o),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),null!==e&&(l=e[0],u=e[1],jn.params||(jn.params={}),u=void 0===u?void 0:u[1],e=void(jn.params[l.toLowerCase()]=u)),null===e&&(i=r),e}function Et(){var e;return null===(e=k())&&null===(e=le())&&(e=Y()),e}function At(){var e;return"render"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&a('"render"')),null===e&&("session"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&a('"session"')),null===e&&("icon"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&a('"icon"')),null===e&&("alert"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&a('"alert"')),null===e&&(e=k())))),e}function Rt(){var e;return null===(e=wt())&&(e=St()),e}function wt(){var e,t,r,s;return s=i,"handling"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&a('"handling"')),null!==e&&null!==(t=M())?("optional"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&a('"optional"')),null===r&&("required"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&a('"required"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s),e}function It(){var e,t,n,r,s,o,l,u;if(l=i,null!==(e=Ot()))if(null!==(t=P()))if(null!==(n=xt())){for(r=[],u=i,null!==(s=G())&&null!==(o=Pt())?s=[s,o]:(s=null,i=u);null!==s;)r.push(s),u=i,null!==(s=G())&&null!==(o=Pt())?s=[s,o]:(s=null,i=u);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Ot(){var e;return null===(e=Nt())&&(e=kt()),e}function Nt(){var e;return"text"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&a('"text"')),null===e&&("image"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&a('"image"')),null===e&&("audio"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&a('"audio"')),null===e&&("video"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&a('"video"')),null===e&&("application"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&a('"application"')),null===e&&(e=Dt()))))),e}function kt(){var e;return"message"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&a('"message"')),null===e&&("multipart"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&a('"multipart"')),null===e&&(e=Dt())),e}function Dt(){var e;return null===(e=k())&&(e=Ut()),e}function Ut(){var e,t,r;return r=i,"x-"===n.substr(i,2).toLowerCase()?(e=n.substr(i,2),i+=2):(e=null,0===o&&a('"x-"')),null!==e&&null!==(t=k())?e=[e,t]:(e=null,i=r),e}function xt(){var e;return null===(e=Dt())&&(e=k()),e}function Pt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())&&null!==(n=Mt())?e=[e,t,n]:(e=null,i=r),e}function Mt(){var e;return null===(e=k())&&(e=Y()),e}function Lt(){var e,t,n,r;if(n=i,null!==(t=h()))for(e=[];null!==t;)e.push(t),t=h();else e=null;return null!==e&&(r=e,e=void(jn.value=parseInt(r.join("")))),null===e&&(i=n),e}function qt(){var e,t,r,s,l,u;if(l=i,null!==(e=D())){for(t=[],u=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&a('"."')),null!==r&&null!==(s=D())?r=[r,s]:(r=null,i=u);null!==r;)t.push(r),u=i,46===n.charCodeAt(i)?(r=".",i++):(r=null,0===o&&a('"."')),null!==r&&null!==(s=D())?r=[r,s]:(r=null,i=u);null!==t?e=[e,t]:(e=null,i=l)}else e=null,i=l;return e}function Ht(){var e;return null===(e=Ft())&&(e=St()),e}function Ft(){var e,t,r,s,l,u;return s=i,l=i,"tag"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&a('"tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(u=e[2],e=void(jn.tag=u)),null===e&&(i=s),e}function jt(){var e,t,r,s,l,u,c,h;if(c=i,"digest"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&a('"Digest"')),null!==e)if(null!==(t=E()))if(null!==(r=Vt())){for(s=[],h=i,null!==(l=j())&&null!==(u=Vt())?l=[l,u]:(l=null,i=h);null!==l;)s.push(l),h=i,null!==(l=j())&&null!==(u=Vt())?l=[l,u]:(l=null,i=h);null!==s?e=[e,t,r,s]:(e=null,i=c)}else e=null,i=c;else e=null,i=c;else e=null,i=c;return null===e&&(e=Gt()),e}function Gt(){var e,t,n,r,s,o,l,u;if(l=i,null!==(e=k()))if(null!==(t=E()))if(null!==(n=Wt())){for(r=[],u=i,null!==(s=j())&&null!==(o=Wt())?s=[s,o]:(s=null,i=u);null!==s;)r.push(s),u=i,null!==(s=j())&&null!==(o=Wt())?s=[s,o]:(s=null,i=u);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function Wt(){var e,t,n,r;return r=i,null!==(e=k())&&null!==(t=M())?(null===(n=k())&&(n=Y()),null!==n?e=[e,t,n]:(e=null,i=r)):(e=null,i=r),e}function Vt(){var e;return null===(e=Bt())&&null===(e=Yt())&&null===(e=$t())&&null===(e=Jt())&&null===(e=Qt())&&null===(e=Zt())&&null===(e=en())&&(e=Wt()),e}function Bt(){var e,t,r,s;return s=i,"realm"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&a('"realm"')),null!==e&&null!==(t=M())&&null!==(r=Kt())?e=[e,t,r]:(e=null,i=s),e}function Kt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.realm=n)),null===e&&(i=t),e}function Yt(){var e,t,r,s,l,u,c,h,d;if(h=i,"domain"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&a('"domain"')),null!==e)if(null!==(t=M()))if(null!==(r=V()))if(null!==(s=zt())){if(l=[],d=i,null!==(c=v()))for(u=[];null!==c;)u.push(c),c=v();else u=null;for(null!==u&&null!==(c=zt())?u=[u,c]:(u=null,i=d);null!==u;){if(l.push(u),d=i,null!==(c=v()))for(u=[];null!==c;)u.push(c),c=v();else u=null;null!==u&&null!==(c=zt())?u=[u,c]:(u=null,i=d)}null!==l&&null!==(u=B())?e=[e,t,r,s,l,u]:(e=null,i=h)}else e=null,i=h;else e=null,i=h;else e=null,i=h;else e=null,i=h;return e}function zt(){var e;return null===(e=qe())&&(e=je()),e}function $t(){var e,t,r,s;return s=i,"nonce"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&a('"nonce"')),null!==e&&null!==(t=M())&&null!==(r=Xt())?e=[e,t,r]:(e=null,i=s),e}function Xt(){var e,t,n;return t=i,null!==(e=z())&&(n=e,e=void(jn.nonce=n)),null===e&&(i=t),e}function Jt(){var e,t,r,s,l,u;return s=i,l=i,"opaque"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&a('"opaque"')),null!==e&&null!==(t=M())&&null!==(r=z())?e=[e,t,r]:(e=null,i=l),null!==e&&(u=e[2],e=void(jn.opaque=u)),null===e&&(i=s),e}function Qt(){var e,t,r,s,l;return s=i,"stale"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&a('"stale"')),null!==e&&null!==(t=M())?(l=i,"true"===n.substr(i,4).toLowerCase()?(r=n.substr(i,4),i+=4):(r=null,0===o&&a('"true"')),null!==r&&(r=void(jn.stale=!0)),null===r&&(i=l),null===r&&(l=i,"false"===n.substr(i,5).toLowerCase()?(r=n.substr(i,5),i+=5):(r=null,0===o&&a('"false"')),null!==r&&(r=void(jn.stale=!1)),null===r&&(i=l)),null!==r?e=[e,t,r]:(e=null,i=s)):(e=null,i=s),e}function Zt(){var e,t,r,s,l,u;return s=i,l=i,"algorithm"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&a('"algorithm"')),null!==e&&null!==(t=M())?("md5"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&a('"MD5"')),null===r&&("md5-sess"===n.substr(i,8).toLowerCase()?(r=n.substr(i,8),i+=8):(r=null,0===o&&a('"MD5-sess"')),null===r&&(r=k())),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(u=e[2],e=void(jn.algorithm=u.toUpperCase())),null===e&&(i=s),e}function en(){var e,t,r,s,l,u,c,h,d,f;if(h=i,"qop"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&a('"qop"')),null!==e)if(null!==(t=M()))if(null!==(r=V())){if(d=i,null!==(s=tn())){for(l=[],f=i,44===n.charCodeAt(i)?(u=",",i++):(u=null,0===o&&a('","')),null!==u&&null!==(c=tn())?u=[u,c]:(u=null,i=f);null!==u;)l.push(u),f=i,44===n.charCodeAt(i)?(u=",",i++):(u=null,0===o&&a('","')),null!==u&&null!==(c=tn())?u=[u,c]:(u=null,i=f);null!==l?s=[s,l]:(s=null,i=d)}else s=null,i=d;null!==s&&null!==(l=B())?e=[e,t,r,s,l]:(e=null,i=h)}else e=null,i=h;else e=null,i=h;else e=null,i=h;return e}function tn(){var e,t,r;return t=i,"auth-int"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&a('"auth-int"')),null===e&&("auth"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&a('"auth"')),null===e&&(e=k())),null!==e&&(r=e,jn.qop||(jn.qop=[]),e=void jn.qop.push(r.toLowerCase())),null===e&&(i=t),e}function nn(){var e,t,n,r,s,o,l;if(s=i,o=i,null!==(e=mt())){for(t=[],l=i,null!==(n=G())&&null!==(r=St())?n=[n,r]:(n=null,i=l);null!==n;)t.push(n),l=i,null!==(n=G())&&null!==(r=St())?n=[n,r]:(n=null,i=l);null!==t?e=[e,t]:(e=null,i=o)}else e=null,i=o;return null!==e&&(e=function(e){var t;jn.multi_header||(jn.multi_header=[]);try{t=new Fn(jn.uri,jn.display_name,jn.params),delete jn.uri,delete jn.display_name,delete jn.params}catch(e){t=null}jn.multi_header.push({possition:i,offset:e,parsed:t})}(s)),null===e&&(i=s),e}function rn(){var e;return null===(e=sn())&&(e=St()),e}function sn(){var e,t,r,s,l,u,c;if(l=i,u=i,"cause"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&a('"cause"')),null!==e)if(null!==(t=M())){if(null!==(s=h()))for(r=[];null!==s;)r.push(s),s=h();else r=null;null!==r?e=[e,t,r]:(e=null,i=u)}else e=null,i=u;else e=null,i=u;return null!==e&&(c=e[2],e=void(jn.cause=parseInt(c.join("")))),null===e&&(i=l),e}function on(){var e,t,n,r,s,o;if(s=i,null!==(e=mt())){for(t=[],o=i,null!==(n=G())&&null!==(r=St())?n=[n,r]:(n=null,i=o);null!==n;)t.push(n),o=i,null!==(n=G())&&null!==(r=St())?n=[n,r]:(n=null,i=o);null!==t?e=[e,t]:(e=null,i=s)}else e=null,i=s;return e}function ln(){var e,t,r;return t=i,"active"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&a('"active"')),null===e&&("pending"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&a('"pending"')),null===e&&("terminated"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&a('"terminated"')),null===e&&(e=k()))),null!==e&&(r=t,e=void(jn.state=n.substring(i,r))),null===e&&(i=t),e}function un(){var e,t,r,s,l,u,c,h;return s=i,l=i,"reason"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&a('"reason"')),null!==e&&null!==(t=M())&&null!==(r=an())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(u=e[2])&&(jn.reason=u))),null===e&&(i=s),null===e&&(s=i,l=i,"expires"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&a('"expires"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(h=e[2])&&(jn.expires=h))),null===e&&(i=s),null===e&&(s=i,l=i,"retry_after"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&a('"retry_after"')),null!==e&&null!==(t=M())&&null!==(r=Ct())?e=[e,t,r]:(e=null,i=l),null!==e&&(e=void(void 0!==(c=e[2])&&(jn.retry_after=c))),null===e&&(i=s),null===e&&(e=St()))),e}function an(){var e;return"deactivated"===n.substr(i,11).toLowerCase()?(e=n.substr(i,11),i+=11):(e=null,0===o&&a('"deactivated"')),null===e&&("probation"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&a('"probation"')),null===e&&("rejected"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&a('"rejected"')),null===e&&("timeout"===n.substr(i,7).toLowerCase()?(e=n.substr(i,7),i+=7):(e=null,0===o&&a('"timeout"')),null===e&&("giveup"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&a('"giveup"')),null===e&&("noresource"===n.substr(i,10).toLowerCase()?(e=n.substr(i,10),i+=10):(e=null,0===o&&a('"noresource"')),null===e&&("invariant"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&a('"invariant"')),null===e&&(e=k()))))))),e}function cn(){var e;return null===(e=Ft())&&(e=St()),e}function hn(){var e,t,n,r,s,o,l,u;if(l=i,null!==(e=yn()))if(null!==(t=E()))if(null!==(n=bn())){for(r=[],u=i,null!==(s=G())&&null!==(o=dn())?s=[s,o]:(s=null,i=u);null!==s;)r.push(s),u=i,null!==(s=G())&&null!==(o=dn())?s=[s,o]:(s=null,i=u);null!==r?e=[e,t,n,r]:(e=null,i=l)}else e=null,i=l;else e=null,i=l;else e=null,i=l;return e}function dn(){var e;return null===(e=fn())&&null===(e=_n())&&null===(e=pn())&&null===(e=mn())&&null===(e=vn())&&(e=St()),e}function fn(){var e,t,r,s,l,u;return s=i,l=i,"ttl"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&a('"ttl"')),null!==e&&null!==(t=M())&&null!==(r=An())?e=[e,t,r]:(e=null,i=l),null!==e&&(u=e[2],e=void(jn.ttl=u)),null===e&&(i=s),e}function _n(){var e,t,r,s,l,u;return s=i,l=i,"maddr"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&a('"maddr"')),null!==e&&null!==(t=M())&&null!==(r=le())?e=[e,t,r]:(e=null,i=l),null!==e&&(u=e[2],e=void(jn.maddr=u)),null===e&&(i=s),e}function pn(){var e,t,r,s,l,u;return s=i,l=i,"received"===n.substr(i,8).toLowerCase()?(e=n.substr(i,8),i+=8):(e=null,0===o&&a('"received"')),null!==e&&null!==(t=M())?(null===(r=pe())&&(r=de()),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(u=e[2],e=void(jn.received=u)),null===e&&(i=s),e}function mn(){var e,t,r,s,l,u;return s=i,l=i,"branch"===n.substr(i,6).toLowerCase()?(e=n.substr(i,6),i+=6):(e=null,0===o&&a('"branch"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(u=e[2],e=void(jn.branch=u)),null===e&&(i=s),e}function vn(){var e,t,r,s,l;return s=i,"rport"===n.substr(i,5).toLowerCase()?(e=n.substr(i,5),i+=5):(e=null,0===o&&a('"rport"')),null!==e?(l=i,null!==(t=M())&&null!==(r=gn())?t=[t,r]:(t=null,i=l),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=s)):(e=null,i=s),e}function gn(){var e,t,n,r,s,o,l,u;return o=i,l=i,null!==(e=null!==(e=h())?e:"")&&null!==(t=null!==(t=h())?t:"")&&null!==(n=null!==(n=h())?n:"")&&null!==(r=null!==(r=h())?r:"")&&null!==(s=null!==(s=h())?s:"")?e=[e,t,n,r,s]:(e=null,i=l),null!==e&&(u=e,e=void(jn.rport=parseInt(u.join("")))),null===e&&(i=o),e}function yn(){var e,t,n,r,s,o;return o=i,null!==(e=Tn())&&null!==(t=P())&&null!==(n=k())&&null!==(r=P())&&null!==(s=Cn())?e=[e,t,n,r,s]:(e=null,i=o),e}function Tn(){var e,t,r;return t=i,"sip"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&a('"SIP"')),null===e&&(e=k()),null!==e&&(r=e,e=void(jn.protocol=r)),null===e&&(i=t),e}function Cn(){var e,t,r;return t=i,"udp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&a('"UDP"')),null===e&&("tcp"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&a('"TCP"')),null===e&&("tls"===n.substr(i,3).toLowerCase()?(e=n.substr(i,3),i+=3):(e=null,0===o&&a('"TLS"')),null===e&&("sctp"===n.substr(i,4).toLowerCase()?(e=n.substr(i,4),i+=4):(e=null,0===o&&a('"SCTP"')),null===e&&(e=k())))),null!==e&&(r=e,e=void(jn.transport=r)),null===e&&(i=t),e}function bn(){var e,t,n,r,s;return r=i,null!==(e=Sn())?(s=i,null!==(t=W())&&null!==(n=En())?t=[t,n]:(t=null,i=s),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=r)):(e=null,i=r),e}function Sn(){var e,t,r;return t=i,null===(e=pe())&&null===(e=he())&&(e=ue()),null!==e&&(r=t,e=void(jn.host=n.substring(i,r))),null===e&&(i=t),e}function En(){var e,t,n,r,s,o,l,u;return o=i,l=i,null!==(e=null!==(e=h())?e:"")&&null!==(t=null!==(t=h())?t:"")&&null!==(n=null!==(n=h())?n:"")&&null!==(r=null!==(r=h())?r:"")&&null!==(s=null!==(s=h())?s:"")?e=[e,t,n,r,s]:(e=null,i=l),null!==e&&(u=e,e=void(jn.port=parseInt(u.join("")))),null===e&&(i=o),e}function An(){var e,t,n,r,s;return r=i,s=i,null!==(e=h())&&null!==(t=null!==(t=h())?t:"")&&null!==(n=null!==(n=h())?n:"")?e=[e,t,n]:(e=null,i=s),null!==e&&(e=parseInt(e.join(""))),null===e&&(i=r),e}function Rn(){var e,t,n;return t=i,null!==(e=Ct())&&(n=e,e=void(jn.expires=n)),null===e&&(i=t),e}function wn(){var e;return null===(e=In())&&(e=St()),e}function In(){var e,t,r,s,l,u;return s=i,l=i,"refresher"===n.substr(i,9).toLowerCase()?(e=n.substr(i,9),i+=9):(e=null,0===o&&a('"refresher"')),null!==e&&null!==(t=M())?("uac"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&a('"uac"')),null===r&&("uas"===n.substr(i,3).toLowerCase()?(r=n.substr(i,3),i+=3):(r=null,0===o&&a('"uas"'))),null!==r?e=[e,t,r]:(e=null,i=l)):(e=null,i=l),null!==e&&(u=e[2],e=void(jn.refresher=u.toLowerCase())),null===e&&(i=s),e}function On(){var e,t;for(e=[],null===(t=I())&&null===(t=N())&&(t=E());null!==t;)e.push(t),null===(t=I())&&null===(t=N())&&(t=E());return e}function Nn(){var e,t,r,s,l,u,c,h,d,f,_,p;return f=i,_=i,null!==(e=Dn())?(45===n.charCodeAt(i)?(t="-",i++):(t=null,0===o&&a('"-"')),null!==t&&null!==(r=kn())?(45===n.charCodeAt(i)?(s="-",i++):(s=null,0===o&&a('"-"')),null!==s&&null!==(l=kn())?(45===n.charCodeAt(i)?(u="-",i++):(u=null,0===o&&a('"-"')),null!==u&&null!==(c=kn())?(45===n.charCodeAt(i)?(h="-",i++):(h=null,0===o&&a('"-"')),null!==h&&null!==(d=Un())?e=[e,t,r,s,l,u,c,h,d]:(e=null,i=_)):(e=null,i=_)):(e=null,i=_)):(e=null,i=_)):(e=null,i=_),null!==e&&(p=f,e[0],e=void(jn=n.substring(i+5,p))),null===e&&(i=f),e}function kn(){var e,t,n,r,s;return s=i,null!==(e=f())&&null!==(t=f())&&null!==(n=f())&&null!==(r=f())?e=[e,t,n,r]:(e=null,i=s),e}function Dn(){var e,t,n;return n=i,null!==(e=kn())&&null!==(t=kn())?e=[e,t]:(e=null,i=n),e}function Un(){var e,t,n,r;return r=i,null!==(e=kn())&&null!==(t=kn())&&null!==(n=kn())?e=[e,t,n]:(e=null,i=r),e}function xn(){var e,t,r,s,l,u,c;return s=i,l=i,null!==(e=U())?(u=i,64===n.charCodeAt(i)?(t="@",i++):(t=null,0===o&&a('"@"')),null!==t&&null!==(r=U())?t=[t,r]:(t=null,i=u),null!==(t=null!==t?t:"")?e=[e,t]:(e=null,i=l)):(e=null,i=l),null!==e&&(c=s,e=void(jn.call_id=n.substring(i,c))),null===e&&(i=s),e}function Pn(){var e;return null===(e=Mn())&&null===(e=Ln())&&null===(e=qn())&&(e=St()),e}function Mn(){var e,t,r,s,l,u;return s=i,l=i,"to-tag"===n.substr(i,6)?(e="to-tag",i+=6):(e=null,0===o&&a('"to-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(u=e[2],e=void(jn.to_tag=u)),null===e&&(i=s),e}function Ln(){var e,t,r,s,l,u;return s=i,l=i,"from-tag"===n.substr(i,8)?(e="from-tag",i+=8):(e=null,0===o&&a('"from-tag"')),null!==e&&null!==(t=M())&&null!==(r=k())?e=[e,t,r]:(e=null,i=l),null!==e&&(u=e[2],e=void(jn.from_tag=u)),null===e&&(i=s),e}function qn(){var e,t;return t=i,"early-only"===n.substr(i,10)?(e="early-only",i+=10):(e=null,0===o&&a('"early-only"')),null!==e&&(e=void(jn.early_only=!0)),null===e&&(i=t),e}var Hn=e("./URI"),Fn=e("./NameAddrHeader"),jn={};if(null===s[r]()||i!==n.length){var Gn=Math.max(i,l),Wn=Gn2&&void 0!==arguments[2]?arguments[2]:{},s=e;if(void 0===e||void 0===t)throw new TypeError("Not enough arguments");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(s));var i=d.cloneArray(r.extraHeaders),o=d.cloneObject(r.eventHandlers),l=r.contentType||"text/plain";for(var u in o)Object.prototype.hasOwnProperty.call(o,u)&&this.on(u,o[u]);i.push("Content-Type: ".concat(l)),this._request=new h.OutgoingRequest(c.MESSAGE,e,this._ua,null,i),t&&(this._request.body=t);var a=new f(this._ua,this._request,{onRequestTimeout:function(){n._onRequestTimeout()},onTransportError:function(){n._onTransportError()},onReceiveResponse:function(e){n._receiveResponse(e)}});this._newMessage("local",this._request),a.send()}},{key:"init_incoming",value:function(e){this._request=e,this._newMessage("remote",e),this._is_replied||(this._is_replied=!0,e.reply(200)),this._close()}},{key:"accept",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=d.cloneArray(e.extraHeaders),n=e.body;if("incoming"!==this._direction)throw new _.NotSupportedError('"accept" not supported for outgoing Message');if(this._is_replied)throw new Error("incoming Message already replied");this._is_replied=!0,this._request.reply(200,null,t,n)}},{key:"reject",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.status_code||480,n=e.reason_phrase,r=d.cloneArray(e.extraHeaders),s=e.body;if("incoming"!==this._direction)throw new _.NotSupportedError('"reject" not supported for outgoing Message');if(this._is_replied)throw new Error("incoming Message already replied");if(t<300||t>=700)throw new TypeError("Invalid status_code: ".concat(t));this._is_replied=!0,this._request.reply(t,n,r,s)}},{key:"_receiveResponse",value:function(e){if(!this._closed)switch(!0){case/^1[0-9]{2}$/.test(e.status_code):break;case/^2[0-9]{2}$/.test(e.status_code):this._succeeded("remote",e);break;default:var t=d.sipErrorCause(e.status_code);this._failed("remote",e,t)}}},{key:"_onRequestTimeout",value:function(){this._closed||this._failed("system",null,c.causes.REQUEST_TIMEOUT)}},{key:"_onTransportError",value:function(){this._closed||this._failed("system",null,c.causes.CONNECTION_ERROR)}},{key:"_close",value:function(){this._closed=!0,this._ua.destroyMessage(this)}},{key:"_newMessage",value:function(e,t){"remote"===e?(this._direction="incoming",this._local_identity=t.to,this._remote_identity=t.from):"local"===e&&(this._direction="outgoing",this._local_identity=t.from,this._remote_identity=t.to),this._ua.newMessage(this,{originator:e,message:this,request:t})}},{key:"_failed",value:function(e,t,n){p.debug("MESSAGE failed"),this._close(),p.debug('emit "failed"'),this.emit("failed",{originator:e,response:t||null,cause:n})}},{key:"_succeeded",value:function(e,t){p.debug("MESSAGE succeeded"),this._close(),p.debug('emit "succeeded"'),this.emit("succeeded",{originator:e,response:t})}},{key:"direction",get:function(){return this._direction}},{key:"local_identity",get:function(){return this._local_identity}},{key:"remote_identity",get:function(){return this._remote_identity}}])&&s(t.prototype,n),r&&s(t,r),a}()},{"./Constants":2,"./Exceptions":6,"./Logger":9,"./RequestSender":19,"./SIPMessage":20,"./Utils":27,events:30}],11:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,t)&&(e+=";".concat(t),null!==this._parameters[t]&&(e+="=".concat(this._parameters[t])));return e}},{key:"uri",get:function(){return this._uri}},{key:"display_name",get:function(){return this._display_name},set:function(e){this._display_name=0===e?"0":e}}]),e}()},{"./Grammar":7,"./URI":26}],12:[function(e,t,n){"use strict";function r(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return s(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return s(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,l=!0,u=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return l=e.done,e},e:function(e){u=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(u)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:s}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,l=!0,u=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return l=e.done,e},e:function(e){u=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(u)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;w.debug("connect()");var r=e,s=v.cloneObject(t.eventHandlers),i=v.cloneArray(t.extraHeaders),o=v.cloneObject(t.mediaConstraints,{audio:!0,video:!0}),l=t.mediaStream||null,u=v.cloneObject(t.pcConfig,{iceServers:[]}),a=t.rtcConstraints||null,c=t.rtcOfferConstraints||null;if(this._rtcOfferConstraints=c,this._rtcAnswerConstraints=t.rtcAnswerConstraints||null,this._data=t.data||this._data,void 0===e)throw new TypeError("Not enough arguments");if(this._status!==I.STATUS_NULL)throw new p.InvalidStateError(this._status);if(!window.RTCPeerConnection)throw new p.NotSupportedError("WebRTC not supported");if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));for(var h in this._sessionTimers.enabled&&v.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=_.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=_.SESSION_EXPIRES),s)Object.prototype.hasOwnProperty.call(s,h)&&this.on(h,s[h]);this._from_tag=v.newTag();var d=t.anonymous||!1,f={from_tag:this._from_tag};this._contact=this._ua.contact.toString({anonymous:d,outbound:!0}),d?(f.from_display_name="Anonymous",f.from_uri=new R("sip","anonymous","anonymous.invalid"),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString())),i.push("Privacy: id")):t.fromUserName&&(f.from_uri=new R("sip",t.fromUserName,this._ua.configuration.uri.host),i.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()))),t.fromDisplayName&&(f.from_display_name=t.fromDisplayName),i.push("Contact: ".concat(this._contact)),i.push("Content-Type: application/sdp"),this._sessionTimers.enabled&&i.push("Session-Expires: ".concat(this._sessionTimers.defaultExpires).concat(this._ua.configuration.session_timers_force_refresher?";refresher=uac":"")),this._request=new y.InitialOutgoingInviteRequest(e,this._ua,f,i),this._id=this._request.call_id+this._from_tag,this._createRTCConnection(u,a),this._direction="outgoing",this._local_identity=this._request.from,this._remote_identity=this._request.to,n&&n(this),this._newRTCSession("local",this._request),this._sendInitialRequest(o,c,l)}},{key:"init_incoming",value:function(e,t){var n,r=this;w.debug("init_incoming()");var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;e.body&&"application/sdp"!==s?e.reply(415):(this._status=I.STATUS_INVITE_RECEIVED,this._from_tag=e.from_tag,this._id=e.call_id+this._from_tag,this._request=e,this._contact=this._ua.contact.toString(),e.hasHeader("expires")&&(n=1e3*e.getHeader("expires")),e.to_tag=v.newTag(),this._createDialog(e,"UAS",!0)?(e.body?this._late_sdp=!1:this._late_sdp=!0,this._status=I.STATUS_WAITING_FOR_ANSWER,this._timers.userNoAnswerTimer=setTimeout(function(){e.reply(408),r._failed("local",null,_.causes.NO_ANSWER)},this._ua.configuration.no_answer_timeout),n&&(this._timers.expiresTimer=setTimeout(function(){r._status===I.STATUS_WAITING_FOR_ANSWER&&(e.reply(487),r._failed("system",null,_.causes.EXPIRES))},n)),this._direction="incoming",this._local_identity=e.to,this._remote_identity=e.from,t&&t(this),this._newRTCSession("remote",e),this._status!==I.STATUS_TERMINATED&&(e.reply(180,null,["Contact: ".concat(this._contact)]),this._progress("local",null))):e.reply(500,"Missing Contact header field"))}},{key:"answer",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};w.debug("answer()");var n=this._request,r=v.cloneArray(t.extraHeaders),i=v.cloneObject(t.mediaConstraints),o=t.mediaStream||null,l=v.cloneObject(t.pcConfig,{iceServers:[]}),u=t.rtcConstraints||null,a=t.rtcAnswerConstraints||null,c=v.cloneObject(t.rtcOfferConstraints),h=!1,d=!1,f=!1,m=!1;if(this._rtcAnswerConstraints=a,this._rtcOfferConstraints=t.rtcOfferConstraints||null,this._data=t.data||this._data,"incoming"!==this._direction)throw new p.NotSupportedError('"answer" not supported for outgoing RTCSession');if(this._status!==I.STATUS_WAITING_FOR_ANSWER)throw new p.InvalidStateError(this._status);if(this._sessionTimers.enabled&&v.isDecimal(t.sessionTimersExpires)&&(t.sessionTimersExpires>=_.MIN_SESSION_EXPIRES?this._sessionTimers.defaultExpires=t.sessionTimersExpires:this._sessionTimers.defaultExpires=_.SESSION_EXPIRES),this._status=I.STATUS_ANSWERED,this._createDialog(n,"UAS")){clearTimeout(this._timers.userNoAnswerTimer),r.unshift("Contact: ".concat(this._contact));var g=n.parseSDP();Array.isArray(g.media)||(g.media=[g.media]);var y,T=s(g.media);try{for(T.s();!(y=T.n()).done;){var C=y.value;"audio"===C.type&&(h=!0,C.direction&&"sendrecv"!==C.direction||(f=!0)),"video"===C.type&&(d=!0,C.direction&&"sendrecv"!==C.direction||(m=!0))}}catch(e){T.e(e)}finally{T.f()}if(o&&!1===i.audio){var b,S=s(o.getAudioTracks());try{for(S.s();!(b=S.n()).done;){var E=b.value;o.removeTrack(E)}}catch(e){S.e(e)}finally{S.f()}}if(o&&!1===i.video){var A,R=s(o.getVideoTracks());try{for(R.s();!(A=R.n()).done;){var O=A.value;o.removeTrack(O)}}catch(e){R.e(e)}finally{R.f()}}o||void 0!==i.audio||(i.audio=f),o||void 0!==i.video||(i.video=m),o||h||c.offerToReceiveAudio||(i.audio=!1),o||d||c.offerToReceiveVideo||(i.video=!1),this._createRTCConnection(l,u),Promise.resolve().then(function(){return o||(i.audio||i.video?(e._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(i).catch(function(t){if(e._status===I.STATUS_TERMINATED)throw new Error("terminated");throw n.reply(480),e._failed("local",null,_.causes.USER_DENIED_MEDIA_ACCESS),w.warn('emit "getusermediafailed" [error:%o]',t),e.emit("getusermediafailed",t),new Error("getUserMedia() failed")})):void 0)}).then(function(t){if(e._status===I.STATUS_TERMINATED)throw new Error("terminated");e._localMediaStream=t,t&&t.getTracks().forEach(function(n){e._connection.addTrack(n,t)})}).then(function(){if(!e._late_sdp){var t={originator:"remote",type:"offer",sdp:n.body};w.debug('emit "sdp"'),e.emit("sdp",t);var r=new RTCSessionDescription({type:"offer",sdp:t.sdp});return e._connectionPromiseQueue=e._connectionPromiseQueue.then(function(){return e._connection.setRemoteDescription(r)}).catch(function(t){throw n.reply(488),e._failed("system",null,_.causes.WEBRTC_ERROR),w.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',t),e.emit("peerconnection:setremotedescriptionfailed",t),new Error("peerconnection.setRemoteDescription() failed")}),e._connectionPromiseQueue}}).then(function(){if(e._status===I.STATUS_TERMINATED)throw new Error("terminated");return e._connecting(n),e._late_sdp?e._createLocalDescription("offer",e._rtcOfferConstraints).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")}):e._createLocalDescription("answer",a).catch(function(){throw n.reply(500),new Error("_createLocalDescription() failed")})}).then(function(t){if(e._status===I.STATUS_TERMINATED)throw new Error("terminated");e._handleSessionTimersInIncomingRequest(n,r),n.reply(200,null,r,t,function(){e._status=I.STATUS_WAITING_FOR_ACK,e._setInvite2xxTimer(n,t),e._setACKTimer(),e._accepted("local")},function(){e._failed("system",null,_.causes.CONNECTION_ERROR)})}).catch(function(t){e._status!==I.STATUS_TERMINATED&&w.warn(t)})}else n.reply(500,"Error creating dialog")}},{key:"terminate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};w.debug("terminate()");var n,r=t.cause||_.causes.BYE,s=v.cloneArray(t.extraHeaders),i=t.body,o=t.status_code,l=t.reason_phrase;if(this._status===I.STATUS_TERMINATED)throw new p.InvalidStateError(this._status);switch(this._status){case I.STATUS_NULL:case I.STATUS_INVITE_SENT:case I.STATUS_1XX_RECEIVED:if(w.debug("canceling session"),o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));o&&(l=l||_.REASON_PHRASE[o]||"",n="SIP ;cause=".concat(o,' ;text="').concat(l,'"')),this._status===I.STATUS_NULL||this._status===I.STATUS_INVITE_SENT?(this._is_canceled=!0,this._cancel_reason=n):this._status===I.STATUS_1XX_RECEIVED&&this._request.cancel(n),this._status=I.STATUS_CANCELED,this._failed("local",null,_.causes.CANCELED);break;case I.STATUS_WAITING_FOR_ANSWER:case I.STATUS_ANSWERED:if(w.debug("rejecting session"),(o=o||480)<300||o>=700)throw new TypeError("Invalid status_code: ".concat(o));this._request.reply(o,l,s,i),this._failed("local",null,_.causes.REJECTED);break;case I.STATUS_WAITING_FOR_ACK:case I.STATUS_CONFIRMED:if(w.debug("terminating session"),l=t.reason_phrase||_.REASON_PHRASE[o]||"",o&&(o<200||o>=700))throw new TypeError("Invalid status_code: ".concat(o));if(o&&s.push("Reason: SIP ;cause=".concat(o,'; text="').concat(l,'"')),this._status===I.STATUS_WAITING_FOR_ACK&&"incoming"===this._direction&&this._request.server_transaction.state!==m.C.STATUS_TERMINATED){var u=this._dialog;this.receiveRequest=function(t){t.method===_.ACK&&(e.sendRequest(_.BYE,{extraHeaders:s,body:i}),u.terminate())},this._request.server_transaction.on("stateChanged",function(){e._request.server_transaction.state===m.C.STATUS_TERMINATED&&(e.sendRequest(_.BYE,{extraHeaders:s,body:i}),u.terminate())}),this._ended("local",null,r),this._dialog=u,this._ua.newDialog(u)}else this.sendRequest(_.BYE,{extraHeaders:s,body:i}),this._ended("local",null,r)}}},{key:"sendDTMF",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};w.debug("sendDTMF() | tones: %s",e);var n=0,r=t.duration||null,s=t.interToneGap||null,i=t.transportType||_.DTMF_TRANSPORT.INFO;if(void 0===e)throw new TypeError("Not enough arguments");if(this._status!==I.STATUS_CONFIRMED&&this._status!==I.STATUS_WAITING_FOR_ACK)throw new p.InvalidStateError(this._status);if(i!==_.DTMF_TRANSPORT.INFO&&i!==_.DTMF_TRANSPORT.RFC2833)throw new TypeError("invalid transportType: ".concat(i));if("number"==typeof e&&(e=e.toString()),!e||"string"!=typeof e||!e.match(/^[0-9A-DR#*,]+$/i))throw new TypeError("Invalid tones: ".concat(e));if(r&&!v.isDecimal(r))throw new TypeError("Invalid tone duration: ".concat(r));if(r?rb.C.MAX_DURATION?(w.debug('"duration" value is greater than the maximum allowed, setting it to '.concat(b.C.MAX_DURATION," milliseconds")),r=b.C.MAX_DURATION):r=Math.abs(r):r=b.C.DEFAULT_DURATION,t.duration=r,s&&!v.isDecimal(s))throw new TypeError("Invalid interToneGap: ".concat(s));if(s?s=this._tones.length)return void(this._tones=null);var l=this._tones[n];n+=1;if(","===l)o=2e3;else{var u=new b(this);t.eventHandlers={onFailed:function(){i._tones=null}},u.send(l,t),o=r+s}setTimeout(e.bind(this),o)}.call(this));else{var o=this._getDTMFRTPSender();o&&(e=o.toneBuffer+e,o.insertDTMF(e,r,s))}}},{key:"sendInfo",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(w.debug("sendInfo()"),this._status!==I.STATUS_CONFIRMED&&this._status!==I.STATUS_WAITING_FOR_ACK)throw new p.InvalidStateError(this._status);new S(this).send(e,t,n)}},{key:"mute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!1};w.debug("mute()");var t=!1,n=!1;!1===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!0,this._toggleMuteAudio(!0)),!1===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!0,this._toggleMuteVideo(!0)),!0!==t&&!0!==n||this._onmute({audio:t,video:n})}},{key:"unmute",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{audio:!0,video:!0};w.debug("unmute()");var t=!1,n=!1;!0===this._audioMuted&&e.audio&&(t=!0,this._audioMuted=!1,!1===this._localHold&&this._toggleMuteAudio(!1)),!0===this._videoMuted&&e.video&&(n=!0,this._videoMuted=!1,!1===this._localHold&&this._toggleMuteVideo(!1)),!0!==t&&!0!==n||this._onunmute({audio:t,video:n})}},{key:"hold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(w.debug("hold()"),this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;if(!0===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!0,this._onhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:_.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Hold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"unhold",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;if(w.debug("unhold()"),this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;if(!1===this._localHold)return!1;if(!this._isReadyToReOffer())return!1;this._localHold=!1,this._onunhold("local");var r={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:_.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Unhold Failed"})}};return t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:r,extraHeaders:t.extraHeaders}),!0}},{key:"renegotiate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;w.debug("renegotiate()");var r=t.rtcOfferConstraints||null;if(this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;if(!this._isReadyToReOffer())return!1;var s={succeeded:function(){n&&n()},failed:function(){e.terminate({cause:_.causes.WEBRTC_ERROR,status_code:500,reason_phrase:"Media Renegotiation Failed"})}};return this._setLocalMediaStatus(),t.useUpdate?this._sendUpdate({sdpOffer:!0,eventHandlers:s,rtcOfferConstraints:r,extraHeaders:t.extraHeaders}):this._sendReinvite({eventHandlers:s,rtcOfferConstraints:r,extraHeaders:t.extraHeaders}),!0}},{key:"refer",value:function(e,t){var n=this;w.debug("refer()");var r=e;if(this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;if(!(e=this._ua.normalizeTarget(e)))throw new TypeError("Invalid target: ".concat(r));var s=new A(this);s.sendRefer(e,t);var i=s.id;return this._referSubscribers[i]=s,s.on("requestFailed",function(){delete n._referSubscribers[i]}),s.on("accepted",function(){delete n._referSubscribers[i]}),s.on("failed",function(){delete n._referSubscribers[i]}),s}},{key:"sendRequest",value:function(e,t){return w.debug("sendRequest()"),this._dialog.sendRequest(e,t)}},{key:"receiveRequest",value:function(e){var t=this;if(w.debug("receiveRequest()"),e.method===_.CANCEL)this._status!==I.STATUS_WAITING_FOR_ANSWER&&this._status!==I.STATUS_ANSWERED||(this._status=I.STATUS_CANCELED,this._request.reply(487),this._failed("remote",e,_.causes.CANCELED));else switch(e.method){case _.ACK:if(this._status!==I.STATUS_WAITING_FOR_ACK)return;if(this._status=I.STATUS_CONFIRMED,clearTimeout(this._timers.ackTimer),clearTimeout(this._timers.invite2xxTimer),this._late_sdp){if(!e.body){this.terminate({cause:_.causes.MISSING_SDP,status_code:400});break}var n={originator:"remote",type:"answer",sdp:e.body};w.debug('emit "sdp"'),this.emit("sdp",n);var r=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._connection.setRemoteDescription(r)}).then(function(){t._is_confirmed||t._confirmed("remote",e)}).catch(function(e){t.terminate({cause:_.causes.BAD_MEDIA_DESCRIPTION,status_code:488}),w.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else this._is_confirmed||this._confirmed("remote",e);break;case _.BYE:this._status===I.STATUS_CONFIRMED||this._status===I.STATUS_WAITING_FOR_ACK?(e.reply(200),this._ended("remote",e,_.causes.BYE)):this._status===I.STATUS_INVITE_RECEIVED||this._status===I.STATUS_WAITING_FOR_ANSWER?(e.reply(200),this._request.reply(487,"BYE Received"),this._ended("remote",e,_.causes.BYE)):e.reply(403,"Wrong Status");break;case _.INVITE:this._status===I.STATUS_CONFIRMED?e.hasHeader("replaces")?this._receiveReplaces(e):this._receiveReinvite(e):e.reply(403,"Wrong Status");break;case _.INFO:if(this._status===I.STATUS_1XX_RECEIVED||this._status===I.STATUS_WAITING_FOR_ANSWER||this._status===I.STATUS_ANSWERED||this._status===I.STATUS_WAITING_FOR_ACK||this._status===I.STATUS_CONFIRMED){var s=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0;s&&s.match(/^application\/dtmf-relay/i)?new b(this).init_incoming(e):void 0!==s?new S(this).init_incoming(e):e.reply(415)}else e.reply(403,"Wrong Status");break;case _.UPDATE:this._status===I.STATUS_CONFIRMED?this._receiveUpdate(e):e.reply(403,"Wrong Status");break;case _.REFER:this._status===I.STATUS_CONFIRMED?this._receiveRefer(e):e.reply(403,"Wrong Status");break;case _.NOTIFY:this._status===I.STATUS_CONFIRMED?this._receiveNotify(e):e.reply(403,"Wrong Status");break;default:e.reply(501)}}},{key:"onTransportError",value:function(){w.warn("onTransportError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:_.causes.CONNECTION_ERROR,cause:_.causes.CONNECTION_ERROR})}},{key:"onRequestTimeout",value:function(){w.warn("onRequestTimeout()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:408,reason_phrase:_.causes.REQUEST_TIMEOUT,cause:_.causes.REQUEST_TIMEOUT})}},{key:"onDialogError",value:function(){w.warn("onDialogError()"),this._status!==I.STATUS_TERMINATED&&this.terminate({status_code:500,reason_phrase:_.causes.DIALOG_ERROR,cause:_.causes.DIALOG_ERROR})}},{key:"newDTMF",value:function(e){w.debug("newDTMF()"),this.emit("newDTMF",e)}},{key:"newInfo",value:function(e){w.debug("newInfo()"),this.emit("newInfo",e)}},{key:"_isReadyToReOffer",value:function(){return this._rtcReady?this._dialog?!0!==this._dialog.uac_pending_reply&&!0!==this._dialog.uas_pending_reply||(w.debug("_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress"),!1):(w.debug("_isReadyToReOffer() | session not established yet"),!1):(w.debug("_isReadyToReOffer() | internal WebRTC status not ready"),!1)}},{key:"_close",value:function(){if(w.debug("close()"),this._localMediaStream&&this._localMediaStreamLocallyGenerated&&(w.debug("close() | closing local MediaStream"),v.closeMediaStream(this._localMediaStream)),this._status!==I.STATUS_TERMINATED){if(this._status=I.STATUS_TERMINATED,this._connection)try{this._connection.close()}catch(e){w.warn("close() | error closing the RTCPeerConnection: %o",e)}for(var e in this._timers)Object.prototype.hasOwnProperty.call(this._timers,e)&&clearTimeout(this._timers[e]);for(var t in clearTimeout(this._sessionTimers.timer),this._dialog&&(this._dialog.terminate(),delete this._dialog),this._earlyDialogs)Object.prototype.hasOwnProperty.call(this._earlyDialogs,t)&&(this._earlyDialogs[t].terminate(),delete this._earlyDialogs[t]);for(var n in this._referSubscribers)Object.prototype.hasOwnProperty.call(this._referSubscribers,n)&&delete this._referSubscribers[n];this._ua.destroyRTCSession(this)}}},{key:"_setInvite2xxTimer",value:function(e,t){var n=g.T1;this._timers.invite2xxTimer=setTimeout(function r(){this._status===I.STATUS_WAITING_FOR_ACK&&(e.reply(200,null,["Contact: ".concat(this._contact)],t),ng.T2&&(n=g.T2),this._timers.invite2xxTimer=setTimeout(r.bind(this),n))}.bind(this),n)}},{key:"_setACKTimer",value:function(){var e=this;this._timers.ackTimer=setTimeout(function(){e._status===I.STATUS_WAITING_FOR_ACK&&(w.debug("no ACK received, terminating the session"),clearTimeout(e._timers.invite2xxTimer),e.sendRequest(_.BYE),e._ended("remote",null,_.causes.NO_ACK))},g.TIMER_H)}},{key:"_createRTCConnection",value:function(e,t){var n=this;this._connection=new RTCPeerConnection(e,t),this._connection.addEventListener("iceconnectionstatechange",function(){"failed"===n._connection.iceConnectionState&&n.terminate({cause:_.causes.RTP_TIMEOUT,status_code:408,reason_phrase:_.causes.RTP_TIMEOUT})}),w.debug('emit "peerconnection"'),this.emit("peerconnection",{peerconnection:this._connection})}},{key:"_createLocalDescription",value:function(e,t){var n=this;if(w.debug("createLocalDescription()"),"offer"!==e&&"answer"!==e)throw new Error('createLocalDescription() | invalid type "'.concat(e,'"'));var r=this._connection;return this._rtcReady=!1,Promise.resolve().then(function(){return"offer"===e?r.createOffer(t).catch(function(e){return w.warn('emit "peerconnection:createofferfailed" [error:%o]',e),n.emit("peerconnection:createofferfailed",e),Promise.reject(e)}):r.createAnswer(t).catch(function(e){return w.warn('emit "peerconnection:createanswerfailed" [error:%o]',e),n.emit("peerconnection:createanswerfailed",e),Promise.reject(e)})}).then(function(e){return r.setLocalDescription(e).catch(function(e){return n._rtcReady=!0,w.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]',e),n.emit("peerconnection:setlocaldescriptionfailed",e),Promise.reject(e)})}).then(function(){if(!("complete"!==r.iceGatheringState||t&&t.iceRestart)){n._rtcReady=!0;var s={originator:"local",type:e,sdp:r.localDescription.sdp};return w.debug('emit "sdp"'),n.emit("sdp",s),Promise.resolve(s.sdp)}return new Promise(function(t){var s,i,o=!1,l=function(){r.removeEventListener("icecandidate",s),r.removeEventListener("icegatheringstatechange",i),o=!0,n._rtcReady=!0;var l={originator:"local",type:e,sdp:r.localDescription.sdp};w.debug('emit "sdp"'),n.emit("sdp",l),t(l.sdp)};r.addEventListener("icecandidate",s=function(e){var t=e.candidate;t?n.emit("icecandidate",{candidate:t,ready:l}):o||l()}),r.addEventListener("icegatheringstatechange",i=function(){"complete"!==r.iceGatheringState||o||l()})})})}},{key:"_createDialog",value:function(e,t,n){var r="UAS"===t?e.to_tag:e.from_tag,s="UAS"===t?e.from_tag:e.to_tag,i=e.call_id+r+s,o=this._earlyDialogs[i];if(n)return!!o||((o=new T(this,e,t,T.C.STATUS_EARLY)).error?(w.debug(o.error),this._failed("remote",e,_.causes.INTERNAL_ERROR),!1):(this._earlyDialogs[i]=o,!0));if(this._from_tag=e.from_tag,this._to_tag=e.to_tag,o)return o.update(e,t),this._dialog=o,delete this._earlyDialogs[i],!0;var l=new T(this,e,t);return l.error?(w.debug(l.error),this._failed("remote",e,_.causes.INTERNAL_ERROR),!1):(this._dialog=l,!0)}},{key:"_receiveReinvite",value:function(e){var t=this;w.debug("receiveReinvite()");var n=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0,r={request:e,callback:void 0,reject:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};s=!0;var n=t.status_code||403,r=t.reason_phrase||"",i=v.cloneArray(t.extraHeaders);if(this._status!==I.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("reinvite",r),!s){if(this._late_sdp=!1,!e.body)return this._late_sdp=!0,this._remoteHold&&(this._remoteHold=!1,this._onunhold("remote")),void(this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._createLocalDescription("offer",t._rtcOfferConstraints)}).then(function(e){i.call(t,e)}).catch(function(){e.reply(500)}));if("application/sdp"!==n)return w.debug("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==I.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){w.warn(e)})}function i(t){var n=this,s=["Contact: ".concat(this._contact)];this._handleSessionTimersInIncomingRequest(e,s),this._late_sdp&&(t=this._mangleOffer(t)),e.reply(200,null,s,t,function(){n._status=I.STATUS_WAITING_FOR_ACK,n._setInvite2xxTimer(e,t),n._setACKTimer()}),"function"==typeof r.callback&&r.callback()}}},{key:"_receiveUpdate",value:function(e){var t=this;w.debug("receiveUpdate()");var n=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0,r={request:e,callback:void 0,reject:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};s=!0;var n=t.status_code||403,r=t.reason_phrase||"",i=v.cloneArray(t.extraHeaders);if(this._status!==I.STATUS_CONFIRMED)return!1;if(n<300||n>=700)throw new TypeError("Invalid status_code: ".concat(n));e.reply(n,r,i)}.bind(this)},s=!1;if(this.emit("update",r),!s)if(e.body){if("application/sdp"!==n)return w.debug("invalid Content-Type"),void e.reply(415);this._processInDialogSdpOffer(e).then(function(e){t._status!==I.STATUS_TERMINATED&&i.call(t,e)}).catch(function(e){w.warn(e)})}else i.call(this,null);function i(t){var n=["Contact: ".concat(this._contact)];this._handleSessionTimersInIncomingRequest(e,n),e.reply(200,null,n,t),"function"==typeof r.callback&&r.callback()}}},{key:"_processInDialogSdpOffer",value:function(e){var t=this;w.debug("_processInDialogSdpOffer()");var n,r=e.parseSDP(),i=!1,o=s(r.media);try{for(o.s();!(n=o.n()).done;){var l=n.value;if(-1!==O.indexOf(l.type)){var u=l.direction||r.direction||"sendrecv";if("sendonly"!==u&&"inactive"!==u){i=!1;break}i=!0}}}catch(e){o.e(e)}finally{o.f()}var a={originator:"remote",type:"offer",sdp:e.body};w.debug('emit "sdp"'),this.emit("sdp",a);var c=new RTCSessionDescription({type:"offer",sdp:a.sdp});return this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if(t._status===I.STATUS_TERMINATED)throw new Error("terminated");return t._connection.setRemoteDescription(c).catch(function(n){throw e.reply(488),w.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n),n})}).then(function(){if(t._status===I.STATUS_TERMINATED)throw new Error("terminated");!0===t._remoteHold&&!1===i?(t._remoteHold=!1,t._onunhold("remote")):!1===t._remoteHold&&!0===i&&(t._remoteHold=!0,t._onhold("remote"))}).then(function(){if(t._status===I.STATUS_TERMINATED)throw new Error("terminated");return t._createLocalDescription("answer",t._rtcAnswerConstraints).catch(function(t){throw e.reply(500),w.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]',t),t})}).catch(function(e){w.warn("_processInDialogSdpOffer() failed [error: %o]",e)}),this._connectionPromiseQueue}},{key:"_receiveRefer",value:function(e){var t=this;if(w.debug("receiveRefer()"),!e.refer_to)return w.debug("no Refer-To header field present in REFER"),void e.reply(400);if(e.refer_to.uri.scheme!==_.SIP)return w.debug("Refer-To header field points to a non-SIP URI scheme"),void e.reply(416);e.reply(202);var r=new E(this,e.cseq);w.debug('emit "refer"'),this.emit("refer",{request:e,accept:function(s,i){(function(t){var s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t="function"==typeof t?t:null,this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;var i=new n(this._ua);if(i.on("progress",function(e){var t=e.response;r.notify(t.status_code,t.reason_phrase)}),i.on("accepted",function(e){var t=e.response;r.notify(t.status_code,t.reason_phrase)}),i.on("_failed",function(e){var t=e.message,n=e.cause;t?r.notify(t.status_code,t.reason_phrase):r.notify(487,n)}),e.refer_to.uri.hasHeader("replaces")){var o=decodeURIComponent(e.refer_to.uri.getHeader("replaces"));s.extraHeaders=v.cloneArray(s.extraHeaders),s.extraHeaders.push("Replaces: ".concat(o))}i.connect(e.refer_to.uri.toAor(),s,t)}).call(t,s,i)},reject:function(){(function(){r.notify(603)}).call(t)}})}},{key:"_receiveNotify",value:function(e){switch(w.debug("receiveNotify()"),e.event||e.reply(400),e.event.event){case"refer":var t,n;if(e.event.params&&e.event.params.id)t=e.event.params.id,n=this._referSubscribers[t];else{if(1!==Object.keys(this._referSubscribers).length)return void e.reply(400,"Missing event id parameter");n=this._referSubscribers[Object.keys(this._referSubscribers)[0]]}if(!n)return void e.reply(481,"Subscription does not exist");n.receiveNotify(e),e.reply(200);break;default:e.reply(489)}}},{key:"_receiveReplaces",value:function(e){var t=this;w.debug("receiveReplaces()"),this.emit("replaces",{request:e,accept:function(r){(function(t){var r=this;if(this._status!==I.STATUS_WAITING_FOR_ACK&&this._status!==I.STATUS_CONFIRMED)return!1;var s=new n(this._ua);s.on("confirmed",function(){r.terminate()}),s.init_incoming(e,t)}).call(t,r)},reject:function(){(function(){w.debug("Replaced INVITE rejected by the user"),e.reply(486)}).call(t)}})}},{key:"_sendInitialRequest",value:function(e,t,n){var r=this,s=new C(this._ua,this._request,{onRequestTimeout:function(){r.onRequestTimeout()},onTransportError:function(){r.onTransportError()},onAuthenticated:function(e){r._request=e},onReceiveResponse:function(e){r._receiveInviteResponse(e)}});Promise.resolve().then(function(){return n||(e.audio||e.video?(r._localMediaStreamLocallyGenerated=!0,navigator.mediaDevices.getUserMedia(e).catch(function(e){if(r._status===I.STATUS_TERMINATED)throw new Error("terminated");throw r._failed("local",null,_.causes.USER_DENIED_MEDIA_ACCESS),w.warn('emit "getusermediafailed" [error:%o]',e),r.emit("getusermediafailed",e),e})):void 0)}).then(function(e){if(r._status===I.STATUS_TERMINATED)throw new Error("terminated");return r._localMediaStream=e,e&&e.getTracks().forEach(function(t){r._connection.addTrack(t,e)}),r._connecting(r._request),r._createLocalDescription("offer",t).catch(function(e){throw r._failed("local",null,_.causes.WEBRTC_ERROR),e})}).then(function(e){if(r._is_canceled||r._status===I.STATUS_TERMINATED)throw new Error("terminated");r._request.body=e,r._status=I.STATUS_INVITE_SENT,w.debug('emit "sending" [request:%o]',r._request),r.emit("sending",{request:r._request}),s.send()}).catch(function(e){r._status!==I.STATUS_TERMINATED&&w.warn(e)})}},{key:"_getDTMFRTPSender",value:function(){var e=this._connection.getSenders().find(function(e){return e.track&&"audio"===e.track.kind});if(e&&e.dtmf)return e.dtmf;w.warn("sendDTMF() | no local audio track to send DTMF with")}},{key:"_receiveInviteResponse",value:function(e){var t=this;if(w.debug("receiveInviteResponse()"),this._dialog&&e.status_code>=200&&e.status_code<=299){if(this._dialog.id.call_id===e.call_id&&this._dialog.id.local_tag===e.from_tag&&this._dialog.id.remote_tag===e.to_tag)return void this.sendRequest(_.ACK);var n=new T(this,e,"UAC");return void 0!==n.error?void w.debug(n.error):(this.sendRequest(_.ACK),void this.sendRequest(_.BYE))}if(this._is_canceled)e.status_code>=100&&e.status_code<200?this._request.cancel(this._cancel_reason):e.status_code>=200&&e.status_code<299&&this._acceptAndTerminate(e);else if(this._status===I.STATUS_INVITE_SENT||this._status===I.STATUS_1XX_RECEIVED)switch(!0){case/^100$/.test(e.status_code):this._status=I.STATUS_1XX_RECEIVED;break;case/^1[0-9]{2}$/.test(e.status_code):if(!e.to_tag){w.debug("1xx response received without to tag");break}if(e.hasHeader("contact")&&!this._createDialog(e,"UAC",!0))break;if(this._status=I.STATUS_1XX_RECEIVED,!e.body){this._progress("remote",e);break}var r={originator:"remote",type:"answer",sdp:e.body};w.debug('emit "sdp"'),this.emit("sdp",r);var s=new RTCSessionDescription({type:"answer",sdp:r.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._connection.setRemoteDescription(s)}).then(function(){return t._progress("remote",e)}).catch(function(e){w.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)});break;case/^2[0-9]{2}$/.test(e.status_code):if(this._status=I.STATUS_CONFIRMED,!e.body){this._acceptAndTerminate(e,400,_.causes.MISSING_SDP),this._failed("remote",e,_.causes.BAD_MEDIA_DESCRIPTION);break}if(!this._createDialog(e,"UAC"))break;var i={originator:"remote",type:"answer",sdp:e.body};w.debug('emit "sdp"'),this.emit("sdp",i);var o=new RTCSessionDescription({type:"answer",sdp:i.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){if("stable"===t._connection.signalingState)return t._connection.createOffer(t._rtcOfferConstraints).then(function(e){return t._connection.setLocalDescription(e)}).catch(function(n){t._acceptAndTerminate(e,500,n.toString()),t._failed("local",e,_.causes.WEBRTC_ERROR)})}).then(function(){t._connection.setRemoteDescription(o).then(function(){t._handleSessionTimersInIncomingResponse(e),t._accepted("remote",e),t.sendRequest(_.ACK),t._confirmed("local",null)}).catch(function(n){t._acceptAndTerminate(e,488,"Not Acceptable Here"),t._failed("remote",e,_.causes.BAD_MEDIA_DESCRIPTION),w.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',n),t.emit("peerconnection:setremotedescriptionfailed",n)})});break;default:var l=v.sipErrorCause(e.status_code);this._failed("remote",e,l)}}},{key:"_sendReinvite",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};w.debug("sendReinvite()");var n=v.cloneArray(t.extraHeaders),r=v.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=!1;function o(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),n.push("Content-Type: application/sdp"),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return e._createLocalDescription("offer",s)}).then(function(t){var s={originator:"local",type:"offer",sdp:t=e._mangleOffer(t)};w.debug('emit "sdp"'),e.emit("sdp",s),e.sendRequest(_.INVITE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){(function(e){var t=this;if(this._status===I.STATUS_TERMINATED)return;if(this.sendRequest(_.ACK),i)return;if(this._handleSessionTimersInIncomingResponse(e),!e.body)return void o.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void o.call(this);var n={originator:"remote",type:"answer",sdp:e.body};w.debug('emit "sdp"'),this.emit("sdp",n);var s=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._connection.setRemoteDescription(s)}).then(function(){r.succeeded&&r.succeeded(e)}).catch(function(e){o.call(t),w.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}).call(e,t),i=!0},onErrorResponse:function(t){o.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){o()})}},{key:"_sendUpdate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};w.debug("sendUpdate()");var n=v.cloneArray(t.extraHeaders),r=v.cloneObject(t.eventHandlers),s=t.rtcOfferConstraints||this._rtcOfferConstraints||null,i=t.sdpOffer||!1,o=!1;function l(e){var t=this;if(this._status!==I.STATUS_TERMINATED&&!o)if(this._handleSessionTimersInIncomingResponse(e),i){if(!e.body)return void u.call(this);if(!e.hasHeader("Content-Type")||"application/sdp"!==e.getHeader("Content-Type").toLowerCase())return void u.call(this);var n={originator:"remote",type:"answer",sdp:e.body};w.debug('emit "sdp"'),this.emit("sdp",n);var s=new RTCSessionDescription({type:"answer",sdp:n.sdp});this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return t._connection.setRemoteDescription(s)}).then(function(){r.succeeded&&r.succeeded(e)}).catch(function(e){u.call(t),w.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]',e),t.emit("peerconnection:setremotedescriptionfailed",e)})}else r.succeeded&&r.succeeded(e)}function u(e){r.failed&&r.failed(e)}n.push("Contact: ".concat(this._contact)),this._sessionTimers.running&&n.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(this._sessionTimers.refresher?"uac":"uas")),i?(n.push("Content-Type: application/sdp"),this._connectionPromiseQueue=this._connectionPromiseQueue.then(function(){return e._createLocalDescription("offer",s)}).then(function(t){var r={originator:"local",type:"offer",sdp:t=e._mangleOffer(t)};w.debug('emit "sdp"'),e.emit("sdp",r),e.sendRequest(_.UPDATE,{extraHeaders:n,body:t,eventHandlers:{onSuccessResponse:function(t){l.call(e,t),o=!0},onErrorResponse:function(t){u.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}).catch(function(){u.call(e)})):this.sendRequest(_.UPDATE,{extraHeaders:n,eventHandlers:{onSuccessResponse:function(t){l.call(e,t)},onErrorResponse:function(t){u.call(e,t)},onTransportError:function(){e.onTransportError()},onRequestTimeout:function(){e.onRequestTimeout()},onDialogError:function(){e.onDialogError()}}})}},{key:"_acceptAndTerminate",value:function(e,t,n){w.debug("acceptAndTerminate()");var r=[];t&&(n=n||_.REASON_PHRASE[t]||"",r.push("Reason: SIP ;cause=".concat(t,'; text="').concat(n,'"'))),(this._dialog||this._createDialog(e,"UAC"))&&(this.sendRequest(_.ACK),this.sendRequest(_.BYE,{extraHeaders:r})),this._status=I.STATUS_TERMINATED}},{key:"_mangleOffer",value:function(e){if(!this._localHold&&!this._remoteHold)return e;if(e=d.parse(e),this._localHold&&!this._remoteHold){w.debug("mangleOffer() | me on hold, mangling offer");var t,n=s(e.media);try{for(n.s();!(t=n.n()).done;){var r=t.value;-1!==O.indexOf(r.type)&&(r.direction?"sendrecv"===r.direction?r.direction="sendonly":"recvonly"===r.direction&&(r.direction="inactive"):r.direction="sendonly")}}catch(e){n.e(e)}finally{n.f()}}else if(this._localHold&&this._remoteHold){w.debug("mangleOffer() | both on hold, mangling offer");var i,o=s(e.media);try{for(o.s();!(i=o.n()).done;){var l=i.value;-1!==O.indexOf(l.type)&&(l.direction="inactive")}}catch(e){o.e(e)}finally{o.f()}}else if(this._remoteHold){w.debug("mangleOffer() | remote on hold, mangling offer");var u,a=s(e.media);try{for(a.s();!(u=a.n()).done;){var c=u.value;-1!==O.indexOf(c.type)&&(c.direction?"sendrecv"===c.direction?c.direction="recvonly":"recvonly"===c.direction&&(c.direction="inactive"):c.direction="recvonly")}}catch(e){a.e(e)}finally{a.f()}}return d.write(e)}},{key:"_setLocalMediaStatus",value:function(){var e=!0,t=!0;(this._localHold||this._remoteHold)&&(e=!1,t=!1),this._audioMuted&&(e=!1),this._videoMuted&&(t=!1),this._toggleMuteAudio(!e),this._toggleMuteVideo(!t)}},{key:"_handleSessionTimersInIncomingRequest",value:function(e,t){var n;this._sessionTimers.enabled&&(e.session_expires&&e.session_expires>=_.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,n=e.session_expires_refresher||"uas"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,n="uas"),t.push("Session-Expires: ".concat(this._sessionTimers.currentExpires,";refresher=").concat(n)),this._sessionTimers.refresher="uas"===n,this._runSessionTimer())}},{key:"_handleSessionTimersInIncomingResponse",value:function(e){var t;this._sessionTimers.enabled&&(e.session_expires&&e.session_expires>=_.MIN_SESSION_EXPIRES?(this._sessionTimers.currentExpires=e.session_expires,t=e.session_expires_refresher||"uac"):(this._sessionTimers.currentExpires=this._sessionTimers.defaultExpires,t="uac"),this._sessionTimers.refresher="uac"===t,this._runSessionTimer())}},{key:"_runSessionTimer",value:function(){var e=this,t=this._sessionTimers.currentExpires;this._sessionTimers.running=!0,clearTimeout(this._sessionTimers.timer),this._sessionTimers.refresher?this._sessionTimers.timer=setTimeout(function(){e._status!==I.STATUS_TERMINATED&&(w.debug("runSessionTimer() | sending session refresh request"),e._sessionTimers.refreshMethod===_.UPDATE?e._sendUpdate():e._sendReinvite())},500*t):this._sessionTimers.timer=setTimeout(function(){e._status!==I.STATUS_TERMINATED&&(w.warn("runSessionTimer() | timer expired, terminating the session"),e.terminate({cause:_.causes.REQUEST_TIMEOUT,status_code:408,reason_phrase:"Session Timer Expired"}))},1100*t)}},{key:"_toggleMuteAudio",value:function(e){var t,n=s(this._connection.getSenders().filter(function(e){return e.track&&"audio"===e.track.kind}));try{for(n.s();!(t=n.n()).done;){t.value.track.enabled=!e}}catch(e){n.e(e)}finally{n.f()}}},{key:"_toggleMuteVideo",value:function(e){var t,n=s(this._connection.getSenders().filter(function(e){return e.track&&"video"===e.track.kind}));try{for(n.s();!(t=n.n()).done;){t.value.track.enabled=!e}}catch(e){n.e(e)}finally{n.f()}}},{key:"_newRTCSession",value:function(e,t){w.debug("newRTCSession()"),this._ua.newRTCSession(this,{originator:e,session:this,request:t})}},{key:"_connecting",value:function(e){w.debug("session connecting"),w.debug('emit "connecting"'),this.emit("connecting",{request:e})}},{key:"_progress",value:function(e,t){w.debug("session progress"),w.debug('emit "progress"'),this.emit("progress",{originator:e,response:t||null})}},{key:"_accepted",value:function(e,t){w.debug("session accepted"),this._start_time=new Date,w.debug('emit "accepted"'),this.emit("accepted",{originator:e,response:t||null})}},{key:"_confirmed",value:function(e,t){w.debug("session confirmed"),this._is_confirmed=!0,w.debug('emit "confirmed"'),this.emit("confirmed",{originator:e,ack:t||null})}},{key:"_ended",value:function(e,t,n){w.debug("session ended"),this._end_time=new Date,this._close(),w.debug('emit "ended"'),this.emit("ended",{originator:e,message:t||null,cause:n})}},{key:"_failed",value:function(e,t,n){w.debug("session failed"),w.debug('emit "_failed"'),this.emit("_failed",{originator:e,message:t||null,cause:n}),this._close(),w.debug('emit "failed"'),this.emit("failed",{originator:e,message:t||null,cause:n})}},{key:"_onhold",value:function(e){w.debug("session onhold"),this._setLocalMediaStatus(),w.debug('emit "hold"'),this.emit("hold",{originator:e})}},{key:"_onunhold",value:function(e){w.debug("session onunhold"),this._setLocalMediaStatus(),w.debug('emit "unhold"'),this.emit("unhold",{originator:e})}},{key:"_onmute",value:function(e){var t=e.audio,n=e.video;w.debug("session onmute"),this._setLocalMediaStatus(),w.debug('emit "muted"'),this.emit("muted",{audio:t,video:n})}},{key:"_onunmute",value:function(e){var t=e.audio,n=e.video;w.debug("session onunmute"),this._setLocalMediaStatus(),w.debug('emit "unmuted"'),this.emit("unmuted",{audio:t,video:n})}},{key:"C",get:function(){return I}},{key:"causes",get:function(){return _.causes}},{key:"id",get:function(){return this._id}},{key:"connection",get:function(){return this._connection}},{key:"contact",get:function(){return this._contact}},{key:"direction",get:function(){return this._direction}},{key:"local_identity",get:function(){return this._local_identity}},{key:"remote_identity",get:function(){return this._remote_identity}},{key:"start_time",get:function(){return this._start_time}},{key:"end_time",get:function(){return this._end_time}},{key:"data",get:function(){return this._data},set:function(e){this._data=e}},{key:"status",get:function(){return this._status}}]),n}()},{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./Logger":9,"./RTCSession/DTMF":14,"./RTCSession/Info":15,"./RTCSession/ReferNotifier":16,"./RTCSession/ReferSubscriber":17,"./RequestSender":19,"./SIPMessage":20,"./Timers":22,"./Transactions":23,"./URI":26,"./Utils":27,events:30,"sdp-transform":36}],14:[function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function s(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:{};if(void 0===e)throw new TypeError("Not enough arguments");if(this._direction="outgoing",this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new h.InvalidStateError(this._session.status);var r=d.cloneArray(n.extraHeaders);if(this.eventHandlers=d.cloneObject(n.eventHandlers),"string"==typeof e)e=e.toUpperCase();else{if("number"!=typeof e)throw new TypeError("Invalid tone: ".concat(e));e=e.toString()}if(!e.match(/^[0-9A-DR#*]$/))throw new TypeError("Invalid tone: ".concat(e));this._tone=e,this._duration=n.duration,r.push("Content-Type: application/dtmf-relay");var s="Signal=".concat(this._tone,"\r\n");s+="Duration=".concat(this._duration),this._session.newDTMF({originator:"local",dtmf:this,request:this._request}),this._session.sendRequest(c.INFO,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t.emit("succeeded",{originator:"remote",response:e})},onErrorResponse:function(e){t.eventHandlers.onFailed&&t.eventHandlers.onFailed(),t.emit("failed",{originator:"remote",response:e})},onRequestTimeout:function(){t._session.onRequestTimeout()},onTransportError:function(){t._session.onTransportError()},onDialogError:function(){t._session.onDialogError()}},body:s})}},{key:"init_incoming",value:function(e){var t=/^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*/,n=/^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*/;if(this._direction="incoming",this._request=e,e.reply(200),e.body){var r=e.body.split("\n");r.length>=1&&t.test(r[0])&&(this._tone=r[0].replace(t,"$2")),r.length>=2&&n.test(r[1])&&(this._duration=parseInt(r[1].replace(n,"$2"),10))}this._duration||(this._duration=_.DEFAULT_DURATION),this._tone?this._session.newDTMF({originator:"remote",dtmf:this,request:e}):f.debug("invalid INFO DTMF received, discarded")}},{key:"tone",get:function(){return this._tone}},{key:"duration",get:function(){return this._duration}}])&&s(t.prototype,n),r&&s(t,r),a}(),t.exports.C=_},{"../Constants":2,"../Exceptions":6,"../Logger":9,"../Utils":27,events:30}],15:[function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function s(e,t){for(var n=0;n2&&void 0!==arguments[2]?arguments[2]:{};if(this._direction="outgoing",void 0===e)throw new TypeError("Not enough arguments");if(this._session.status!==this._session.C.STATUS_CONFIRMED&&this._session.status!==this._session.C.STATUS_WAITING_FOR_ACK)throw new c.InvalidStateError(this._session.status);this._contentType=e,this._body=t;var s=h.cloneArray(r.extraHeaders);s.push("Content-Type: ".concat(e)),this._session.newInfo({originator:"local",info:this,request:this.request}),this._session.sendRequest(a.INFO,{extraHeaders:s,eventHandlers:{onSuccessResponse:function(e){n.emit("succeeded",{originator:"remote",response:e})},onErrorResponse:function(e){n.emit("failed",{originator:"remote",response:e})},onTransportError:function(){n._session.onTransportError()},onRequestTimeout:function(){n._session.onRequestTimeout()},onDialogError:function(){n._session.onDialogError()}},body:t})}},{key:"init_incoming",value:function(e){this._direction="incoming",this.request=e,e.reply(200),this._contentType=e.hasHeader("Content-Type")?e.getHeader("Content-Type").toLowerCase():void 0,this._body=e.body,this._session.newInfo({originator:"remote",info:this,request:e})}},{key:"contentType",get:function(){return this._contentType}},{key:"body",get:function(){return this._body}}])&&s(t.prototype,n),r&&s(t,r),d}()},{"../Constants":2,"../Exceptions":6,"../Utils":27,events:30}],16:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=200?"terminated;reason=noresource":"active;expires=".concat(this._expires),this._session.sendRequest(i.NOTIFY,{extraHeaders:["Event: ".concat(l.event_type,";id=").concat(this._id),"Subscription-State: ".concat(n),"Content-Type: ".concat(l.body_type)],body:"SIP/2.0 ".concat(e," ").concat(t),eventHandlers:{onErrorResponse:function(){this._active=!1}}}))}}])&&r(t.prototype,n),s&&r(t,s),e}()},{"../Constants":2,"../Logger":9}],17:[function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function s(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:{};f.debug("sendRefer()");var r=d.cloneArray(n.extraHeaders),s=d.cloneObject(n.eventHandlers);for(var i in s)Object.prototype.hasOwnProperty.call(s,i)&&this.on(i,s[i]);var o=null;n.replaces&&(o=n.replaces._request.call_id,o+=";to-tag=".concat(n.replaces._to_tag),o+=";from-tag=".concat(n.replaces._from_tag),o=encodeURIComponent(o));var l="Refer-To: <".concat(e).concat(o?"?Replaces=".concat(o):"",">");r.push(l);var u="Referred-By: <".concat(this._session._ua._configuration.uri._scheme,":").concat(this._session._ua._configuration.uri._user,"@").concat(this._session._ua._configuration.uri._host,">");r.push(u),r.push("Contact: ".concat(this._session.contact));var a=this._session.sendRequest(c.REFER,{extraHeaders:r,eventHandlers:{onSuccessResponse:function(e){t._requestSucceeded(e)},onErrorResponse:function(e){t._requestFailed(e,c.causes.REJECTED)},onTransportError:function(){t._requestFailed(null,c.causes.CONNECTION_ERROR)},onRequestTimeout:function(){t._requestFailed(null,c.causes.REQUEST_TIMEOUT)},onDialogError:function(){t._requestFailed(null,c.causes.DIALOG_ERROR)}}});this._id=a.cseq}},{key:"receiveNotify",value:function(e){if(f.debug("receiveNotify()"),e.body){var t=h.parse(e.body.trim(),"Status_Line");if(-1!==t)switch(!0){case/^100$/.test(t.status_code):this.emit("trying",{request:e,status_line:t});break;case/^1[0-9]{2}$/.test(t.status_code):this.emit("progress",{request:e,status_line:t});break;case/^2[0-9]{2}$/.test(t.status_code):this.emit("accepted",{request:e,status_line:t});break;default:this.emit("failed",{request:e,status_line:t})}else f.debug('receiveNotify() | error parsing NOTIFY body: "'.concat(e.body,'"'))}}},{key:"_requestSucceeded",value:function(e){f.debug("REFER succeeded"),f.debug('emit "requestSucceeded"'),this.emit("requestSucceeded",{response:e})}},{key:"_requestFailed",value:function(e,t){f.debug("REFER failed"),f.debug('emit "requestFailed"'),this.emit("requestFailed",{response:e||null,cause:t})}},{key:"id",get:function(){return this._id}}])&&s(t.prototype,n),r&&s(t,r),a}()},{"../Constants":2,"../Grammar":7,"../Logger":9,"../Utils":27,events:30}],18:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n"')}var t,n,s;return t=e,(n=[{key:"setExtraHeaders",value:function(e){Array.isArray(e)||(e=[]),this._extraHeaders=e.slice()}},{key:"setExtraContactParams",value:function(e){for(var t in e instanceof Object||(e={}),this._extraContactParams="",e)if(Object.prototype.hasOwnProperty.call(e,t)){var n=e[t];this._extraContactParams+=";".concat(t),n&&(this._extraContactParams+="=".concat(n))}}},{key:"register",value:function(){var e=this;if(this._registering)a.debug("Register request in progress...");else{var t=this._extraHeaders.slice();t.push("Contact: ".concat(this._contact,";expires=").concat(this._expires).concat(this._extraContactParams)),t.push("Expires: ".concat(this._expires));var n=new l.OutgoingRequest(o.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},t),r=new u(this._ua,n,{onRequestTimeout:function(){e._registrationFailure(null,o.causes.REQUEST_TIMEOUT)},onTransportError:function(){e._registrationFailure(null,o.causes.CONNECTION_ERROR)},onAuthenticated:function(){e._cseq+=1},onReceiveResponse:function(t){if(t.cseq===e._cseq)switch(null!==e._registrationTimer&&(clearTimeout(e._registrationTimer),e._registrationTimer=null),!0){case/^1[0-9]{2}$/.test(t.status_code):break;case/^2[0-9]{2}$/.test(t.status_code):if(e._registering=!1,!t.hasHeader("Contact")){a.debug("no Contact header in response to REGISTER, response ignored");break}var n=t.headers.Contact.reduce(function(e,t){return e.concat(t.parsed)},[]).find(function(t){return t.uri.user===e._ua.contact.uri.user});if(!n){a.debug("no Contact header pointing to us, response ignored");break}var r=n.getParam("expires");!r&&t.hasHeader("expires")&&(r=t.getHeader("expires")),r||(r=e._expires),(r=Number(r))<10&&(r=10);var s=r>64?1e3*r/2+Math.floor(1e3*(r/2-32)*Math.random()):1e3*r-5e3;e._registrationTimer=setTimeout(function(){e._registrationTimer=null,0===e._ua.listeners("registrationExpiring").length?e.register():e._ua.emit("registrationExpiring")},s),n.hasParam("temp-gruu")&&(e._ua.contact.temp_gruu=n.getParam("temp-gruu").replace(/"/g,"")),n.hasParam("pub-gruu")&&(e._ua.contact.pub_gruu=n.getParam("pub-gruu").replace(/"/g,"")),e._registered||(e._registered=!0,e._ua.registered({response:t}));break;case/^423$/.test(t.status_code):t.hasHeader("min-expires")?(e._expires=Number(t.getHeader("min-expires")),e._expires<10&&(e._expires=10),e.register()):(a.debug("423 response received for REGISTER without Min-Expires"),e._registrationFailure(t,o.causes.SIP_FAILURE_CODE));break;default:var l=i.sipErrorCause(t.status_code);e._registrationFailure(t,l)}}});this._registering=!0,r.send()}}},{key:"unregister",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this._registered){this._registered=!1,null!==this._registrationTimer&&(clearTimeout(this._registrationTimer),this._registrationTimer=null);var n=this._extraHeaders.slice();t.all?n.push("Contact: *".concat(this._extraContactParams)):n.push("Contact: ".concat(this._contact,";expires=0").concat(this._extraContactParams)),n.push("Expires: 0");var r=new l.OutgoingRequest(o.REGISTER,this._registrar,this._ua,{to_uri:this._to_uri,call_id:this._call_id,cseq:this._cseq+=1},n);new u(this._ua,r,{onRequestTimeout:function(){e._unregistered(null,o.causes.REQUEST_TIMEOUT)},onTransportError:function(){e._unregistered(null,o.causes.CONNECTION_ERROR)},onAuthenticated:function(){e._cseq+=1},onReceiveResponse:function(t){switch(!0){case/^1[0-9]{2}$/.test(t.status_code):break;case/^2[0-9]{2}$/.test(t.status_code):e._unregistered(t);break;default:var n=i.sipErrorCause(t.status_code);e._unregistered(t,n)}}}).send()}else a.debug("already unregistered")}},{key:"close",value:function(){this._registered&&this.unregister()}},{key:"onTransportClosed",value:function(){this._registering=!1,null!==this._registrationTimer&&(clearTimeout(this._registrationTimer),this._registrationTimer=null),this._registered&&(this._registered=!1,this._ua.unregistered({}))}},{key:"_registrationFailure",value:function(e,t){this._registering=!1,this._ua.registrationFailed({response:e||null,cause:t}),this._registered&&(this._registered=!1,this._ua.unregistered({response:e||null,cause:t}))}},{key:"_unregistered",value:function(e,t){this._registering=!1,this._registered=!1,this._ua.unregistered({response:e||null,cause:t||null})}},{key:"registered",get:function(){return this._registered}}])&&r(t.prototype,n),s&&r(t,s),e}()},{"./Constants":2,"./Logger":9,"./RequestSender":19,"./SIPMessage":20,"./Utils":27}],19:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:s}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,o=!0,l=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return o=e.done,e},e:function(e){l=!0,i=e},f:function(){try{o||null==n.return||n.return()}finally{if(l)throw i}}}}function a(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n")),this.setHeader("via",""),this.setHeader("max-forwards",p.MAX_FORWARDS);var l=s.to_uri||n,u=s.to_tag?{tag:s.to_tag}:null,a=void 0!==s.to_display_name?s.to_display_name:null;this.to=new v(l,a,u),this.setHeader("to",this.to.toString());var h,d=s.from_uri||r.configuration.uri,f={tag:s.from_tag||m.newTag()};h=void 0!==s.from_display_name?s.from_display_name:r.configuration.display_name?r.configuration.display_name:null,this.from=new v(d,h,f),this.setHeader("from",this.from.toString());var _=s.call_id||r.configuration.jssip_id+m.createRandomToken(15);this.call_id=_,this.setHeader("call-id",_);var g=s.cseq||Math.floor(1e4*Math.random());this.cseq=g,this.setHeader("cseq","".concat(g," ").concat(t))}return d(e,[{key:"setHeader",value:function(e,t){for(var n=new RegExp("^\\s*".concat(e,"\\s*:"),"i"),r=0;r1&&void 0!==arguments[1]?arguments[1]:0;if(e=m.headerize(e),this.headers[e]){if(!(t>=this.headers[e].length)){var n=this.headers[e][t],r=n.raw;if(n.parsed)return n.parsed;var s=g.parse(r,e.replace(/-/g,"_"));return-1===s?(this.headers[e].splice(t,1),void y.debug('error parsing "'.concat(e,'" header field with value "').concat(r,'"'))):(n.parsed=s,s)}y.debug('not so many "'.concat(e,'" headers present'))}else y.debug('header "'.concat(e,'" not present'))}},{key:"s",value:function(e,t){return this.parseHeader(e,t)}},{key:"setHeader",value:function(e,t){var n={raw:t};this.headers[m.headerize(e)]=[n]}},{key:"parseSDP",value:function(e){return!e&&this.sdp?this.sdp:(this.sdp=f.parse(this.body||""),this.sdp)}},{key:"toString",value:function(){return this.data}}]),e}(),S=function(e){s(n,b);var t=o(n);function n(e){var r;return c(this,n),(r=t.call(this)).ua=e,r.headers={},r.ruri=null,r.transport=null,r.server_transaction=null,r}return d(n,[{key:"reply",value:function(e,t,n,r,s,i){var o=[],l=this.getHeader("To");if(t=t||null,!(e=e||null)||e<100||e>699)throw new TypeError("Invalid status_code: ".concat(e));if(t&&"string"!=typeof t&&!(t instanceof String))throw new TypeError("Invalid reason_phrase: ".concat(t));t=t||p.REASON_PHRASE[e]||"",n=m.cloneArray(n);var a="SIP/2.0 ".concat(e," ").concat(t,"\r\n");if(this.method===p.INVITE&&e>100&&e<=200){var c,h=u(this.getHeaders("record-route"));try{for(h.s();!(c=h.n()).done;){var d=c.value;a+="Record-Route: ".concat(d,"\r\n")}}catch(e){h.e(e)}finally{h.f()}}var f,_=u(this.getHeaders("via"));try{for(_.s();!(f=_.n()).done;){var v=f.value;a+="Via: ".concat(v,"\r\n")}}catch(e){_.e(e)}finally{_.f()}!this.to_tag&&e>100?l+=";tag=".concat(m.newTag()):this.to_tag&&!this.s("to").hasParam("tag")&&(l+=";tag=".concat(this.to_tag)),a+="To: ".concat(l,"\r\n"),a+="From: ".concat(this.getHeader("From"),"\r\n"),a+="Call-ID: ".concat(this.call_id,"\r\n"),a+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n");var g,y=u(n);try{for(y.s();!(g=y.n()).done;){var T=g.value;a+="".concat(T.trim(),"\r\n")}}catch(e){y.e(e)}finally{y.f()}switch(this.method){case p.INVITE:this.ua.configuration.session_timers&&o.push("timer"),(this.ua.contact.pub_gruu||this.ua.contact.temp_gruu)&&o.push("gruu"),o.push("ice","replaces");break;case p.UPDATE:this.ua.configuration.session_timers&&o.push("timer"),r&&o.push("ice"),o.push("replaces")}if(o.push("outbound"),this.method===p.OPTIONS?(a+="Allow: ".concat(p.ALLOWED_METHODS,"\r\n"),a+="Accept: ".concat(p.ACCEPTED_BODY_TYPES,"\r\n")):405===e?a+="Allow: ".concat(p.ALLOWED_METHODS,"\r\n"):415===e&&(a+="Accept: ".concat(p.ACCEPTED_BODY_TYPES,"\r\n")),a+="Supported: ".concat(o,"\r\n"),r){var C=m.str_utf8_length(r);a+="Content-Type: application/sdp\r\n",a+="Content-Length: ".concat(C,"\r\n\r\n"),a+=r}else a+="Content-Length: ".concat(0,"\r\n\r\n");this.server_transaction.receiveResponse(e,a,s,i)}},{key:"reply_sl",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=this.getHeaders("via");if(!e||e<100||e>699)throw new TypeError("Invalid status_code: ".concat(e));if(t&&"string"!=typeof t&&!(t instanceof String))throw new TypeError("Invalid reason_phrase: ".concat(t));t=t||p.REASON_PHRASE[e]||"";var r,s="SIP/2.0 ".concat(e," ").concat(t,"\r\n"),i=u(n);try{for(i.s();!(r=i.n()).done;){var o=r.value;s+="Via: ".concat(o,"\r\n")}}catch(e){i.e(e)}finally{i.f()}var l=this.getHeader("To");!this.to_tag&&e>100?l+=";tag=".concat(m.newTag()):this.to_tag&&!this.s("to").hasParam("tag")&&(l+=";tag=".concat(this.to_tag)),s+="To: ".concat(l,"\r\n"),s+="From: ".concat(this.getHeader("From"),"\r\n"),s+="Call-ID: ".concat(this.call_id,"\r\n"),s+="CSeq: ".concat(this.cseq," ").concat(this.method,"\r\n"),s+="Content-Length: ".concat(0,"\r\n\r\n"),this.transport.send(s)}}]),n}(),E=function(e){s(n,b);var t=o(n);function n(){var e;return c(this,n),(e=t.call(this)).headers={},e.status_code=null,e.reason_phrase=null,e}return n}();t.exports={OutgoingRequest:T,InitialOutgoingInviteRequest:C,IncomingRequest:S,IncomingResponse:E}},{"./Constants":2,"./Grammar":7,"./Logger":9,"./NameAddrHeader":11,"./Utils":27,"sdp-transform":36}],21:[function(e,t,n){"use strict";var r=e("./Logger"),s=e("./Utils"),i=e("./Grammar"),o=new r("Socket");n.isSocket=function(e){if(Array.isArray(e))return!1;if(void 0===e)return o.warn("undefined JsSIP.Socket instance"),!1;try{if(!s.isString(e.url))throw o.warn("missing or invalid JsSIP.Socket url property"),new Error;if(!s.isString(e.via_transport))throw o.warn("missing or invalid JsSIP.Socket via_transport property"),new Error;if(-1===i.parse(e.sip_uri,"SIP_URI"))throw o.warn("missing or invalid JsSIP.Socket sip_uri property"),new Error}catch(e){return!1}try{["connect","disconnect","send"].forEach(function(t){if(!s.isFunction(e[t]))throw o.warn("missing or invalid JsSIP.Socket method: ".concat(t)),new Error})}catch(e){return!1}return!0}},{"./Grammar":7,"./Logger":9,"./Utils":27}],22:[function(e,t,n){"use strict";var r=500;t.exports={T1:r,T2:4e3,T4:5e3,TIMER_B:32e3,TIMER_D:0,TIMER_F:32e3,TIMER_H:32e3,TIMER_I:0,TIMER_J:0,TIMER_K:0,TIMER_L:32e3,TIMER_M:32e3,PROVISIONAL_RESPONSE_INTERVAL:6e4}},{}],23:[function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n=100&&n<=199)switch(this.state){case b.STATUS_CALLING:this.stateChanged(b.STATUS_PROCEEDING),this.eventHandlers.onReceiveResponse(e);break;case b.STATUS_PROCEEDING:this.eventHandlers.onReceiveResponse(e)}else if(n>=200&&n<=299)switch(this.state){case b.STATUS_CALLING:case b.STATUS_PROCEEDING:this.stateChanged(b.STATUS_ACCEPTED),this.M=setTimeout(function(){t.timer_M()},m.TIMER_M),this.eventHandlers.onReceiveResponse(e);break;case b.STATUS_ACCEPTED:this.eventHandlers.onReceiveResponse(e)}else if(n>=300&&n<=699)switch(this.state){case b.STATUS_CALLING:case b.STATUS_PROCEEDING:this.stateChanged(b.STATUS_COMPLETED),this.sendACK(e),this.eventHandlers.onReceiveResponse(e);break;case b.STATUS_COMPLETED:this.sendACK(e)}}},{key:"C",get:function(){return b}}]),n}(),A=function(e){l(n,d);var t=a(n);function n(e,r,i,o){var l;s(this,n),(l=t.call(this)).id="z9hG4bK".concat(Math.floor(1e7*Math.random())),l.transport=r,l.request=i,l.eventHandlers=o;var u="SIP/2.0/".concat(r.via_transport);return u+=" ".concat(e.configuration.via_host,";branch=").concat(l.id),l.request.setHeader("via",u),l}return o(n,[{key:"send",value:function(){this.transport.send(this.request)||this.onTransportError()}},{key:"onTransportError",value:function(){y.debug("transport error occurred for transaction ".concat(this.id)),this.eventHandlers.onTransportError()}},{key:"C",get:function(){return b}}]),n}(),R=function(e){l(n,d);var t=a(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=b.NON_INVITE_SERVER,o.id=i.via_branch,o.ua=e,o.transport=r,o.request=i,o.last_response="",i.server_transaction=c(o),o.state=b.STATUS_TRYING,e.newTransaction(c(o)),o}return o(n,[{key:"stateChanged",value:function(e){this.state=e,this.emit("stateChanged")}},{key:"timer_J",value:function(){T.debug("Timer J expired for transaction ".concat(this.id)),this.stateChanged(b.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,T.debug("transport error occurred, deleting transaction ".concat(this.id)),clearTimeout(this.J),this.stateChanged(b.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(100===e)switch(this.state){case b.STATUS_TRYING:this.stateChanged(b.STATUS_PROCEEDING),this.transport.send(t)||this.onTransportError();break;case b.STATUS_PROCEEDING:this.last_response=t,this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=200&&e<=699)switch(this.state){case b.STATUS_TRYING:case b.STATUS_PROCEEDING:this.stateChanged(b.STATUS_COMPLETED),this.last_response=t,this.J=setTimeout(function(){s.timer_J()},m.TIMER_J),this.transport.send(t)?n&&n():(this.onTransportError(),r&&r());break;case b.STATUS_COMPLETED:}}},{key:"C",get:function(){return b}}]),n}(),w=function(e){l(n,d);var t=a(n);function n(e,r,i){var o;return s(this,n),(o=t.call(this)).type=b.INVITE_SERVER,o.id=i.via_branch,o.ua=e,o.transport=r,o.request=i,o.last_response="",i.server_transaction=c(o),o.state=b.STATUS_PROCEEDING,e.newTransaction(c(o)),o.resendProvisionalTimer=null,i.reply(100),o}return o(n,[{key:"stateChanged",value:function(e){this.state=e,this.emit("stateChanged")}},{key:"timer_H",value:function(){C.debug("Timer H expired for transaction ".concat(this.id)),this.state===b.STATUS_COMPLETED&&C.debug("ACK not received, dialog will be terminated"),this.stateChanged(b.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_I",value:function(){this.stateChanged(b.STATUS_TERMINATED),this.ua.destroyTransaction(this)}},{key:"timer_L",value:function(){C.debug("Timer L expired for transaction ".concat(this.id)),this.state===b.STATUS_ACCEPTED&&(this.stateChanged(b.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"onTransportError",value:function(){this.transportError||(this.transportError=!0,C.debug("transport error occurred, deleting transaction ".concat(this.id)),null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),clearTimeout(this.L),clearTimeout(this.H),clearTimeout(this.I),this.stateChanged(b.STATUS_TERMINATED),this.ua.destroyTransaction(this))}},{key:"resend_provisional",value:function(){this.transport.send(this.last_response)||this.onTransportError()}},{key:"receiveResponse",value:function(e,t,n,r){var s=this;if(e>=100&&e<=199)switch(this.state){case b.STATUS_PROCEEDING:this.transport.send(t)||this.onTransportError(),this.last_response=t}if(e>100&&e<=199&&this.state===b.STATUS_PROCEEDING)null===this.resendProvisionalTimer&&(this.resendProvisionalTimer=setInterval(function(){s.resend_provisional()},m.PROVISIONAL_RESPONSE_INTERVAL));else if(e>=200&&e<=299)switch(this.state){case b.STATUS_PROCEEDING:this.stateChanged(b.STATUS_ACCEPTED),this.last_response=t,this.L=setTimeout(function(){s.timer_L()},m.TIMER_L),null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null);case b.STATUS_ACCEPTED:this.transport.send(t)?n&&n():(this.onTransportError(),r&&r())}else if(e>=300&&e<=699)switch(this.state){case b.STATUS_PROCEEDING:null!==this.resendProvisionalTimer&&(clearInterval(this.resendProvisionalTimer),this.resendProvisionalTimer=null),this.transport.send(t)?(this.stateChanged(b.STATUS_COMPLETED),this.H=setTimeout(function(){s.timer_H()},m.TIMER_H),n&&n()):(this.onTransportError(),r&&r())}}},{key:"C",get:function(){return b}}]),n}();t.exports={C:b,NonInviteClientTransaction:S,InviteClientTransaction:E,AckClientTransaction:A,NonInviteServerTransaction:R,InviteServerTransaction:w,checkTransaction:function(e,t){var n,r=e._transactions;switch(t.method){case _.INVITE:if(n=r.ist[t.via_branch]){switch(n.state){case b.STATUS_PROCEEDING:n.transport.send(n.last_response);break;case b.STATUS_ACCEPTED:}return!0}break;case _.ACK:if(!(n=r.ist[t.via_branch]))return!1;if(n.state===b.STATUS_ACCEPTED)return!1;if(n.state===b.STATUS_COMPLETED)return n.state=b.STATUS_CONFIRMED,n.I=setTimeout(function(){n.timer_I()},m.TIMER_I),!0;break;case _.CANCEL:return(n=r.ist[t.via_branch])?(t.reply_sl(200),n.state!==b.STATUS_PROCEEDING):(t.reply_sl(481),!0);default:if(n=r.nist[t.via_branch]){switch(n.state){case b.STATUS_TRYING:break;case b.STATUS_PROCEEDING:case b.STATUS_COMPLETED:n.transport.send(n.last_response)}return!0}}}}},{"./Constants":2,"./Logger":9,"./SIPMessage":20,"./Timers":22,events:30}],24:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:u.recovery_options;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),l.debug("new()"),this.status=u.STATUS_DISCONNECTED,this.socket=null,this.sockets=[],this.recovery_options=n,this.recover_attempts=0,this.recovery_timer=null,this.close_requested=!1;try{this.textDecoder=new TextDecoder("utf8")}catch(e){l.warn("cannot use TextDecoder: ".concat(e))}if(void 0===t)throw new TypeError("Invalid argument. undefined 'sockets' argument");t instanceof Array||(t=[t]),t.forEach(function(e){if(!i.isSocket(e.socket))throw new TypeError("Invalid argument. invalid 'JsSIP.Socket' instance");if(e.weight&&!Number(e.weight))throw new TypeError("Invalid argument. 'weight' attribute is not a number");this.sockets.push({socket:e.socket,weight:e.weight||0,status:u.SOCKET_STATUS_READY})},this),this._getSocket()}var t,n,s;return t=e,(n=[{key:"connect",value:function(){l.debug("connect()"),this.isConnected()?l.debug("Transport is already connected"):this.isConnecting()?l.debug("Transport is connecting"):(this.close_requested=!1,this.status=u.STATUS_CONNECTING,this.onconnecting({socket:this.socket,attempts:this.recover_attempts}),this.close_requested||(this.socket.onconnect=this._onConnect.bind(this),this.socket.ondisconnect=this._onDisconnect.bind(this),this.socket.ondata=this._onData.bind(this),this.socket.connect()))}},{key:"disconnect",value:function(){l.debug("close()"),this.close_requested=!0,this.recover_attempts=0,this.status=u.STATUS_DISCONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.socket.onconnect=function(){},this.socket.ondisconnect=function(){},this.socket.ondata=function(){},this.socket.disconnect(),this.ondisconnect({socket:this.socket,error:!1})}},{key:"send",value:function(e){if(l.debug("send()"),!this.isConnected())return l.warn("unable to send message, transport is not connected"),!1;var t=e.toString();return l.debug("sending message:\n\n".concat(t,"\n")),this.socket.send(t)}},{key:"isConnected",value:function(){return this.status===u.STATUS_CONNECTED}},{key:"isConnecting",value:function(){return this.status===u.STATUS_CONNECTING}},{key:"_reconnect",value:function(){var e=this;this.recover_attempts+=1;var t=Math.floor(Math.random()*Math.pow(2,this.recover_attempts)+1);tthis.recovery_options.max_interval&&(t=this.recovery_options.max_interval),l.debug("reconnection attempt: ".concat(this.recover_attempts,". next connection attempt in ").concat(t," seconds")),this.recovery_timer=setTimeout(function(){e.close_requested||e.isConnected()||e.isConnecting()||(e._getSocket(),e.connect())},1e3*t)}},{key:"_getSocket",value:function(){var e=[];if(this.sockets.forEach(function(t){t.status!==u.SOCKET_STATUS_ERROR&&(0===e.length?e.push(t):t.weight>e[0].weight?e=[t]:t.weight===e[0].weight&&e.push(t))}),0===e.length)return this.sockets.forEach(function(e){e.status=u.SOCKET_STATUS_READY}),void this._getSocket();var t=Math.floor(Math.random()*e.length);this.socket=e[t].socket}},{key:"_onConnect",value:function(){this.recover_attempts=0,this.status=u.STATUS_CONNECTED,null!==this.recovery_timer&&(clearTimeout(this.recovery_timer),this.recovery_timer=null),this.onconnect({socket:this})}},{key:"_onDisconnect",value:function(e,t,n){this.status=u.STATUS_DISCONNECTED,this.ondisconnect({socket:this.socket,error:e,code:t,reason:n}),this.close_requested||(this.sockets.forEach(function(e){this.socket===e.socket&&(e.status=u.SOCKET_STATUS_ERROR)},this),this._reconnect(e))}},{key:"_onData",value:function(e){if("\r\n"!==e){if("string"!=typeof e){try{e=this.textDecoder?this.textDecoder.decode(e):String.fromCharCode.apply(null,new Uint8Array(e))}catch(e){return void l.debug("received binary message failed to be converted into string, message discarded")}l.debug("received binary message:\n\n".concat(e,"\n"))}else l.debug("received text message:\n\n".concat(e,"\n"));this.ondata({transport:this,message:e})}else l.debug("received message with CRLF Keep Alive response")}},{key:"via_transport",get:function(){return this.socket.via_transport}},{key:"url",get:function(){return this.socket.url}},{key:"sip_uri",get:function(){return this.socket.sip_uri}}])&&r(t.prototype,n),s&&r(t,s),e}()},{"./Constants":2,"./Logger":9,"./Socket":21}],25:[function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function s(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=e.anonymous||null,n=e.outbound||null,r="<";return r+=t?this.temp_gruu||"sip:anonymous@anonymous.invalid;transport=ws":this.pub_gruu||this.uri.toString(),!n||(t?this.temp_gruu:this.pub_gruu)||(r+=";ob"),r+=">"}};var r=["authorization_user","password","realm","ha1","authorization_jwt","display_name","register"];for(var s in this._configuration)Object.prototype.hasOwnProperty.call(this._configuration,s)&&(-1!==r.indexOf(s)?Object.defineProperty(this._configuration,s,{writable:!0,configurable:!1}):Object.defineProperty(this._configuration,s,{writable:!1,configurable:!1}));for(var i in A.debug("configuration parameters after validation:"),this._configuration)if(Object.prototype.hasOwnProperty.call(E.settings,i))switch(i){case"uri":case"registrar_server":A.debug("- ".concat(i,": ").concat(this._configuration[i]));break;case"password":case"ha1":case"authorization_jwt":A.debug("- ".concat(i,": NOT SHOWN"));break;default:A.debug("- ".concat(i,": ").concat(JSON.stringify(this._configuration[i])))}}},{key:"C",get:function(){return R}},{key:"status",get:function(){return this._status}},{key:"contact",get:function(){return this._contact}},{key:"configuration",get:function(){return this._configuration}},{key:"transport",get:function(){return this._transport}}]),n}()},{"./Config":1,"./Constants":2,"./Exceptions":6,"./Logger":9,"./Message":10,"./Parser":12,"./RTCSession":13,"./Registrator":18,"./SIPMessage":20,"./Transactions":23,"./Transport":24,"./URI":26,"./Utils":27,"./sanityCheck":29,events:30}],26:[function(e,t,n){"use strict";function r(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return s(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return s(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,l=!0,u=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return l=e.done,e},e:function(e){u=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(u)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n4&&void 0!==arguments[4]?arguments[4]:{},o=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),!r)throw new TypeError('missing or invalid "host" parameter');for(var u in this._parameters={},this._headers={},this._scheme=t||l.SIP,this._user=n,this._host=r,this._port=s,i)Object.prototype.hasOwnProperty.call(i,u)&&this.setParam(u,i[u]);for(var a in o)Object.prototype.hasOwnProperty.call(o,a)&&this.setHeader(a,o[a])}return o(e,null,[{key:"parse",value:function(e){return-1!==(e=a.parse(e,"SIP_URI"))?e:void 0}}]),o(e,[{key:"setParam",value:function(e,t){e&&(this._parameters[e.toLowerCase()]=null==t?null:t.toString())}},{key:"getParam",value:function(e){if(e)return this._parameters[e.toLowerCase()]}},{key:"hasParam",value:function(e){if(e)return!!this._parameters.hasOwnProperty(e.toLowerCase())}},{key:"deleteParam",value:function(e){if(e=e.toLowerCase(),this._parameters.hasOwnProperty(e)){var t=this._parameters[e];return delete this._parameters[e],t}}},{key:"clearParams",value:function(){this._parameters={}}},{key:"setHeader",value:function(e,t){this._headers[u.headerize(e)]=Array.isArray(t)?t:[t]}},{key:"getHeader",value:function(e){if(e)return this._headers[u.headerize(e)]}},{key:"hasHeader",value:function(e){if(e)return!!this._headers.hasOwnProperty(u.headerize(e))}},{key:"deleteHeader",value:function(e){if(e=u.headerize(e),this._headers.hasOwnProperty(e)){var t=this._headers[e];return delete this._headers[e],t}}},{key:"clearHeaders",value:function(){this._headers={}}},{key:"clone",value:function(){return new e(this._scheme,this._user,this._host,this._port,JSON.parse(JSON.stringify(this._parameters)),JSON.parse(JSON.stringify(this._headers)))}},{key:"toString",value:function(){var e=[],t="".concat(this._scheme,":");for(var n in this._user&&(t+="".concat(u.escapeUser(this._user),"@")),t+=this._host,(this._port||0===this._port)&&(t+=":".concat(this._port)),this._parameters)Object.prototype.hasOwnProperty.call(this._parameters,n)&&(t+=";".concat(n),null!==this._parameters[n]&&(t+="=".concat(this._parameters[n])));for(var s in this._headers)if(Object.prototype.hasOwnProperty.call(this._headers,s)){var i,o=r(this._headers[s]);try{for(o.s();!(i=o.n()).done;){var l=i.value;e.push("".concat(s,"=").concat(l))}}catch(e){o.e(e)}finally{o.f()}}return e.length>0&&(t+="?".concat(e.join("&"))),t}},{key:"toAor",value:function(e){var t="".concat(this._scheme,":");return this._user&&(t+="".concat(u.escapeUser(this._user),"@")),t+=this._host,e&&(this._port||0===this._port)&&(t+=":".concat(this._port)),t}},{key:"scheme",get:function(){return this._scheme},set:function(e){this._scheme=e.toLowerCase()}},{key:"user",get:function(){return this._user},set:function(e){this._user=e}},{key:"host",get:function(){return this._host},set:function(e){this._host=e.toLowerCase()}},{key:"port",get:function(){return this._port},set:function(e){this._port=0===e?e:parseInt(e,10)||null}}]),e}()},{"./Constants":2,"./Grammar":7,"./Utils":27}],27:[function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function s(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return i(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return i(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,s=function(){};return{s:s,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:s}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,l=!0,u=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return l=e.done,e},e:function(e){u=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(u)throw o}}}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:32,r="";for(t=0;t>>32-t}function n(e,t){var n=2147483648&e,r=2147483648&t,s=1073741824&e,i=1073741824&t,o=(1073741823&e)+(1073741823&t);return s&i?2147483648^o^n^r:s|i?1073741824&o?3221225472^o^n^r:1073741824^o^n^r:o^n^r}function r(e,r,s,i,o,l,u){return e=n(e,n(n(function(e,t,n){return e&t|~e&n}(r,s,i),o),u)),n(t(e,l),r)}function s(e,r,s,i,o,l,u){return e=n(e,n(n(function(e,t,n){return e&n|t&~n}(r,s,i),o),u)),n(t(e,l),r)}function i(e,r,s,i,o,l,u){return e=n(e,n(n(function(e,t,n){return e^t^n}(r,s,i),o),u)),n(t(e,l),r)}function o(e,r,s,i,o,l,u){return e=n(e,n(n(function(e,t,n){return t^(e|~n)}(r,s,i),o),u)),n(t(e,l),r)}function l(e){var t,n="",r="";for(t=0;t<=3;t++)n+=(r="0".concat((e>>>8*t&255).toString(16))).substr(r.length-2,2);return n}var u,a,c,h,d,f,_,p,m,v;for(u=function(e){for(var t,n=e.length,r=n+8,s=16*((r-r%64)/64+1),i=new Array(s-1),o=0,l=0;l>>29,i}(e=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",n=0;n127&&r<2048?(t+=String.fromCharCode(r>>6|192),t+=String.fromCharCode(63&r|128)):(t+=String.fromCharCode(r>>12|224),t+=String.fromCharCode(r>>6&63|128),t+=String.fromCharCode(63&r|128))}return t}(e)),_=1732584193,p=4023233417,m=2562383102,v=271733878,a=0;a1&&void 0!==arguments[1]?arguments[1]:{};return e&&Object.assign({},e)||t}},{"./Constants":2,"./Grammar":7,"./URI":26}],28:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,l=!0,u=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return l=e.done,e},e:function(e){u=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(u)throw o}}}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n1)return d.debug("more than one Via header field present in the response, dropping the response"),!1},function(){var e=h.str_utf8_length(i.body),t=i.getHeader("content-length");if(e0&&l.length>i){l.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+l.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=l.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",u.name,u.message)}}else l=o[t]=n,++e._eventsCount;return e}function d(){if(!this.fired)switch(this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length){case 0:return this.listener.call(this.target);case 1:return this.listener.call(this.target,arguments[0]);case 2:return this.listener.call(this.target,arguments[0],arguments[1]);case 3:return this.listener.call(this.target,arguments[0],arguments[1],arguments[2]);default:for(var e=new Array(arguments.length),t=0;t1&&(t=arguments[1]),t instanceof Error)throw t;var u=new Error('Unhandled "error" event. ('+t+")");throw u.context=t,u}if(!(n=o[e]))return!1;var a="function"==typeof n;switch(r=arguments.length){case 1:!function(e,t,n){if(t)e.call(n);else for(var r=e.length,s=m(e,r),i=0;i=0;o--)if(n[o]===t||n[o].listener===t){l=n[o].listener,i=o;break}if(i<0)return this;0===i?n.shift():function(e,t){for(var n=t,r=n+1,s=e.length;r=0;i--)this.removeListener(e,t[i]);return this},o.prototype.listeners=function(e){return _(this,e,!0)},o.prototype.rawListeners=function(e){return _(this,e,!1)},o.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):p.call(e,t)},o.prototype.listenerCount=p,o.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]}},{}],31:[function(e,t,n){(function(r){n.log=function(...e){return"object"==typeof console&&console.log&&console.log(...e)},n.formatArgs=function(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+t.exports.humanize(this.diff),!this.useColors)return;const n="color: "+this.color;e.splice(1,0,n,"color: inherit");let r=0,s=0;e[0].replace(/%[a-zA-Z%]/g,e=>{"%%"!==e&&(r++,"%c"===e&&(s=r))}),e.splice(s,0,n)},n.save=function(e){try{e?n.storage.setItem("debug",e):n.storage.removeItem("debug")}catch(e){}},n.load=function(){let e;try{e=n.storage.getItem("debug")}catch(e){}!e&&void 0!==r&&"env"in r&&(e=r.env.DEBUG);return e},n.useColors=function(){if("undefined"!=typeof window&&window.process&&("renderer"===window.process.type||window.process.__nwjs))return!0;if("undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},n.storage=function(){try{return localStorage}catch(e){}}(),n.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.exports=e("./common")(n);const{formatters:s}=t.exports;s.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}).call(this,e("_process"))},{"./common":32,_process:34}],32:[function(e,t,n){t.exports=function(t){function n(e){let t=0;for(let n=0;n{if("%%"===t)return t;l++;const i=r.formatters[s];if("function"==typeof i){const r=e[l];t=i.call(n,r),e.splice(l,1),l--}return t}),r.formatArgs.call(n,e),(n.log||r.log).apply(n,e)}return o.namespace=e,o.enabled=r.enabled(e),o.useColors=r.useColors(),o.color=n(e),o.destroy=s,o.extend=i,"function"==typeof r.init&&r.init(o),r.instances.push(o),o}function s(){const e=r.instances.indexOf(this);return-1!==e&&(r.instances.splice(e,1),!0)}function i(e,t){const n=r(this.namespace+(void 0===t?":":t)+e);return n.log=this.log,n}function o(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return r.debug=r,r.default=r,r.coerce=function(e){return e instanceof Error?e.stack||e.message:e},r.disable=function(){const e=[...r.names.map(o),...r.skips.map(o).map(e=>"-"+e)].join(",");return r.enable(""),e},r.enable=function(e){let t;r.save(e),r.names=[],r.skips=[];const n=("string"==typeof e?e:"").split(/[\s,]+/),s=n.length;for(t=0;t{r[e]=t[e]}),r.instances=[],r.names=[],r.skips=[],r.formatters={},r.selectColor=n,r.enable(r.load()),r}},{ms:33}],33:[function(e,t,n){var r=1e3,s=60*r,i=60*s,o=24*i,l=7*o,u=365.25*o;function a(e,t,n,r){var s=t>=1.5*n;return Math.round(e/n)+" "+r+(s?"s":"")}t.exports=function(e,t){t=t||{};var n=typeof e;if("string"===n&&e.length>0)return function(e){if((e=String(e)).length>100)return;var t=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(!t)return;var n=parseFloat(t[1]);switch((t[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return n*u;case"weeks":case"week":case"w":return n*l;case"days":case"day":case"d":return n*o;case"hours":case"hour":case"hrs":case"hr":case"h":return n*i;case"minutes":case"minute":case"mins":case"min":case"m":return n*s;case"seconds":case"second":case"secs":case"sec":case"s":return n*r;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return n;default:return}}(e);if("number"===n&&isFinite(e))return t.long?function(e){var t=Math.abs(e);if(t>=o)return a(e,t,o,"day");if(t>=i)return a(e,t,i,"hour");if(t>=s)return a(e,t,s,"minute");if(t>=r)return a(e,t,r,"second");return e+" ms"}(e):function(e){var t=Math.abs(e);if(t>=o)return Math.round(e/o)+"d";if(t>=i)return Math.round(e/i)+"h";if(t>=s)return Math.round(e/s)+"m";if(t>=r)return Math.round(e/r)+"s";return e+"ms"}(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))}},{}],34:[function(e,t,n){var r,s,i=t.exports={};function o(){throw new Error("setTimeout has not been defined")}function l(){throw new Error("clearTimeout has not been defined")}function u(e){if(r===setTimeout)return setTimeout(e,0);if((r===o||!r)&&setTimeout)return r=setTimeout,setTimeout(e,0);try{return r(e,0)}catch(t){try{return r.call(null,e,0)}catch(t){return r.call(this,e,0)}}}!function(){try{r="function"==typeof setTimeout?setTimeout:o}catch(e){r=o}try{s="function"==typeof clearTimeout?clearTimeout:l}catch(e){s=l}}();var a,c=[],h=!1,d=-1;function f(){h&&a&&(h=!1,a.length?c=a.concat(c):d=-1,c.length&&_())}function _(){if(!h){var e=u(f);h=!0;for(var t=c.length;t;){for(a=c,c=[];++d1)for(var n=1;n1&&(e[n[0]]=void 0),e};n.parseParams=function(e){return e.split(/;\s?/).reduce(l,{})},n.parseFmtpConfig=n.parseParams,n.parsePayloads=function(e){return e.toString().split(" ").map(Number)},n.parseRemoteCandidates=function(e){for(var t=[],n=e.split(" ").map(r),s=0;s=r)return e;var s=n[t];switch(t+=1,e){case"%%":return"%";case"%s":return String(s);case"%d":return Number(s);case"%v":return""}})}.apply(null,r)},o=["v","o","s","i","u","e","p","c","b","t","r","z","a"],l=["i","c","b","a"];t.exports=function(e,t){t=t||{},null==e.version&&(e.version=0),null==e.name&&(e.name=" "),e.media.forEach(function(e){null==e.payloads&&(e.payloads="")});var n=t.outerOrder||o,s=t.innerOrder||l,u=[];return n.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?u.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){u.push(i(t,n,e))})})}),e.media.forEach(function(e){u.push(i("m",r.m[0],e)),s.forEach(function(t){r[t].forEach(function(n){n.name in e&&null!=e[n.name]?u.push(i(t,n,e)):n.push in e&&null!=e[n.push]&&e[n.push].forEach(function(e){u.push(i(t,n,e))})})})}),u.join("\r\n")+"\r\n"}},{"./grammar":35}],39:[function(e,t,n){t.exports={name:"jssip",title:"JsSIP",description:"the Javascript SIP library",version:"3.7.5",homepage:"https://jssip.net",author:"José Luis Millán (https://github.com/jmillan)",contributors:["Iñaki Baz Castillo (https://github.com/ibc)"],types:"lib/JsSIP.d.ts",main:"lib-es5/JsSIP.js",keywords:["sip","websocket","webrtc","node","browser","library"],license:"MIT",repository:{type:"git",url:"https://github.com/versatica/JsSIP.git"},bugs:{url:"https://github.com/versatica/JsSIP/issues"},dependencies:{"@types/debug":"^4.1.5","@types/node":"^14.14.34",debug:"^4.3.1",events:"^3.3.0","sdp-transform":"^2.14.1"},devDependencies:{"@babel/core":"^7.13.10","@babel/preset-env":"^7.13.10","ansi-colors":"^3.2.4",browserify:"^16.5.1",eslint:"^5.16.0","fancy-log":"^1.3.3",gulp:"^4.0.2","gulp-babel":"^8.0.0","gulp-eslint":"^5.0.0","gulp-expect-file":"^1.0.2","gulp-header":"^2.0.9","gulp-nodeunit-runner":"^0.2.2","gulp-plumber":"^1.2.1","gulp-rename":"^1.4.0","gulp-uglify-es":"^1.0.4",pegjs:"^0.7.0","vinyl-buffer":"^1.0.1","vinyl-source-stream":"^2.0.0"},scripts:{lint:"gulp lint",test:"gulp test",prepublishOnly:"gulp babel"}}},{}]},{},[8])(8)}); \ No newline at end of file diff --git a/lib/Dialog.js b/lib/Dialog.js index 10e0a4e..795a86d 100644 --- a/lib/Dialog.js +++ b/lib/Dialog.js @@ -1,9 +1,11 @@ +const Logger = require('./Logger'); const SIPMessage = require('./SIPMessage'); const JsSIP_C = require('./Constants'); const Transactions = require('./Transactions'); const Dialog_RequestSender = require('./Dialog/RequestSender'); const Utils = require('./Utils'); -const debug = require('debug')('JsSIP:Dialog'); + +const logger = new Logger('Dialog'); const C = { // Dialog states. @@ -85,7 +87,7 @@ module.exports = class Dialog } this._ua.newDialog(this); - debug(`new ${type} dialog created with status ${this._state === C.STATUS_EARLY ? 'EARLY': 'CONFIRMED'}`); + logger.debug(`new ${type} dialog created with status ${this._state === C.STATUS_EARLY ? 'EARLY': 'CONFIRMED'}`); } get id() @@ -127,7 +129,7 @@ module.exports = class Dialog { this._state = C.STATUS_CONFIRMED; - debug(`dialog ${this._id.toString()} changed to CONFIRMED state`); + logger.debug(`dialog ${this._id.toString()} changed to CONFIRMED state`); if (type === 'UAC') { @@ -138,7 +140,7 @@ module.exports = class Dialog terminate() { - debug(`dialog ${this._id.toString()} deleted`); + logger.debug(`dialog ${this._id.toString()} deleted`); this._ua.destroyDialog(this); } diff --git a/lib/DigestAuthentication.js b/lib/DigestAuthentication.js index 4c7be61..44b439d 100644 --- a/lib/DigestAuthentication.js +++ b/lib/DigestAuthentication.js @@ -1,8 +1,7 @@ +const Logger = require('./Logger'); const Utils = require('./Utils'); -const debug = require('debug')('JsSIP:DigestAuthentication'); -const debugerror = require('debug')('JsSIP:ERROR:DigestAuthentication'); -debugerror.log = console.warn.bind(console); +const logger = new Logger('DigestAuthentication'); module.exports = class DigestAuthentication { @@ -35,7 +34,7 @@ module.exports = class DigestAuthentication return this._ha1; default: - debugerror('get() | cannot get "%s" parameter', parameter); + logger.warn('get() | cannot get "%s" parameter', parameter); return undefined; } @@ -58,7 +57,7 @@ module.exports = class DigestAuthentication { if (this._algorithm !== 'MD5') { - debugerror('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'); + logger.warn('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted'); return false; } @@ -70,14 +69,14 @@ module.exports = class DigestAuthentication if (!this._nonce) { - debugerror('authenticate() | challenge without Digest nonce, authentication aborted'); + logger.warn('authenticate() | challenge without Digest nonce, authentication aborted'); return false; } if (!this._realm) { - debugerror('authenticate() | challenge without Digest realm, authentication aborted'); + logger.warn('authenticate() | challenge without Digest realm, authentication aborted'); return false; } @@ -88,7 +87,7 @@ module.exports = class DigestAuthentication // If ha1 is not provided we cannot authenticate. if (!this._credentials.ha1) { - debugerror('authenticate() | no plain SIP password nor ha1 provided, authentication aborted'); + logger.warn('authenticate() | no plain SIP password nor ha1 provided, authentication aborted'); return false; } @@ -96,7 +95,7 @@ module.exports = class DigestAuthentication // If the realm does not match the stored realm we cannot authenticate. if (this._credentials.realm !== this._realm) { - debugerror('authenticate() | no plain SIP password, and stored `realm` does not match the given `realm`, cannot authenticate [stored:"%s", given:"%s"]', this._credentials.realm, this._realm); + logger.warn('authenticate() | no plain SIP password, and stored `realm` does not match the given `realm`, cannot authenticate [stored:"%s", given:"%s"]', this._credentials.realm, this._realm); return false; } @@ -116,7 +115,7 @@ module.exports = class DigestAuthentication else { // Otherwise 'qop' is present but does not contain 'auth' or 'auth-int', so abort here. - debugerror('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted'); + logger.warn('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted'); return false; } @@ -166,7 +165,7 @@ module.exports = class DigestAuthentication a2 = `${this._method}:${this._uri}`; ha2 = Utils.calculateMD5(a2); - debug('authenticate() | using qop=auth [a2:"%s"]', a2); + logger.debug('authenticate() | using qop=auth [a2:"%s"]', a2); // Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2). this._response = Utils.calculateMD5(`${this._ha1}:${this._nonce}:${this._ncHex}:${this._cnonce}:auth:${ha2}`); @@ -178,7 +177,7 @@ module.exports = class DigestAuthentication a2 = `${this._method}:${this._uri}:${Utils.calculateMD5(body ? body : '')}`; ha2 = Utils.calculateMD5(a2); - debug('authenticate() | using qop=auth-int [a2:"%s"]', a2); + logger.debug('authenticate() | using qop=auth-int [a2:"%s"]', a2); // Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2). this._response = Utils.calculateMD5(`${this._ha1}:${this._nonce}:${this._ncHex}:${this._cnonce}:auth-int:${ha2}`); @@ -190,13 +189,13 @@ module.exports = class DigestAuthentication a2 = `${this._method}:${this._uri}`; ha2 = Utils.calculateMD5(a2); - debug('authenticate() | using qop=null [a2:"%s"]', a2); + logger.debug('authenticate() | using qop=null [a2:"%s"]', a2); // Response = MD5(HA1:nonce:HA2). this._response = Utils.calculateMD5(`${this._ha1}:${this._nonce}:${ha2}`); } - debug('authenticate() | response generated'); + logger.debug('authenticate() | response generated'); return true; } diff --git a/lib/Logger.js b/lib/Logger.js new file mode 100644 index 0000000..4feeceb --- /dev/null +++ b/lib/Logger.js @@ -0,0 +1,42 @@ +const debug = require('debug'); + +const APP_NAME = 'JsSIP'; + +module.exports = class Logger +{ + constructor(prefix) + { + if (prefix) + { + this._debug = debug.default(`${APP_NAME}:${prefix}`); + this._warn = debug.default(`${APP_NAME}:WARN:${prefix}`); + this._error = debug.default(`${APP_NAME}:ERROR:${prefix}`); + } + else + { + this._debug = debug.default(APP_NAME); + this._warn = debug.default(`${APP_NAME}:WARN`); + this._error = debug.default(`${APP_NAME}:ERROR`); + } + /* eslint-disable no-console */ + this._debug.log = console.info.bind(console); + this._warn.log = console.warn.bind(console); + this._error.log = console.error.bind(console); + /* eslint-enable no-console */ + } + + get debug() + { + return this._debug; + } + + get warn() + { + return this._warn; + } + + get error() + { + return this._error; + } +}; diff --git a/lib/Message.js b/lib/Message.js index 98a14f8..fc0f794 100644 --- a/lib/Message.js +++ b/lib/Message.js @@ -1,10 +1,12 @@ const EventEmitter = require('events').EventEmitter; +const Logger = require('./Logger'); const JsSIP_C = require('./Constants'); const SIPMessage = require('./SIPMessage'); const Utils = require('./Utils'); const RequestSender = require('./RequestSender'); const Exceptions = require('./Exceptions'); -const debug = require('debug')('JsSIP:Message'); + +const logger = new Logger('Message'); module.exports = class Message extends EventEmitter { @@ -249,11 +251,11 @@ module.exports = class Message extends EventEmitter _failed(originator, response, cause) { - debug('MESSAGE failed'); + logger.debug('MESSAGE failed'); this._close(); - debug('emit "failed"'); + logger.debug('emit "failed"'); this.emit('failed', { originator, @@ -264,11 +266,11 @@ module.exports = class Message extends EventEmitter _succeeded(originator, response) { - debug('MESSAGE succeeded'); + logger.debug('MESSAGE succeeded'); this._close(); - debug('emit "succeeded"'); + logger.debug('emit "succeeded"'); this.emit('succeeded', { originator, diff --git a/lib/Parser.js b/lib/Parser.js index c294112..e7a5090 100644 --- a/lib/Parser.js +++ b/lib/Parser.js @@ -1,8 +1,8 @@ +const Logger = require('./Logger'); const Grammar = require('./Grammar'); const SIPMessage = require('./SIPMessage'); -const debugerror = require('debug')('JsSIP:ERROR:Parser'); -debugerror.log = console.warn.bind(console); +const logger = new Logger('Parser'); /** * Parse SIP Message @@ -15,7 +15,7 @@ exports.parseMessage = (data, ua) => if (headerEnd === -1) { - debugerror('parseMessage() | no CRLF found, not a SIP message'); + logger.warn('parseMessage() | no CRLF found, not a SIP message'); return; } @@ -26,7 +26,7 @@ exports.parseMessage = (data, ua) => if (parsed === -1) { - debugerror(`parseMessage() | error parsing first line of SIP message: "${firstLine}"`); + logger.warn(`parseMessage() | error parsing first line of SIP message: "${firstLine}"`); return; } @@ -62,7 +62,7 @@ exports.parseMessage = (data, ua) => // Data.indexOf returned -1 due to a malformed message. else if (headerEnd === -1) { - debugerror('parseMessage() | malformed message'); + logger.warn('parseMessage() | malformed message'); return; } @@ -71,7 +71,7 @@ exports.parseMessage = (data, ua) => if (parsed !== true) { - debugerror('parseMessage() |', parsed.error); + logger.warn('parseMessage() |', parsed.error); return; } diff --git a/lib/RTCSession.js b/lib/RTCSession.js index 7003c25..2dae2b0 100644 --- a/lib/RTCSession.js +++ b/lib/RTCSession.js @@ -2,6 +2,7 @@ const EventEmitter = require('events').EventEmitter; const sdp_transform = require('sdp-transform'); +const Logger = require('./Logger'); const JsSIP_C = require('./Constants'); const Exceptions = require('./Exceptions'); const Transactions = require('./Transactions'); @@ -15,10 +16,8 @@ const RTCSession_Info = require('./RTCSession/Info'); const RTCSession_ReferNotifier = require('./RTCSession/ReferNotifier'); const RTCSession_ReferSubscriber = require('./RTCSession/ReferSubscriber'); const URI = require('./URI'); -const debug = require('debug')('JsSIP:RTCSession'); -const debugerror = require('debug')('JsSIP:ERROR:RTCSession'); -debugerror.log = console.warn.bind(console); +const logger = new Logger('RTCSession'); const C = { // RTCSession states. @@ -51,7 +50,7 @@ module.exports = class RTCSession extends EventEmitter constructor(ua) { - debug('new'); + logger.debug('new'); super(); @@ -263,7 +262,7 @@ module.exports = class RTCSession extends EventEmitter connect(target, options = {}, initCallback) { - debug('connect()'); + logger.debug('connect()'); const originalTarget = target; const eventHandlers = Utils.cloneObject(options.eventHandlers); @@ -398,7 +397,7 @@ module.exports = class RTCSession extends EventEmitter init_incoming(request, initCallback) { - debug('init_incoming()'); + logger.debug('init_incoming()'); let expires; const contentType = request.hasHeader('Content-Type') ? @@ -506,7 +505,7 @@ module.exports = class RTCSession extends EventEmitter */ answer(options = {}) { - debug('answer()'); + logger.debug('answer()'); const request = this._request; const extraHeaders = Utils.cloneArray(options.extraHeaders); @@ -674,7 +673,7 @@ module.exports = class RTCSession extends EventEmitter request.reply(480); this._failed('local', null, JsSIP_C.causes.USER_DENIED_MEDIA_ACCESS); - debugerror('emit "getusermediafailed" [error:%o]', error); + logger.warn('emit "getusermediafailed" [error:%o]', error); this.emit('getusermediafailed', error); @@ -709,7 +708,7 @@ module.exports = class RTCSession extends EventEmitter const e = { originator: 'remote', type: 'offer', sdp: request.body }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); this.emit('sdp', e); const offer = new RTCSessionDescription({ type: 'offer', sdp: e.sdp }); @@ -722,7 +721,7 @@ module.exports = class RTCSession extends EventEmitter this._failed('system', null, JsSIP_C.causes.WEBRTC_ERROR); - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); this.emit('peerconnection:setremotedescriptionfailed', error); @@ -796,7 +795,7 @@ module.exports = class RTCSession extends EventEmitter return; } - debugerror(error); + logger.warn(error); }); } @@ -805,7 +804,7 @@ module.exports = class RTCSession extends EventEmitter */ terminate(options = {}) { - debug('terminate()'); + logger.debug('terminate()'); const cause = options.cause || JsSIP_C.causes.BYE; const extraHeaders = Utils.cloneArray(options.extraHeaders); @@ -827,7 +826,7 @@ module.exports = class RTCSession extends EventEmitter case C.STATUS_NULL: case C.STATUS_INVITE_SENT: case C.STATUS_1XX_RECEIVED: - debug('canceling session'); + logger.debug('canceling session'); if (status_code && (status_code < 200 || status_code >= 700)) { @@ -858,7 +857,7 @@ module.exports = class RTCSession extends EventEmitter // - UAS - case C.STATUS_WAITING_FOR_ANSWER: case C.STATUS_ANSWERED: - debug('rejecting session'); + logger.debug('rejecting session'); status_code = status_code || 480; @@ -873,7 +872,7 @@ module.exports = class RTCSession extends EventEmitter case C.STATUS_WAITING_FOR_ACK: case C.STATUS_CONFIRMED: - debug('terminating session'); + logger.debug('terminating session'); reason_phrase = options.reason_phrase || JsSIP_C.REASON_PHRASE[status_code] || ''; @@ -949,7 +948,7 @@ module.exports = class RTCSession extends EventEmitter sendDTMF(tones, options = {}) { - debug('sendDTMF() | tones: %s', tones); + logger.debug('sendDTMF() | tones: %s', tones); let position = 0; let duration = options.duration || null; @@ -999,12 +998,12 @@ module.exports = class RTCSession extends EventEmitter } else if (duration < RTCSession_DTMF.C.MIN_DURATION) { - debug(`"duration" value is lower than the minimum allowed, setting it to ${RTCSession_DTMF.C.MIN_DURATION} milliseconds`); + logger.debug(`"duration" value is lower than the minimum allowed, setting it to ${RTCSession_DTMF.C.MIN_DURATION} milliseconds`); duration = RTCSession_DTMF.C.MIN_DURATION; } else if (duration > RTCSession_DTMF.C.MAX_DURATION) { - debug(`"duration" value is greater than the maximum allowed, setting it to ${RTCSession_DTMF.C.MAX_DURATION} milliseconds`); + logger.debug(`"duration" value is greater than the maximum allowed, setting it to ${RTCSession_DTMF.C.MAX_DURATION} milliseconds`); duration = RTCSession_DTMF.C.MAX_DURATION; } else @@ -1024,7 +1023,7 @@ module.exports = class RTCSession extends EventEmitter } else if (interToneGap < RTCSession_DTMF.C.MIN_INTER_TONE_GAP) { - debug(`"interToneGap" value is lower than the minimum allowed, setting it to ${RTCSession_DTMF.C.MIN_INTER_TONE_GAP} milliseconds`); + logger.debug(`"interToneGap" value is lower than the minimum allowed, setting it to ${RTCSession_DTMF.C.MIN_INTER_TONE_GAP} milliseconds`); interToneGap = RTCSession_DTMF.C.MIN_INTER_TONE_GAP; } else @@ -1102,7 +1101,7 @@ module.exports = class RTCSession extends EventEmitter sendInfo(contentType, body, options = {}) { - debug('sendInfo()'); + logger.debug('sendInfo()'); // Check Session Status. if (this._status !== C.STATUS_CONFIRMED && this._status !== C.STATUS_WAITING_FOR_ACK) @@ -1120,7 +1119,7 @@ module.exports = class RTCSession extends EventEmitter */ mute(options = { audio: true, video: false }) { - debug('mute()'); + logger.debug('mute()'); let audioMuted = false, videoMuted = false; @@ -1152,7 +1151,7 @@ module.exports = class RTCSession extends EventEmitter */ unmute(options = { audio: true, video: true }) { - debug('unmute()'); + logger.debug('unmute()'); let audioUnMuted = false, videoUnMuted = false; @@ -1192,7 +1191,7 @@ module.exports = class RTCSession extends EventEmitter */ hold(options = {}, done) { - debug('hold()'); + logger.debug('hold()'); if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { @@ -1248,7 +1247,7 @@ module.exports = class RTCSession extends EventEmitter unhold(options = {}, done) { - debug('unhold()'); + logger.debug('unhold()'); if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) { @@ -1304,7 +1303,7 @@ module.exports = class RTCSession extends EventEmitter renegotiate(options = {}, done) { - debug('renegotiate()'); + logger.debug('renegotiate()'); const rtcOfferConstraints = options.rtcOfferConstraints || null; @@ -1361,7 +1360,7 @@ module.exports = class RTCSession extends EventEmitter */ refer(target, options) { - debug('refer()'); + logger.debug('refer()'); const originalTarget = target; @@ -1408,7 +1407,7 @@ module.exports = class RTCSession extends EventEmitter */ sendRequest(method, options) { - debug('sendRequest()'); + logger.debug('sendRequest()'); return this._dialog.sendRequest(method, options); } @@ -1418,7 +1417,7 @@ module.exports = class RTCSession extends EventEmitter */ receiveRequest(request) { - debug('receiveRequest()'); + logger.debug('receiveRequest()'); if (request.method === JsSIP_C.CANCEL) { @@ -1471,7 +1470,7 @@ module.exports = class RTCSession extends EventEmitter const e = { originator: 'remote', type: 'answer', sdp: request.body }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); this.emit('sdp', e); const answer = new RTCSessionDescription({ type: 'answer', sdp: e.sdp }); @@ -1492,7 +1491,7 @@ module.exports = class RTCSession extends EventEmitter status_code : 488 }); - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); this.emit('peerconnection:setremotedescriptionfailed', error); }); } @@ -1609,7 +1608,7 @@ module.exports = class RTCSession extends EventEmitter onTransportError() { - debugerror('onTransportError()'); + logger.warn('onTransportError()'); if (this._status !== C.STATUS_TERMINATED) { @@ -1623,7 +1622,7 @@ module.exports = class RTCSession extends EventEmitter onRequestTimeout() { - debugerror('onRequestTimeout()'); + logger.warn('onRequestTimeout()'); if (this._status !== C.STATUS_TERMINATED) { @@ -1637,7 +1636,7 @@ module.exports = class RTCSession extends EventEmitter onDialogError() { - debugerror('onDialogError()'); + logger.warn('onDialogError()'); if (this._status !== C.STATUS_TERMINATED) { @@ -1652,7 +1651,7 @@ module.exports = class RTCSession extends EventEmitter // Called from DTMF handler. newDTMF(data) { - debug('newDTMF()'); + logger.debug('newDTMF()'); this.emit('newDTMF', data); } @@ -1660,7 +1659,7 @@ module.exports = class RTCSession extends EventEmitter // Called from Info handler. newInfo(data) { - debug('newInfo()'); + logger.debug('newInfo()'); this.emit('newInfo', data); } @@ -1672,7 +1671,7 @@ module.exports = class RTCSession extends EventEmitter { if (!this._rtcReady) { - debug('_isReadyToReOffer() | internal WebRTC status not ready'); + logger.debug('_isReadyToReOffer() | internal WebRTC status not ready'); return false; } @@ -1680,7 +1679,7 @@ module.exports = class RTCSession extends EventEmitter // No established yet. if (!this._dialog) { - debug('_isReadyToReOffer() | session not established yet'); + logger.debug('_isReadyToReOffer() | session not established yet'); return false; } @@ -1689,7 +1688,7 @@ module.exports = class RTCSession extends EventEmitter if (this._dialog.uac_pending_reply === true || this._dialog.uas_pending_reply === true) { - debug('_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress'); + logger.debug('_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress'); return false; } @@ -1699,12 +1698,12 @@ module.exports = class RTCSession extends EventEmitter _close() { - debug('close()'); + logger.debug('close()'); // Close local MediaStream if it was not given by the user. if (this._localMediaStream && this._localMediaStreamLocallyGenerated) { - debug('close() | closing local MediaStream'); + logger.debug('close() | closing local MediaStream'); Utils.closeMediaStream(this._localMediaStream); } @@ -1725,7 +1724,7 @@ module.exports = class RTCSession extends EventEmitter } catch (error) { - debugerror('close() | error closing the RTCPeerConnection: %o', error); + logger.warn('close() | error closing the RTCPeerConnection: %o', error); } } @@ -1823,7 +1822,7 @@ module.exports = class RTCSession extends EventEmitter { if (this._status === C.STATUS_WAITING_FOR_ACK) { - debug('no ACK received, terminating the session'); + logger.debug('no ACK received, terminating the session'); clearTimeout(this._timers.invite2xxTimer); this.sendRequest(JsSIP_C.BYE); @@ -1852,7 +1851,7 @@ module.exports = class RTCSession extends EventEmitter } }); - debug('emit "peerconnection"'); + logger.debug('emit "peerconnection"'); this.emit('peerconnection', { peerconnection : this._connection @@ -1861,7 +1860,7 @@ module.exports = class RTCSession extends EventEmitter _createLocalDescription(type, constraints) { - debug('createLocalDescription()'); + logger.debug('createLocalDescription()'); if (type !== 'offer' && type !== 'answer') throw new Error(`createLocalDescription() | invalid type "${type}"`); @@ -1879,7 +1878,7 @@ module.exports = class RTCSession extends EventEmitter return connection.createOffer(constraints) .catch((error) => { - debugerror('emit "peerconnection:createofferfailed" [error:%o]', error); + logger.warn('emit "peerconnection:createofferfailed" [error:%o]', error); this.emit('peerconnection:createofferfailed', error); @@ -1891,7 +1890,7 @@ module.exports = class RTCSession extends EventEmitter return connection.createAnswer(constraints) .catch((error) => { - debugerror('emit "peerconnection:createanswerfailed" [error:%o]', error); + logger.warn('emit "peerconnection:createanswerfailed" [error:%o]', error); this.emit('peerconnection:createanswerfailed', error); @@ -1907,7 +1906,7 @@ module.exports = class RTCSession extends EventEmitter { this._rtcReady = true; - debugerror('emit "peerconnection:setlocaldescriptionfailed" [error:%o]', error); + logger.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]', error); this.emit('peerconnection:setlocaldescriptionfailed', error); @@ -1923,7 +1922,7 @@ module.exports = class RTCSession extends EventEmitter const e = { originator: 'local', type: type, sdp: connection.localDescription.sdp }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); this.emit('sdp', e); @@ -1947,7 +1946,7 @@ module.exports = class RTCSession extends EventEmitter const e = { originator: 'local', type: type, sdp: connection.localDescription.sdp }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); this.emit('sdp', e); @@ -2008,7 +2007,7 @@ module.exports = class RTCSession extends EventEmitter // Dialog has been successfully created. if (early_dialog.error) { - debug(early_dialog.error); + logger.debug(early_dialog.error); this._failed('remote', message, JsSIP_C.causes.INTERNAL_ERROR); return false; @@ -2043,7 +2042,7 @@ module.exports = class RTCSession extends EventEmitter if (dialog.error) { - debug(dialog.error); + logger.debug(dialog.error); this._failed('remote', message, JsSIP_C.causes.INTERNAL_ERROR); return false; @@ -2063,7 +2062,7 @@ module.exports = class RTCSession extends EventEmitter _receiveReinvite(request) { - debug('receiveReinvite()'); + logger.debug('receiveReinvite()'); const contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined; @@ -2132,7 +2131,7 @@ module.exports = class RTCSession extends EventEmitter // Request with SDP. if (contentType !== 'application/sdp') { - debug('invalid Content-Type'); + logger.debug('invalid Content-Type'); request.reply(415); return; @@ -2151,7 +2150,7 @@ module.exports = class RTCSession extends EventEmitter }) .catch((error) => { - debugerror(error); + logger.warn(error); }); function sendAnswer(desc) @@ -2187,7 +2186,7 @@ module.exports = class RTCSession extends EventEmitter */ _receiveUpdate(request) { - debug('receiveUpdate()'); + logger.debug('receiveUpdate()'); const contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined; @@ -2237,7 +2236,7 @@ module.exports = class RTCSession extends EventEmitter if (contentType !== 'application/sdp') { - debug('invalid Content-Type'); + logger.debug('invalid Content-Type'); request.reply(415); @@ -2257,7 +2256,7 @@ module.exports = class RTCSession extends EventEmitter }) .catch((error) => { - debugerror(error); + logger.warn(error); }); function sendAnswer(desc) @@ -2278,7 +2277,7 @@ module.exports = class RTCSession extends EventEmitter _processInDialogSdpOffer(request) { - debug('_processInDialogSdpOffer()'); + logger.debug('_processInDialogSdpOffer()'); const sdp = request.parseSDP(); @@ -2307,7 +2306,7 @@ module.exports = class RTCSession extends EventEmitter const e = { originator: 'remote', type: 'offer', sdp: request.body }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); this.emit('sdp', e); const offer = new RTCSessionDescription({ type: 'offer', sdp: e.sdp }); @@ -2325,7 +2324,7 @@ module.exports = class RTCSession extends EventEmitter .catch((error) => { request.reply(488); - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); this.emit('peerconnection:setremotedescriptionfailed', error); @@ -2362,14 +2361,14 @@ module.exports = class RTCSession extends EventEmitter .catch((error) => { request.reply(500); - debugerror('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]', error); + logger.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]', error); throw error; }); }) .catch((error) => { - debugerror('_processInDialogSdpOffer() failed [error: %o]', error); + logger.warn('_processInDialogSdpOffer() failed [error: %o]', error); }); return this._connectionPromiseQueue; @@ -2380,11 +2379,11 @@ module.exports = class RTCSession extends EventEmitter */ _receiveRefer(request) { - debug('receiveRefer()'); + logger.debug('receiveRefer()'); if (!request.refer_to) { - debug('no Refer-To header field present in REFER'); + logger.debug('no Refer-To header field present in REFER'); request.reply(400); return; @@ -2392,7 +2391,7 @@ module.exports = class RTCSession extends EventEmitter if (request.refer_to.uri.scheme !== JsSIP_C.SIP) { - debug('Refer-To header field points to a non-SIP URI scheme'); + logger.debug('Refer-To header field points to a non-SIP URI scheme'); request.reply(416); return; @@ -2403,7 +2402,7 @@ module.exports = class RTCSession extends EventEmitter const notifier = new RTCSession_ReferNotifier(this, request.cseq); - debug('emit "refer"'); + logger.debug('emit "refer"'); // Emit 'refer'. this.emit('refer', { @@ -2475,7 +2474,7 @@ module.exports = class RTCSession extends EventEmitter */ _receiveNotify(request) { - debug('receiveNotify()'); + logger.debug('receiveNotify()'); if (!request.event) { @@ -2529,7 +2528,7 @@ module.exports = class RTCSession extends EventEmitter */ _receiveReplaces(request) { - debug('receiveReplaces()'); + logger.debug('receiveReplaces()'); function accept(initCallback) { @@ -2552,7 +2551,7 @@ module.exports = class RTCSession extends EventEmitter function reject() { - debug('Replaced INVITE rejected by the user'); + logger.debug('Replaced INVITE rejected by the user'); request.reply(486); } @@ -2615,7 +2614,7 @@ module.exports = class RTCSession extends EventEmitter this._failed('local', null, JsSIP_C.causes.USER_DENIED_MEDIA_ACCESS); - debugerror('emit "getusermediafailed" [error:%o]', error); + logger.warn('emit "getusermediafailed" [error:%o]', error); this.emit('getusermediafailed', error); @@ -2661,7 +2660,7 @@ module.exports = class RTCSession extends EventEmitter this._request.body = desc; this._status = C.STATUS_INVITE_SENT; - debug('emit "sending" [request:%o]', this._request); + logger.debug('emit "sending" [request:%o]', this._request); // Emit 'sending' so the app can mangle the body before the request is sent. this.emit('sending', { @@ -2677,7 +2676,7 @@ module.exports = class RTCSession extends EventEmitter return; } - debugerror(error); + logger.warn(error); }); } @@ -2693,7 +2692,7 @@ module.exports = class RTCSession extends EventEmitter if (!(sender && sender.dtmf)) { - debugerror('sendDTMF() | no local audio track to send DTMF with'); + logger.warn('sendDTMF() | no local audio track to send DTMF with'); return; } @@ -2706,7 +2705,7 @@ module.exports = class RTCSession extends EventEmitter */ _receiveInviteResponse(response) { - debug('receiveInviteResponse()'); + logger.debug('receiveInviteResponse()'); // Handle 2XX retransmissions and responses from forked requests. if (this._dialog && (response.status_code >=200 && response.status_code <=299)) @@ -2732,7 +2731,7 @@ module.exports = class RTCSession extends EventEmitter if (dialog.error !== undefined) { - debug(dialog.error); + logger.debug(dialog.error); return; } @@ -2776,7 +2775,7 @@ module.exports = class RTCSession extends EventEmitter // Do nothing with 1xx responses without To tag. if (!response.to_tag) { - debug('1xx response received without to tag'); + logger.debug('1xx response received without to tag'); break; } @@ -2800,7 +2799,7 @@ module.exports = class RTCSession extends EventEmitter const e = { originator: 'remote', type: 'answer', sdp: response.body }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); this.emit('sdp', e); const answer = new RTCSessionDescription({ type: 'answer', sdp: e.sdp }); @@ -2810,7 +2809,7 @@ module.exports = class RTCSession extends EventEmitter .then(() => this._progress('remote', response)) .catch((error) => { - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); this.emit('peerconnection:setremotedescriptionfailed', error); }); @@ -2836,7 +2835,7 @@ module.exports = class RTCSession extends EventEmitter const e = { originator: 'remote', type: 'answer', sdp: response.body }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); this.emit('sdp', e); const answer = new RTCSessionDescription({ type: 'answer', sdp: e.sdp }); @@ -2874,7 +2873,7 @@ module.exports = class RTCSession extends EventEmitter this._acceptAndTerminate(response, 488, 'Not Acceptable Here'); this._failed('remote', response, JsSIP_C.causes.BAD_MEDIA_DESCRIPTION); - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); this.emit('peerconnection:setremotedescriptionfailed', error); }); @@ -2896,7 +2895,7 @@ module.exports = class RTCSession extends EventEmitter */ _sendReinvite(options = {}) { - debug('sendReinvite()'); + logger.debug('sendReinvite()'); const extraHeaders = Utils.cloneArray(options.extraHeaders); const eventHandlers = Utils.cloneObject(options.eventHandlers); @@ -2922,7 +2921,7 @@ module.exports = class RTCSession extends EventEmitter const e = { originator: 'local', type: 'offer', sdp }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); this.emit('sdp', e); this.sendRequest(JsSIP_C.INVITE, { @@ -2989,7 +2988,7 @@ module.exports = class RTCSession extends EventEmitter const e = { originator: 'remote', type: 'answer', sdp: response.body }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); this.emit('sdp', e); const answer = new RTCSessionDescription({ type: 'answer', sdp: e.sdp }); @@ -3007,7 +3006,7 @@ module.exports = class RTCSession extends EventEmitter { onFailed.call(this); - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); this.emit('peerconnection:setremotedescriptionfailed', error); }); @@ -3027,7 +3026,7 @@ module.exports = class RTCSession extends EventEmitter */ _sendUpdate(options = {}) { - debug('sendUpdate()'); + logger.debug('sendUpdate()'); const extraHeaders = Utils.cloneArray(options.extraHeaders); const eventHandlers = Utils.cloneObject(options.eventHandlers); @@ -3057,7 +3056,7 @@ module.exports = class RTCSession extends EventEmitter const e = { originator: 'local', type: 'offer', sdp }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); this.emit('sdp', e); this.sendRequest(JsSIP_C.UPDATE, { @@ -3155,7 +3154,7 @@ module.exports = class RTCSession extends EventEmitter const e = { originator: 'remote', type: 'answer', sdp: response.body }; - debug('emit "sdp"'); + logger.debug('emit "sdp"'); this.emit('sdp', e); const answer = new RTCSessionDescription({ type: 'answer', sdp: e.sdp }); @@ -3173,7 +3172,7 @@ module.exports = class RTCSession extends EventEmitter { onFailed.call(this); - debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); + logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error); this.emit('peerconnection:setremotedescriptionfailed', error); }); @@ -3194,7 +3193,7 @@ module.exports = class RTCSession extends EventEmitter _acceptAndTerminate(response, status_code, reason_phrase) { - debug('acceptAndTerminate()'); + logger.debug('acceptAndTerminate()'); const extraHeaders = []; @@ -3233,7 +3232,7 @@ module.exports = class RTCSession extends EventEmitter // Local hold. if (this._localHold && !this._remoteHold) { - debug('mangleOffer() | me on hold, mangling offer'); + logger.debug('mangleOffer() | me on hold, mangling offer'); for (const m of sdp.media) { if (holdMediaTypes.indexOf(m.type) === -1) @@ -3257,7 +3256,7 @@ module.exports = class RTCSession extends EventEmitter // Local and remote hold. else if (this._localHold && this._remoteHold) { - debug('mangleOffer() | both on hold, mangling offer'); + logger.debug('mangleOffer() | both on hold, mangling offer'); for (const m of sdp.media) { if (holdMediaTypes.indexOf(m.type) === -1) @@ -3270,7 +3269,7 @@ module.exports = class RTCSession extends EventEmitter // Remote hold. else if (this._remoteHold) { - debug('mangleOffer() | remote on hold, mangling offer'); + logger.debug('mangleOffer() | remote on hold, mangling offer'); for (const m of sdp.media) { if (holdMediaTypes.indexOf(m.type) === -1) @@ -3388,7 +3387,7 @@ module.exports = class RTCSession extends EventEmitter { if (this._status === C.STATUS_TERMINATED) { return; } - debug('runSessionTimer() | sending session refresh request'); + logger.debug('runSessionTimer() | sending session refresh request'); if (this._sessionTimers.refreshMethod === JsSIP_C.UPDATE) { @@ -3408,7 +3407,7 @@ module.exports = class RTCSession extends EventEmitter { if (this._status === C.STATUS_TERMINATED) { return; } - debugerror('runSessionTimer() | timer expired, terminating the session'); + logger.warn('runSessionTimer() | timer expired, terminating the session'); this.terminate({ cause : JsSIP_C.causes.REQUEST_TIMEOUT, @@ -3447,7 +3446,7 @@ module.exports = class RTCSession extends EventEmitter _newRTCSession(originator, request) { - debug('newRTCSession()'); + logger.debug('newRTCSession()'); this._ua.newRTCSession(this, { originator, @@ -3458,9 +3457,9 @@ module.exports = class RTCSession extends EventEmitter _connecting(request) { - debug('session connecting'); + logger.debug('session connecting'); - debug('emit "connecting"'); + logger.debug('emit "connecting"'); this.emit('connecting', { request @@ -3469,9 +3468,9 @@ module.exports = class RTCSession extends EventEmitter _progress(originator, response) { - debug('session progress'); + logger.debug('session progress'); - debug('emit "progress"'); + logger.debug('emit "progress"'); this.emit('progress', { originator, @@ -3481,11 +3480,11 @@ module.exports = class RTCSession extends EventEmitter _accepted(originator, message) { - debug('session accepted'); + logger.debug('session accepted'); this._start_time = new Date(); - debug('emit "accepted"'); + logger.debug('emit "accepted"'); this.emit('accepted', { originator, @@ -3495,11 +3494,11 @@ module.exports = class RTCSession extends EventEmitter _confirmed(originator, ack) { - debug('session confirmed'); + logger.debug('session confirmed'); this._is_confirmed = true; - debug('emit "confirmed"'); + logger.debug('emit "confirmed"'); this.emit('confirmed', { originator, @@ -3509,13 +3508,13 @@ module.exports = class RTCSession extends EventEmitter _ended(originator, message, cause) { - debug('session ended'); + logger.debug('session ended'); this._end_time = new Date(); this._close(); - debug('emit "ended"'); + logger.debug('emit "ended"'); this.emit('ended', { originator, @@ -3526,10 +3525,10 @@ module.exports = class RTCSession extends EventEmitter _failed(originator, message, cause) { - debug('session failed'); + logger.debug('session failed'); // Emit private '_failed' event first. - debug('emit "_failed"'); + logger.debug('emit "_failed"'); this.emit('_failed', { originator, @@ -3539,7 +3538,7 @@ module.exports = class RTCSession extends EventEmitter this._close(); - debug('emit "failed"'); + logger.debug('emit "failed"'); this.emit('failed', { originator, @@ -3550,11 +3549,11 @@ module.exports = class RTCSession extends EventEmitter _onhold(originator) { - debug('session onhold'); + logger.debug('session onhold'); this._setLocalMediaStatus(); - debug('emit "hold"'); + logger.debug('emit "hold"'); this.emit('hold', { originator @@ -3563,11 +3562,11 @@ module.exports = class RTCSession extends EventEmitter _onunhold(originator) { - debug('session onunhold'); + logger.debug('session onunhold'); this._setLocalMediaStatus(); - debug('emit "unhold"'); + logger.debug('emit "unhold"'); this.emit('unhold', { originator @@ -3576,11 +3575,11 @@ module.exports = class RTCSession extends EventEmitter _onmute({ audio, video }) { - debug('session onmute'); + logger.debug('session onmute'); this._setLocalMediaStatus(); - debug('emit "muted"'); + logger.debug('emit "muted"'); this.emit('muted', { audio, @@ -3590,11 +3589,11 @@ module.exports = class RTCSession extends EventEmitter _onunmute({ audio, video }) { - debug('session onunmute'); + logger.debug('session onunmute'); this._setLocalMediaStatus(); - debug('emit "unmuted"'); + logger.debug('emit "unmuted"'); this.emit('unmuted', { audio, diff --git a/lib/RTCSession/DTMF.js b/lib/RTCSession/DTMF.js index 17eabcd..e86bb93 100644 --- a/lib/RTCSession/DTMF.js +++ b/lib/RTCSession/DTMF.js @@ -1,11 +1,10 @@ const EventEmitter = require('events').EventEmitter; +const Logger = require('../Logger'); const JsSIP_C = require('../Constants'); const Exceptions = require('../Exceptions'); const Utils = require('../Utils'); -const debug = require('debug')('JsSIP:RTCSession:DTMF'); -const debugerror = require('debug')('JsSIP:ERROR:RTCSession:DTMF'); -debugerror.log = console.warn.bind(console); +const logger = new Logger('RTCSession:DTMF'); const C = { MIN_DURATION : 70, @@ -173,7 +172,7 @@ module.exports = class DTMF extends EventEmitter if (!this._tone) { - debug('invalid INFO DTMF received, discarded'); + logger.debug('invalid INFO DTMF received, discarded'); } else { diff --git a/lib/RTCSession/Info.js b/lib/RTCSession/Info.js index 928e0a7..c331c35 100644 --- a/lib/RTCSession/Info.js +++ b/lib/RTCSession/Info.js @@ -1,7 +1,4 @@ const EventEmitter = require('events').EventEmitter; -const debugerror = require('debug')('JsSIP:ERROR:RTCSession:Info'); - -debugerror.log = console.warn.bind(console); const JsSIP_C = require('../Constants'); const Exceptions = require('../Exceptions'); const Utils = require('../Utils'); diff --git a/lib/RTCSession/ReferNotifier.js b/lib/RTCSession/ReferNotifier.js index 27936e7..dcf5071 100644 --- a/lib/RTCSession/ReferNotifier.js +++ b/lib/RTCSession/ReferNotifier.js @@ -1,5 +1,7 @@ +const Logger = require('../Logger'); const JsSIP_C = require('../Constants'); -const debug = require('debug')('JsSIP:RTCSession:ReferNotifier'); + +const logger = new Logger('RTCSession:ReferNotifier'); const C = { event_type : 'refer', @@ -22,7 +24,7 @@ module.exports = class ReferNotifier notify(code, reason) { - debug('notify()'); + logger.debug('notify()'); if (this._active === false) { diff --git a/lib/RTCSession/ReferSubscriber.js b/lib/RTCSession/ReferSubscriber.js index 151f4a2..032c6a2 100644 --- a/lib/RTCSession/ReferSubscriber.js +++ b/lib/RTCSession/ReferSubscriber.js @@ -1,8 +1,10 @@ const EventEmitter = require('events').EventEmitter; +const Logger = require('../Logger'); const JsSIP_C = require('../Constants'); const Grammar = require('../Grammar'); const Utils = require('../Utils'); -const debug = require('debug')('JsSIP:RTCSession:ReferSubscriber'); + +const logger = new Logger('RTCSession:ReferSubscriber'); module.exports = class ReferSubscriber extends EventEmitter { @@ -21,7 +23,7 @@ module.exports = class ReferSubscriber extends EventEmitter sendRefer(target, options = {}) { - debug('sendRefer()'); + logger.debug('sendRefer()'); const extraHeaders = Utils.cloneArray(options.extraHeaders); const eventHandlers = Utils.cloneObject(options.eventHandlers); @@ -90,7 +92,7 @@ module.exports = class ReferSubscriber extends EventEmitter receiveNotify(request) { - debug('receiveNotify()'); + logger.debug('receiveNotify()'); if (!request.body) { @@ -101,7 +103,7 @@ module.exports = class ReferSubscriber extends EventEmitter if (status_line === -1) { - debug(`receiveNotify() | error parsing NOTIFY body: "${request.body}"`); + logger.debug(`receiveNotify() | error parsing NOTIFY body: "${request.body}"`); return; } @@ -140,9 +142,9 @@ module.exports = class ReferSubscriber extends EventEmitter _requestSucceeded(response) { - debug('REFER succeeded'); + logger.debug('REFER succeeded'); - debug('emit "requestSucceeded"'); + logger.debug('emit "requestSucceeded"'); this.emit('requestSucceeded', { response @@ -151,9 +153,9 @@ module.exports = class ReferSubscriber extends EventEmitter _requestFailed(response, cause) { - debug('REFER failed'); + logger.debug('REFER failed'); - debug('emit "requestFailed"'); + logger.debug('emit "requestFailed"'); this.emit('requestFailed', { response : response || null, diff --git a/lib/Registrator.js b/lib/Registrator.js index fa5d452..bdb97cf 100644 --- a/lib/Registrator.js +++ b/lib/Registrator.js @@ -1,8 +1,10 @@ +const Logger = require('./Logger'); const Utils = require('./Utils'); const JsSIP_C = require('./Constants'); const SIPMessage = require('./SIPMessage'); const RequestSender = require('./RequestSender'); -const debug = require('debug')('JsSIP:Registrator'); + +const logger = new Logger('Registrator'); const MIN_REGISTER_EXPIRES = 10; // In seconds. @@ -95,7 +97,7 @@ module.exports = class Registrator { if (this._registering) { - debug('Register request in progress...'); + logger.debug('Register request in progress...'); return; } @@ -156,7 +158,7 @@ ${this._contact};expires=${this._expires}${this._extraContactParams}`); if (!response.hasHeader('Contact')) { - debug('no Contact header in response to REGISTER, response ignored'); + logger.debug('no Contact header in response to REGISTER, response ignored'); break; } @@ -171,7 +173,7 @@ ${this._contact};expires=${this._expires}${this._extraContactParams}`); if (!contact) { - debug('no Contact header pointing to us, response ignored'); + logger.debug('no Contact header pointing to us, response ignored'); break; } @@ -250,7 +252,7 @@ ${this._contact};expires=${this._expires}${this._extraContactParams}`); } else { // This response MUST contain a Min-Expires header field. - debug('423 response received for REGISTER without Min-Expires'); + logger.debug('423 response received for REGISTER without Min-Expires'); this._registrationFailure(response, JsSIP_C.causes.SIP_FAILURE_CODE); } @@ -276,7 +278,7 @@ ${this._contact};expires=${this._expires}${this._extraContactParams}`); { if (!this._registered) { - debug('already unregistered'); + logger.debug('already unregistered'); return; } diff --git a/lib/RequestSender.js b/lib/RequestSender.js index d33f9f6..f4e55ba 100644 --- a/lib/RequestSender.js +++ b/lib/RequestSender.js @@ -1,7 +1,9 @@ +const Logger = require('./Logger'); const JsSIP_C = require('./Constants'); const DigestAuthentication = require('./DigestAuthentication'); const Transactions = require('./Transactions'); -const debug = require('debug')('JsSIP:RequestSender'); + +const logger = new Logger('RequestSender'); // Default event handlers. const EventHandlers = { @@ -110,7 +112,7 @@ module.exports = class RequestSender // Verify it seems a valid challenge. if (!challenge) { - debug(`${response.status_code} with wrong or missing challenge, cannot authenticate`); + logger.debug(`${response.status_code} with wrong or missing challenge, cannot authenticate`); this._eventHandlers.onReceiveResponse(response); return; diff --git a/lib/SIPMessage.js b/lib/SIPMessage.js index c69eca8..cdf0bfa 100644 --- a/lib/SIPMessage.js +++ b/lib/SIPMessage.js @@ -1,9 +1,11 @@ const sdp_transform = require('sdp-transform'); +const Logger = require('./Logger'); const JsSIP_C = require('./Constants'); const Utils = require('./Utils'); const NameAddrHeader = require('./NameAddrHeader'); const Grammar = require('./Grammar'); -const debug = require('debug')('JsSIP:SIPMessage'); + +const logger = new Logger('SIPMessage'); /** * -param {String} method request method @@ -461,13 +463,13 @@ class IncomingMessage if (!this.headers[name]) { - debug(`header "${name}" not present`); + logger.debug(`header "${name}" not present`); return; } else if (idx >= this.headers[name].length) { - debug(`not so many "${name}" headers present`); + logger.debug(`not so many "${name}" headers present`); return; } @@ -486,7 +488,7 @@ class IncomingMessage if (parsed === -1) { this.headers[name].splice(idx, 1); // delete from headers - debug(`error parsing "${name}" header field with value "${value}"`); + logger.debug(`error parsing "${name}" header field with value "${value}"`); return; } diff --git a/lib/Socket.js b/lib/Socket.js index 5a349de..ad8bc7d 100644 --- a/lib/Socket.js +++ b/lib/Socket.js @@ -1,8 +1,8 @@ +const Logger = require('./Logger'); const Utils = require('./Utils'); const Grammar = require('./Grammar'); -const debugerror = require('debug')('JsSIP:ERROR:Socket'); -debugerror.log = console.warn.bind(console); +const logger = new Logger('Socket'); /** * Interface documentation: https://jssip.net/documentation/$last_version/api/socket/ @@ -33,7 +33,7 @@ exports.isSocket = (socket) => if (typeof socket === 'undefined') { - debugerror('undefined JsSIP.Socket instance'); + logger.warn('undefined JsSIP.Socket instance'); return false; } @@ -43,19 +43,19 @@ exports.isSocket = (socket) => { if (!Utils.isString(socket.url)) { - debugerror('missing or invalid JsSIP.Socket url property'); + logger.warn('missing or invalid JsSIP.Socket url property'); throw new Error(); } if (!Utils.isString(socket.via_transport)) { - debugerror('missing or invalid JsSIP.Socket via_transport property'); + logger.warn('missing or invalid JsSIP.Socket via_transport property'); throw new Error(); } if (Grammar.parse(socket.sip_uri, 'SIP_URI') === -1) { - debugerror('missing or invalid JsSIP.Socket sip_uri property'); + logger.warn('missing or invalid JsSIP.Socket sip_uri property'); throw new Error(); } } @@ -71,7 +71,7 @@ exports.isSocket = (socket) => { if (!Utils.isFunction(socket[method])) { - debugerror(`missing or invalid JsSIP.Socket method: ${method}`); + logger.warn(`missing or invalid JsSIP.Socket method: ${method}`); throw new Error(); } }); diff --git a/lib/Transactions.js b/lib/Transactions.js index 7847697..1f9ded3 100644 --- a/lib/Transactions.js +++ b/lib/Transactions.js @@ -1,12 +1,14 @@ const EventEmitter = require('events').EventEmitter; +const Logger = require('./Logger'); const JsSIP_C = require('./Constants'); const SIPMessage = require('./SIPMessage'); const Timers = require('./Timers'); -const debugnict = require('debug')('JsSIP:NonInviteClientTransaction'); -const debugict = require('debug')('JsSIP:InviteClientTransaction'); -const debugact = require('debug')('JsSIP:AckClientTransaction'); -const debugnist = require('debug')('JsSIP:NonInviteServerTransaction'); -const debugist = require('debug')('JsSIP:InviteServerTransaction'); + +const loggernict = new Logger('NonInviteClientTransaction'); +const loggerict = new Logger('InviteClientTransaction'); +const loggeract = new Logger('AckClientTransaction'); +const loggernist = new Logger('NonInviteServerTransaction'); +const loggerist = new Logger('InviteServerTransaction'); const C = { // Transaction states. @@ -71,7 +73,7 @@ class NonInviteClientTransaction extends EventEmitter onTransportError() { - debugnict(`transport error occurred, deleting transaction ${this.id}`); + loggernict.debug(`transport error occurred, deleting transaction ${this.id}`); clearTimeout(this.F); clearTimeout(this.K); this.stateChanged(C.STATUS_TERMINATED); @@ -81,7 +83,7 @@ class NonInviteClientTransaction extends EventEmitter timer_F() { - debugnict(`Timer F expired for transaction ${this.id}`); + loggernict.debug(`Timer F expired for transaction ${this.id}`); this.stateChanged(C.STATUS_TERMINATED); this.ua.destroyTransaction(this); this.eventHandlers.onRequestTimeout(); @@ -191,7 +193,7 @@ class InviteClientTransaction extends EventEmitter if (this.state !== C.STATUS_ACCEPTED) { - debugict(`transport error occurred, deleting transaction ${this.id}`); + loggerict.debug(`transport error occurred, deleting transaction ${this.id}`); this.eventHandlers.onTransportError(); } @@ -202,7 +204,7 @@ class InviteClientTransaction extends EventEmitter // RFC 6026 7.2. timer_M() { - debugict(`Timer M expired for transaction ${this.id}`); + loggerict.debug(`Timer M expired for transaction ${this.id}`); if (this.state === C.STATUS_ACCEPTED) { @@ -215,7 +217,7 @@ class InviteClientTransaction extends EventEmitter // RFC 3261 17.1.1. timer_B() { - debugict(`Timer B expired for transaction ${this.id}`); + loggerict.debug(`Timer B expired for transaction ${this.id}`); if (this.state === C.STATUS_CALLING) { this.stateChanged(C.STATUS_TERMINATED); @@ -226,7 +228,7 @@ class InviteClientTransaction extends EventEmitter timer_D() { - debugict(`Timer D expired for transaction ${this.id}`); + loggerict.debug(`Timer D expired for transaction ${this.id}`); clearTimeout(this.B); this.stateChanged(C.STATUS_TERMINATED); this.ua.destroyTransaction(this); @@ -363,7 +365,7 @@ class AckClientTransaction extends EventEmitter onTransportError() { - debugact(`transport error occurred for transaction ${this.id}`); + loggeract.debug(`transport error occurred for transaction ${this.id}`); this.eventHandlers.onTransportError(); } } @@ -400,7 +402,7 @@ class NonInviteServerTransaction extends EventEmitter timer_J() { - debugnist(`Timer J expired for transaction ${this.id}`); + loggernist.debug(`Timer J expired for transaction ${this.id}`); this.stateChanged(C.STATUS_TERMINATED); this.ua.destroyTransaction(this); } @@ -411,7 +413,7 @@ class NonInviteServerTransaction extends EventEmitter { this.transportError = true; - debugnist(`transport error occurred, deleting transaction ${this.id}`); + loggernist.debug(`transport error occurred, deleting transaction ${this.id}`); clearTimeout(this.J); this.stateChanged(C.STATUS_TERMINATED); @@ -522,11 +524,11 @@ class InviteServerTransaction extends EventEmitter timer_H() { - debugist(`Timer H expired for transaction ${this.id}`); + loggerist.debug(`Timer H expired for transaction ${this.id}`); if (this.state === C.STATUS_COMPLETED) { - debugist('ACK not received, dialog will be terminated'); + loggerist.debug('ACK not received, dialog will be terminated'); } this.stateChanged(C.STATUS_TERMINATED); @@ -542,7 +544,7 @@ class InviteServerTransaction extends EventEmitter // RFC 6026 7.1. timer_L() { - debugist(`Timer L expired for transaction ${this.id}`); + loggerist.debug(`Timer L expired for transaction ${this.id}`); if (this.state === C.STATUS_ACCEPTED) { @@ -557,7 +559,7 @@ class InviteServerTransaction extends EventEmitter { this.transportError = true; - debugist(`transport error occurred, deleting transaction ${this.id}`); + loggerist.debug(`transport error occurred, deleting transaction ${this.id}`); if (this.resendProvisionalTimer !== null) { diff --git a/lib/Transport.js b/lib/Transport.js index 0e87a60..33018e7 100644 --- a/lib/Transport.js +++ b/lib/Transport.js @@ -1,9 +1,8 @@ +const Logger = require('./Logger'); const Socket = require('./Socket'); -const debug = require('debug')('JsSIP:Transport'); -const debugerror = require('debug')('JsSIP:ERROR:Transport'); const JsSIP_C = require('./Constants'); -debugerror.log = console.warn.bind(console); +const logger = new Logger('Transport'); /** * Constants @@ -37,7 +36,7 @@ module.exports = class Transport { constructor(sockets, recovery_options = C.recovery_options) { - debug('new()'); + logger.debug('new()'); this.status = C.STATUS_DISCONNECTED; @@ -61,7 +60,7 @@ module.exports = class Transport } catch (error) { - debugerror(`cannot use TextDecoder: ${error}`); + logger.warn(`cannot use TextDecoder: ${error}`); } if (typeof sockets === 'undefined') @@ -121,17 +120,17 @@ module.exports = class Transport connect() { - debug('connect()'); + logger.debug('connect()'); if (this.isConnected()) { - debug('Transport is already connected'); + logger.debug('Transport is already connected'); return; } else if (this.isConnecting()) { - debug('Transport is connecting'); + logger.debug('Transport is connecting'); return; } @@ -155,7 +154,7 @@ module.exports = class Transport disconnect() { - debug('close()'); + logger.debug('close()'); this.close_requested = true; this.recover_attempts = 0; @@ -182,18 +181,18 @@ module.exports = class Transport send(data) { - debug('send()'); + logger.debug('send()'); if (!this.isConnected()) { - debugerror('unable to send message, transport is not connected'); + logger.warn('unable to send message, transport is not connected'); return false; } const message = data.toString(); - debug(`sending message:\n\n${message}\n`); + logger.debug(`sending message:\n\n${message}\n`); return this.socket.send(message); } @@ -228,7 +227,7 @@ module.exports = class Transport k = this.recovery_options.max_interval; } - debug(`reconnection attempt: ${this.recover_attempts}. next connection attempt in ${k} seconds`); + logger.debug(`reconnection attempt: ${this.recover_attempts}. next connection attempt in ${k} seconds`); this.recovery_timer = setTimeout(() => { @@ -344,7 +343,7 @@ module.exports = class Transport // CRLF Keep Alive response from server. Ignore it. if (data === '\r\n') { - debug('received message with CRLF Keep Alive response'); + logger.debug('received message with CRLF Keep Alive response'); return; } @@ -361,19 +360,19 @@ module.exports = class Transport } catch (evt) { - debug('received binary message failed to be converted into string,' + + logger.debug('received binary message failed to be converted into string,' + ' message discarded'); return; } - debug(`received binary message:\n\n${data}\n`); + logger.debug(`received binary message:\n\n${data}\n`); } // Text message. else { - debug(`received text message:\n\n${data}\n`); + logger.debug(`received text message:\n\n${data}\n`); } this.ondata({ transport: this, message: data }); diff --git a/lib/UA.js b/lib/UA.js index 878eec6..0310acc 100644 --- a/lib/UA.js +++ b/lib/UA.js @@ -1,4 +1,5 @@ const EventEmitter = require('events').EventEmitter; +const Logger = require('./Logger'); const JsSIP_C = require('./Constants'); const Registrator = require('./Registrator'); const RTCSession = require('./RTCSession'); @@ -12,10 +13,8 @@ const Parser = require('./Parser'); const SIPMessage = require('./SIPMessage'); const sanityCheck = require('./sanityCheck'); const config = require('./Config'); -const debug = require('debug')('JsSIP:UA'); -const debugerror = require('debug')('JsSIP:ERROR:UA'); -debugerror.log = console.warn.bind(console); +const logger = new Logger('UA'); const C = { // UA status codes. @@ -46,7 +45,7 @@ module.exports = class UA extends EventEmitter constructor(configuration) { - debug('new() [configuration:%o]', configuration); + logger.debug('new() [configuration:%o]', configuration); super(); @@ -135,7 +134,7 @@ module.exports = class UA extends EventEmitter */ start() { - debug('start()'); + logger.debug('start()'); if (this._status === C.STATUS_INIT) { @@ -143,7 +142,7 @@ module.exports = class UA extends EventEmitter } else if (this._status === C.STATUS_USER_CLOSED) { - debug('restarting UA'); + logger.debug('restarting UA'); // Disconnect. if (this._closeTimer !== null) @@ -159,11 +158,11 @@ module.exports = class UA extends EventEmitter } else if (this._status === C.STATUS_READY) { - debug('UA is in READY status, not restarted'); + logger.debug('UA is in READY status, not restarted'); } else { - debug('ERROR: connection is down, Auto-Recovery system is trying to reconnect'); + logger.debug('ERROR: connection is down, Auto-Recovery system is trying to reconnect'); } // Set dynamic configuration. @@ -175,7 +174,7 @@ module.exports = class UA extends EventEmitter */ register() { - debug('register()'); + logger.debug('register()'); this._dynConfiguration.register = true; this._registrator.register(); @@ -186,7 +185,7 @@ module.exports = class UA extends EventEmitter */ unregister(options) { - debug('unregister()'); + logger.debug('unregister()'); this._dynConfiguration.register = false; this._registrator.unregister(options); @@ -227,7 +226,7 @@ module.exports = class UA extends EventEmitter */ call(target, options) { - debug('call()'); + logger.debug('call()'); const session = new RTCSession(this); @@ -248,7 +247,7 @@ module.exports = class UA extends EventEmitter */ sendMessage(target, body, options) { - debug('sendMessage()'); + logger.debug('sendMessage()'); const message = new Message(this); @@ -262,7 +261,7 @@ module.exports = class UA extends EventEmitter */ terminateSessions(options) { - debug('terminateSessions()'); + logger.debug('terminateSessions()'); for (const idx in this._sessions) { @@ -279,14 +278,14 @@ module.exports = class UA extends EventEmitter */ stop() { - debug('stop()'); + logger.debug('stop()'); // Remove dynamic settings. this._dynConfiguration = {}; if (this._status === C.STATUS_USER_CLOSED) { - debug('UA already closed'); + logger.debug('UA already closed'); return; } @@ -302,7 +301,7 @@ module.exports = class UA extends EventEmitter { if (Object.prototype.hasOwnProperty.call(this._sessions, session)) { - debug(`closing session ${session}`); + logger.debug(`closing session ${session}`); try { this._sessions[session].terminate(); } catch (error) {} } @@ -368,7 +367,7 @@ module.exports = class UA extends EventEmitter return this._configuration.authorization_jwt; default: - debugerror('get() | cannot get "%s" parameter in runtime', parameter); + logger.warn('get() | cannot get "%s" parameter in runtime', parameter); return undefined; } @@ -415,7 +414,7 @@ module.exports = class UA extends EventEmitter } default: - debugerror('set() | cannot set "%s" parameter in runtime', parameter); + logger.warn('set() | cannot set "%s" parameter in runtime', parameter); return false; } @@ -538,7 +537,7 @@ module.exports = class UA extends EventEmitter if (request.ruri.user !== this._configuration.uri.user && request.ruri.user !== this._contact.uri.user) { - debug('Request-URI does not point to us'); + logger.debug('Request-URI does not point to us'); if (request.method !== JsSIP_C.ACK) { request.reply_sl(404); @@ -649,7 +648,7 @@ module.exports = class UA extends EventEmitter } else { - debugerror('INVITE received but WebRTC is not supported'); + logger.warn('INVITE received but WebRTC is not supported'); request.reply(488); } break; @@ -665,7 +664,7 @@ module.exports = class UA extends EventEmitter } else { - debug('received CANCEL request for a non existent session'); + logger.debug('received CANCEL request for a non existent session'); } break; case JsSIP_C.ACK: @@ -705,7 +704,7 @@ module.exports = class UA extends EventEmitter } else { - debug('received NOTIFY request for a non existent subscription'); + logger.debug('received NOTIFY request for a non existent subscription'); request.reply(481, 'Subscription does not exist'); } } @@ -830,7 +829,7 @@ module.exports = class UA extends EventEmitter } catch (e) { - debugerror(e); + logger.warn(e); throw new Exceptions.ConfigurationError('sockets', this._configuration.sockets); } @@ -927,7 +926,7 @@ module.exports = class UA extends EventEmitter } } - debug('configuration parameters after validation:'); + logger.debug('configuration parameters after validation:'); for (const parameter in this._configuration) { // Only show the user user configurable parameters. @@ -937,15 +936,15 @@ module.exports = class UA extends EventEmitter { case 'uri': case 'registrar_server': - debug(`- ${parameter}: ${this._configuration[parameter]}`); + logger.debug(`- ${parameter}: ${this._configuration[parameter]}`); break; case 'password': case 'ha1': case 'authorization_jwt': - debug(`- ${parameter}: NOT SHOWN`); + logger.debug(`- ${parameter}: NOT SHOWN`); break; default: - debug(`- ${parameter}: ${JSON.stringify(this._configuration[parameter])}`); + logger.debug(`- ${parameter}: ${JSON.stringify(this._configuration[parameter])}`); } } } diff --git a/lib/WebSocketInterface.js b/lib/WebSocketInterface.js index 501c4a7..c212b9f 100644 --- a/lib/WebSocketInterface.js +++ b/lib/WebSocketInterface.js @@ -1,14 +1,13 @@ +const Logger = require('./Logger'); const Grammar = require('./Grammar'); -const debug = require('debug')('JsSIP:WebSocketInterface'); -const debugerror = require('debug')('JsSIP:ERROR:WebSocketInterface'); -debugerror.log = console.warn.bind(console); +const logger = new Logger('WebSocketInterface'); module.exports = class WebSocketInterface { constructor(url) { - debug('new() [url:"%s"]', url); + logger.debug('new() [url:"%s"]', url); this._url = url; this._sip_uri = null; @@ -19,12 +18,12 @@ module.exports = class WebSocketInterface if (parsed_url === -1) { - debugerror(`invalid WebSocket URI: ${url}`); + logger.warn(`invalid WebSocket URI: ${url}`); throw new TypeError(`Invalid argument: ${url}`); } else if (parsed_url.scheme !== 'wss' && parsed_url.scheme !== 'ws') { - debugerror(`invalid WebSocket URI scheme: ${parsed_url.scheme}`); + logger.warn(`invalid WebSocket URI scheme: ${parsed_url.scheme}`); throw new TypeError(`Invalid argument: ${url}`); } else @@ -56,17 +55,17 @@ module.exports = class WebSocketInterface connect() { - debug('connect()'); + logger.debug('connect()'); if (this.isConnected()) { - debug(`WebSocket ${this._url} is already connected`); + logger.debug(`WebSocket ${this._url} is already connected`); return; } else if (this.isConnecting()) { - debug(`WebSocket ${this._url} is connecting`); + logger.debug(`WebSocket ${this._url} is connecting`); return; } @@ -76,7 +75,7 @@ module.exports = class WebSocketInterface this.disconnect(); } - debug(`connecting to WebSocket ${this._url}`); + logger.debug(`connecting to WebSocket ${this._url}`); try { @@ -97,7 +96,7 @@ module.exports = class WebSocketInterface disconnect() { - debug('disconnect()'); + logger.debug('disconnect()'); if (this._ws) { @@ -114,7 +113,7 @@ module.exports = class WebSocketInterface send(message) { - debug('send()'); + logger.debug('send()'); if (this.isConnected()) { @@ -124,7 +123,7 @@ module.exports = class WebSocketInterface } else { - debugerror('unable to send message, WebSocket is not open'); + logger.warn('unable to send message, WebSocket is not open'); return false; } @@ -147,18 +146,18 @@ module.exports = class WebSocketInterface _onOpen() { - debug(`WebSocket ${this._url} connected`); + logger.debug(`WebSocket ${this._url} connected`); this.onconnect(); } _onClose({ wasClean, code, reason }) { - debug(`WebSocket ${this._url} closed`); + logger.debug(`WebSocket ${this._url} closed`); if (wasClean === false) { - debug('WebSocket abrupt disconnection'); + logger.debug('WebSocket abrupt disconnection'); } this.ondisconnect(!wasClean, code, reason); @@ -166,13 +165,13 @@ module.exports = class WebSocketInterface _onMessage({ data }) { - debug('received WebSocket message'); + logger.debug('received WebSocket message'); this.ondata(data); } _onError(e) { - debugerror(`WebSocket ${this._url} error: `, e); + logger.warn(`WebSocket ${this._url} error: `, e); } }; diff --git a/lib/sanityCheck.js b/lib/sanityCheck.js index 576d5bf..b843048 100644 --- a/lib/sanityCheck.js +++ b/lib/sanityCheck.js @@ -1,7 +1,9 @@ +const Logger = require('./Logger'); const JsSIP_C = require('./Constants'); const SIPMessage = require('./SIPMessage'); const Utils = require('./Utils'); -const debug = require('debug')('JsSIP:sanityCheck'); + +const logger = new Logger('sanityCheck'); // Checks for requests and responses. const all = [ minimumHeaders ]; @@ -202,7 +204,7 @@ function rfc3261_8_1_3_3() { if (message.getHeaders('via').length > 1) { - debug('more than one Via header field present in the response, dropping the response'); + logger.debug('more than one Via header field present in the response, dropping the response'); return false; } @@ -214,7 +216,7 @@ function rfc3261_18_3_response() if (len < contentLength) { - debug('message body length is lower than the value in Content-Length header field, dropping the response'); + logger.debug('message body length is lower than the value in Content-Length header field, dropping the response'); return false; } @@ -229,7 +231,7 @@ function minimumHeaders() { if (!message.hasHeader(header)) { - debug(`missing mandatory header field : ${header}, dropping the response`); + logger.debug(`missing mandatory header field : ${header}, dropping the response`); return false; }