@messagebird/client
Advanced tools
Comparing version 1.0.0-next-rc.3 to 1.0.0-next-rc.4
@@ -0,1 +1,9 @@ | ||
# [1.0.0-next-rc.3](https://git.messagebird.io/frontend/javascript-webrtc-sdk/compare/v1.0.0-next-rc.2...v1.0.0-next-rc.3) (2020-04-24) | ||
### Bug Fixes | ||
* remove console.log ([6cb3e4d](https://git.messagebird.io/frontend/javascript-webrtc-sdk/commit/6cb3e4db2c4f006fafaa1c4ad04563f8e55af5b6)) | ||
* rename callError to SessionError ([e887cc0](https://git.messagebird.io/frontend/javascript-webrtc-sdk/commit/e887cc0b90e7fcec24e3e8af1a2ae2cdfbfacefa)) | ||
# [1.0.0-next-rc.2](https://git.messagebird.io/frontend/javascript-webrtc-sdk/compare/v1.0.0-next-rc.1...v1.0.0-next-rc.2) (2020-04-24) | ||
@@ -2,0 +10,0 @@ |
@@ -12,2 +12,4 @@ 'use strict'; | ||
var events = require('events'); | ||
var _regeneratorRuntime = _interopDefault(require('@babel/runtime/regenerator')); | ||
var _asyncToGenerator = _interopDefault(require('@babel/runtime/helpers/asyncToGenerator')); | ||
var _typeof = _interopDefault(require('@babel/runtime/helpers/typeof')); | ||
@@ -21,4 +23,2 @@ var platform = _interopDefault(require('platform')); | ||
var _slicedToArray = _interopDefault(require('@babel/runtime/helpers/slicedToArray')); | ||
var _regeneratorRuntime = _interopDefault(require('@babel/runtime/regenerator')); | ||
var _asyncToGenerator = _interopDefault(require('@babel/runtime/helpers/asyncToGenerator')); | ||
@@ -83,3 +83,3 @@ function assertsIsRegisteredMessage(body) { | ||
function getSDKVersionHeader() { | ||
var version = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "e887cc0b" ; | ||
var version = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "1078f707" ; | ||
return "SDK-Version: ".concat(version); | ||
@@ -234,8 +234,15 @@ } | ||
_defineProperty(this, "reconnectionAttempts", 0); | ||
_defineProperty(this, "removeEventListener", this.eventEmitter.removeListener); | ||
_defineProperty(this, "handleDisconnected", function (data) { | ||
// JsSIP will always emit the disconnected event after the WS connection is closed | ||
// When registration fails, the WS client will be disconnected, but only after capturing the registration error | ||
// The registration error contains import information for the user and therefore we don't overwrite it | ||
if (_this.error) return; | ||
_this.setStatus(exports.ClientStatus.Error); | ||
_this.setError(new InternalError("User Agent Disconnected: ".concat(data.error))); | ||
_this.setError(new InternalError("User Agent Disconnected")); | ||
}); | ||
@@ -251,8 +258,42 @@ | ||
_defineProperty(this, "retryWithNewToken", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() { | ||
var nextToken; | ||
return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_this.reconnectionAttempts += 1; | ||
_this.setStatus(exports.ClientStatus.Connecting); | ||
_this.stop(); | ||
_context.next = 5; | ||
return _this.tokenRefresh(); | ||
case 5: | ||
nextToken = _context.sent; | ||
_this.updateToken(nextToken); | ||
_this.sipUA.start(); | ||
case 8: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
}))); | ||
_defineProperty(this, "handleRegistrationFailed", function (data) { | ||
var _data$response; | ||
// Registration failed events without a response are fired when the UserAgent disconnects. | ||
// The "Disconnected" event handler takes care of setting the correct error state for this already. | ||
if (!(data === null || data === void 0 ? void 0 : data.response)) { | ||
return; | ||
} | ||
var error; | ||
switch (data === null || data === void 0 ? void 0 : (_data$response = data.response) === null || _data$response === void 0 ? void 0 : _data$response.status_code) { | ||
switch (data.response.status_code) { | ||
case exports.ErrorCodes.NotAcceptable: | ||
@@ -263,2 +304,10 @@ error = new NotAcceptableError(data.response.reason_phrase); | ||
case exports.ErrorCodes.Forbidden: | ||
if (_this.reconnectionAttempts === 0) { | ||
_this.retryWithNewToken()["catch"](function (error) { | ||
_this.setError(new InternalError("Connection Retry Failed: ".concat(error.message))); | ||
}); | ||
return; | ||
} | ||
error = new ForbiddenError(data.response.reason_phrase); | ||
@@ -270,4 +319,9 @@ break; | ||
break; | ||
} | ||
} // When a registration fails, we want to stop JSSIP from attempting to reconnect | ||
// Indefinitely. In the future we might want to include our own retry behavior for | ||
// Failed registrations based on the error. | ||
_this.stop(); | ||
_this.setError(error); | ||
@@ -295,2 +349,4 @@ }); | ||
_this._error = null; | ||
_this.setStatus(exports.ClientStatus.Connected); | ||
@@ -326,2 +382,3 @@ }); | ||
value: function startConnection(jwt) { | ||
this.reconnectionAttempts = 0; | ||
this.setStatus(exports.ClientStatus.Connecting); | ||
@@ -377,5 +434,5 @@ this.updateToken(jwt); | ||
var _ref2 = turn || {}, | ||
servers = _ref2.servers, | ||
credentials = _ref2.credentials; | ||
var _ref3 = turn || {}, | ||
servers = _ref3.servers, | ||
credentials = _ref3.credentials; | ||
@@ -382,0 +439,0 @@ if (!servers || !servers.length || !credentials) return []; |
@@ -19,3 +19,3 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
export function getSDKVersionHeader() { | ||
var version = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "e887cc0b" || 'HEAD'; | ||
var version = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "1078f707" || 'HEAD'; | ||
return "SDK-Version: ".concat(version); | ||
@@ -22,0 +22,0 @@ } |
@@ -0,1 +1,3 @@ | ||
import _regeneratorRuntime from "@babel/runtime/regenerator"; | ||
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; | ||
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
@@ -38,8 +40,15 @@ import _createClass from "@babel/runtime/helpers/createClass"; | ||
_defineProperty(this, "reconnectionAttempts", 0); | ||
_defineProperty(this, "removeEventListener", this.eventEmitter.removeListener); | ||
_defineProperty(this, "handleDisconnected", function (data) { | ||
// JsSIP will always emit the disconnected event after the WS connection is closed | ||
// When registration fails, the WS client will be disconnected, but only after capturing the registration error | ||
// The registration error contains import information for the user and therefore we don't overwrite it | ||
if (_this.error) return; | ||
_this.setStatus(ClientStatus.Error); | ||
_this.setError(new InternalError("User Agent Disconnected: ".concat(data.error))); | ||
_this.setError(new InternalError("User Agent Disconnected")); | ||
}); | ||
@@ -55,8 +64,42 @@ | ||
_defineProperty(this, "retryWithNewToken", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() { | ||
var nextToken; | ||
return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_this.reconnectionAttempts += 1; | ||
_this.setStatus(ClientStatus.Connecting); | ||
_this.stop(); | ||
_context.next = 5; | ||
return _this.tokenRefresh(); | ||
case 5: | ||
nextToken = _context.sent; | ||
_this.updateToken(nextToken); | ||
_this.sipUA.start(); | ||
case 8: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
}))); | ||
_defineProperty(this, "handleRegistrationFailed", function (data) { | ||
var _data$response; | ||
// Registration failed events without a response are fired when the UserAgent disconnects. | ||
// The "Disconnected" event handler takes care of setting the correct error state for this already. | ||
if (!(data === null || data === void 0 ? void 0 : data.response)) { | ||
return; | ||
} | ||
var error; | ||
switch (data === null || data === void 0 ? void 0 : (_data$response = data.response) === null || _data$response === void 0 ? void 0 : _data$response.status_code) { | ||
switch (data.response.status_code) { | ||
case ErrorCodes.NotAcceptable: | ||
@@ -67,2 +110,10 @@ error = new NotAcceptableError(data.response.reason_phrase); | ||
case ErrorCodes.Forbidden: | ||
if (_this.reconnectionAttempts === 0) { | ||
_this.retryWithNewToken()["catch"](function (error) { | ||
_this.setError(new InternalError("Connection Retry Failed: ".concat(error.message))); | ||
}); | ||
return; | ||
} | ||
error = new ForbiddenError(data.response.reason_phrase); | ||
@@ -74,4 +125,9 @@ break; | ||
break; | ||
} | ||
} // When a registration fails, we want to stop JSSIP from attempting to reconnect | ||
// Indefinitely. In the future we might want to include our own retry behavior for | ||
// Failed registrations based on the error. | ||
_this.stop(); | ||
_this.setError(error); | ||
@@ -99,2 +155,4 @@ }); | ||
_this._error = null; | ||
_this.setStatus(ClientStatus.Connected); | ||
@@ -130,2 +188,3 @@ }); | ||
value: function startConnection(jwt) { | ||
this.reconnectionAttempts = 0; | ||
this.setStatus(ClientStatus.Connecting); | ||
@@ -181,5 +240,5 @@ this.updateToken(jwt); | ||
var _ref2 = turn || {}, | ||
servers = _ref2.servers, | ||
credentials = _ref2.credentials; | ||
var _ref3 = turn || {}, | ||
servers = _ref3.servers, | ||
credentials = _ref3.credentials; | ||
@@ -186,0 +245,0 @@ if (!servers || !servers.length || !credentials) return []; |
@@ -21,2 +21,3 @@ /// <reference types="node" /> | ||
private tokenRefresh; | ||
private reconnectionAttempts; | ||
constructor({ host, refreshToken }: UserAgentOptions); | ||
@@ -32,2 +33,3 @@ on(name: 'status', calback: (status: ClientStatus) => void): void; | ||
private handleRegistrationExpiring; | ||
private retryWithNewToken; | ||
private handleRegistrationFailed; | ||
@@ -34,0 +36,0 @@ private setError; |
@@ -6,2 +6,4 @@ import { UA, WebSocketInterface, debug } from 'jssip'; | ||
import { EventEmitter } from 'events'; | ||
import _regeneratorRuntime from '@babel/runtime/regenerator'; | ||
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator'; | ||
import _typeof from '@babel/runtime/helpers/typeof'; | ||
@@ -15,4 +17,2 @@ import platform from 'platform'; | ||
import _slicedToArray from '@babel/runtime/helpers/slicedToArray'; | ||
import _regeneratorRuntime from '@babel/runtime/regenerator'; | ||
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator'; | ||
@@ -47,3 +47,3 @@ function assertsIsRegisteredMessage(body) { | ||
function getSDKVersionHeader() { | ||
var version = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "e887cc0b" ; | ||
var version = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "1078f707" ; | ||
return "SDK-Version: ".concat(version); | ||
@@ -206,8 +206,15 @@ } | ||
_defineProperty(this, "reconnectionAttempts", 0); | ||
_defineProperty(this, "removeEventListener", this.eventEmitter.removeListener); | ||
_defineProperty(this, "handleDisconnected", function (data) { | ||
// JsSIP will always emit the disconnected event after the WS connection is closed | ||
// When registration fails, the WS client will be disconnected, but only after capturing the registration error | ||
// The registration error contains import information for the user and therefore we don't overwrite it | ||
if (_this.error) return; | ||
_this.setStatus(ClientStatus.Error); | ||
_this.setError(new InternalError("User Agent Disconnected: ".concat(data.error))); | ||
_this.setError(new InternalError("User Agent Disconnected")); | ||
}); | ||
@@ -223,8 +230,42 @@ | ||
_defineProperty(this, "retryWithNewToken", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() { | ||
var nextToken; | ||
return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_this.reconnectionAttempts += 1; | ||
_this.setStatus(ClientStatus.Connecting); | ||
_this.stop(); | ||
_context.next = 5; | ||
return _this.tokenRefresh(); | ||
case 5: | ||
nextToken = _context.sent; | ||
_this.updateToken(nextToken); | ||
_this.sipUA.start(); | ||
case 8: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
}))); | ||
_defineProperty(this, "handleRegistrationFailed", function (data) { | ||
var _data$response; | ||
// Registration failed events without a response are fired when the UserAgent disconnects. | ||
// The "Disconnected" event handler takes care of setting the correct error state for this already. | ||
if (!(data === null || data === void 0 ? void 0 : data.response)) { | ||
return; | ||
} | ||
var error; | ||
switch (data === null || data === void 0 ? void 0 : (_data$response = data.response) === null || _data$response === void 0 ? void 0 : _data$response.status_code) { | ||
switch (data.response.status_code) { | ||
case ErrorCodes.NotAcceptable: | ||
@@ -235,2 +276,10 @@ error = new NotAcceptableError(data.response.reason_phrase); | ||
case ErrorCodes.Forbidden: | ||
if (_this.reconnectionAttempts === 0) { | ||
_this.retryWithNewToken()["catch"](function (error) { | ||
_this.setError(new InternalError("Connection Retry Failed: ".concat(error.message))); | ||
}); | ||
return; | ||
} | ||
error = new ForbiddenError(data.response.reason_phrase); | ||
@@ -242,4 +291,9 @@ break; | ||
break; | ||
} | ||
} // When a registration fails, we want to stop JSSIP from attempting to reconnect | ||
// Indefinitely. In the future we might want to include our own retry behavior for | ||
// Failed registrations based on the error. | ||
_this.stop(); | ||
_this.setError(error); | ||
@@ -267,2 +321,4 @@ }); | ||
_this._error = null; | ||
_this.setStatus(ClientStatus.Connected); | ||
@@ -298,2 +354,3 @@ }); | ||
value: function startConnection(jwt) { | ||
this.reconnectionAttempts = 0; | ||
this.setStatus(ClientStatus.Connecting); | ||
@@ -349,5 +406,5 @@ this.updateToken(jwt); | ||
var _ref2 = turn || {}, | ||
servers = _ref2.servers, | ||
credentials = _ref2.credentials; | ||
var _ref3 = turn || {}, | ||
servers = _ref3.servers, | ||
credentials = _ref3.credentials; | ||
@@ -354,0 +411,0 @@ if (!servers || !servers.length || !credentials) return []; |
{ | ||
"name": "@messagebird/client", | ||
"version": "1.0.0-next-rc.3", | ||
"version": "1.0.0-next-rc.4", | ||
"license": "UNLICENSED", | ||
@@ -5,0 +5,0 @@ "files": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
432923
4716