@webex/internal-plugin-mercury
Advanced tools
Comparing version 3.0.0 to 3.1.0-next.1
@@ -31,2 +31,3 @@ "use strict"; | ||
var _dec, _dec2, _obj; | ||
/* eslint-disable require-jsdoc */ | ||
/*! | ||
@@ -40,2 +41,3 @@ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file. | ||
namespace: 'Mercury', | ||
lastError: undefined, | ||
session: { | ||
@@ -50,2 +52,6 @@ connected: { | ||
}, | ||
hasEverConnected: { | ||
default: false, | ||
type: 'boolean' | ||
}, | ||
socket: 'object', | ||
@@ -62,2 +68,9 @@ localClusterServiceUrls: 'object' | ||
}, | ||
/** | ||
* Get the last error. | ||
* @returns {any} The last error. | ||
*/ | ||
getLastError: function getLastError() { | ||
return this.lastError; | ||
}, | ||
connect: function connect(webSocketUrl) { | ||
@@ -206,2 +219,4 @@ var _this = this; | ||
}).catch(function (reason) { | ||
_this4.lastError = reason; // remember the last error | ||
// Suppress connection errors that appear to be network related. This | ||
@@ -278,2 +293,3 @@ // may end up suppressing metrics during outages, but we might not care | ||
_this5.connected = true; | ||
_this5.hasEverConnected = true; | ||
_this5._emit('online'); | ||
@@ -292,3 +308,5 @@ return resolve(); | ||
})); | ||
if (_this5.config.maxRetries) { | ||
if (_this5.config.initialConnectionMaxRetries && !_this5.hasEverConnected) { | ||
call.failAfter(_this5.config.initialConnectionMaxRetries); | ||
} else if (_this5.config.maxRetries) { | ||
call.failAfter(_this5.config.maxRetries); | ||
@@ -438,5 +456,5 @@ } | ||
}, | ||
version: "3.0.0" | ||
version: "3.1.0-next.1" | ||
}, ((0, _applyDecoratedDescriptor2.default)(_obj, "connect", [_common.oneFlight], (0, _getOwnPropertyDescriptor.default)(_obj, "connect"), _obj), (0, _applyDecoratedDescriptor2.default)(_obj, "disconnect", [_common.oneFlight], (0, _getOwnPropertyDescriptor.default)(_obj, "disconnect"), _obj), (0, _applyDecoratedDescriptor2.default)(_obj, "listen", [_dec], (0, _getOwnPropertyDescriptor.default)(_obj, "listen"), _obj), (0, _applyDecoratedDescriptor2.default)(_obj, "stopListening", [_dec2], (0, _getOwnPropertyDescriptor.default)(_obj, "stopListening"), _obj)), _obj))); | ||
var _default = exports.default = Mercury; | ||
//# sourceMappingURL=mercury.js.map |
@@ -32,6 +32,6 @@ { | ||
"@webex/legacy-tools": "0.0.0", | ||
"@webex/test-helper-chai": "3.0.0", | ||
"@webex/test-helper-mocha": "3.0.0", | ||
"@webex/test-helper-mock-webex": "3.0.0", | ||
"@webex/test-helper-test-users": "3.0.0", | ||
"@webex/test-helper-chai": "3.1.0-next.1", | ||
"@webex/test-helper-mocha": "3.1.0-next.1", | ||
"@webex/test-helper-mock-webex": "3.1.0-next.1", | ||
"@webex/test-helper-test-users": "3.1.0-next.1", | ||
"eslint": "^8.24.0", | ||
@@ -42,14 +42,14 @@ "prettier": "^2.7.1", | ||
"dependencies": { | ||
"@webex/common": "3.0.0", | ||
"@webex/common-timers": "3.0.0", | ||
"@webex/internal-plugin-device": "3.0.0", | ||
"@webex/internal-plugin-feature": "3.0.0", | ||
"@webex/internal-plugin-metrics": "3.0.0", | ||
"@webex/test-helper-chai": "3.0.0", | ||
"@webex/test-helper-mocha": "3.0.0", | ||
"@webex/test-helper-mock-web-socket": "3.0.0", | ||
"@webex/test-helper-mock-webex": "3.0.0", | ||
"@webex/test-helper-refresh-callback": "3.0.0", | ||
"@webex/test-helper-test-users": "3.0.0", | ||
"@webex/webex-core": "3.0.0", | ||
"@webex/common": "3.1.0-next.1", | ||
"@webex/common-timers": "3.1.0-next.1", | ||
"@webex/internal-plugin-device": "3.1.0-next.1", | ||
"@webex/internal-plugin-feature": "3.1.0-next.1", | ||
"@webex/internal-plugin-metrics": "3.1.0-next.1", | ||
"@webex/test-helper-chai": "3.1.0-next.1", | ||
"@webex/test-helper-mocha": "3.1.0-next.1", | ||
"@webex/test-helper-mock-web-socket": "3.1.0-next.1", | ||
"@webex/test-helper-mock-webex": "3.1.0-next.1", | ||
"@webex/test-helper-refresh-callback": "3.1.0-next.1", | ||
"@webex/test-helper-test-users": "3.1.0-next.1", | ||
"@webex/webex-core": "3.1.0-next.1", | ||
"backoff": "^2.5.0", | ||
@@ -67,5 +67,5 @@ "lodash": "^4.17.21", | ||
"test:style": "eslint ./src/**/*.*", | ||
"test:unit": "webex-legacy-tools test --unit --runner jest" | ||
"test:unit": "webex-legacy-tools test --unit --runner mocha" | ||
}, | ||
"version": "3.0.0" | ||
"version": "3.1.0-next.1" | ||
} |
@@ -32,4 +32,6 @@ # @webex/internal-plugin-mercury | ||
## Using A Proxy Agent To Open A Websocket Connection | ||
## Config Options | ||
### Using A Proxy Agent To Open A Websocket Connection | ||
For consumers who are not using the SDK via the browser it may be necessary to configure a proxy agent in order to connect with Mercury and open a Websocket in a proxy environment. | ||
@@ -55,2 +57,13 @@ | ||
### Retries | ||
The default behaviour is for Mercury to continue to try to connect with an exponential back-off. This behavior can be adjusted with the following config params: | ||
- `maxRetries` - the number of times it will retry before error. Default: 0 | ||
- `initialConnectionMaxRetries` - the number of times it will retry before error on the first connection. Once a connection has been established, any further connection attempts will use `maxRetries`. Default: 0 | ||
- `backoffTimeMax` - The maximum time between connection attempts in ms. Default: 32000 | ||
- `backoffTimeReset` - The time before the first retry in ms. Default: 1000 | ||
## Maintainers | ||
@@ -57,0 +70,0 @@ |
@@ -0,1 +1,2 @@ | ||
/* eslint-disable require-jsdoc */ | ||
/*! | ||
@@ -26,2 +27,3 @@ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file. | ||
namespace: 'Mercury', | ||
lastError: undefined, | ||
@@ -37,2 +39,6 @@ session: { | ||
}, | ||
hasEverConnected: { | ||
default: false, | ||
type: 'boolean', | ||
}, | ||
socket: 'object', | ||
@@ -51,2 +57,10 @@ localClusterServiceUrls: 'object', | ||
/** | ||
* Get the last error. | ||
* @returns {any} The last error. | ||
*/ | ||
getLastError() { | ||
return this.lastError; | ||
}, | ||
@oneFlight | ||
@@ -219,2 +233,4 @@ connect(webSocketUrl) { | ||
.catch((reason) => { | ||
this.lastError = reason; // remember the last error | ||
// Suppress connection errors that appear to be network related. This | ||
@@ -301,2 +317,3 @@ // may end up suppressing metrics during outages, but we might not care | ||
this.connected = true; | ||
this.hasEverConnected = true; | ||
this._emit('online'); | ||
@@ -320,3 +337,5 @@ | ||
if (this.config.maxRetries) { | ||
if (this.config.initialConnectionMaxRetries && !this.hasEverConnected) { | ||
call.failAfter(this.config.initialConnectionMaxRetries); | ||
} else if (this.config.maxRetries) { | ||
call.failAfter(this.config.maxRetries); | ||
@@ -323,0 +342,0 @@ } |
@@ -145,3 +145,3 @@ /*! | ||
describe.skip('when `mercury.buffer_state` is received', () => { | ||
describe('when `mercury.buffer_state` is received', () => { | ||
// This test is here because the buffer states message may arrive before | ||
@@ -148,0 +148,0 @@ // the mercury Promise resolves. |
@@ -155,5 +155,4 @@ /*! | ||
describe('when `maxRetries` is set', () => { | ||
// skipping due to apparent bug with lolex in all browsers but Chrome. | ||
skipInBrowser(it)('fails after `maxRetries` attempts', () => { | ||
mercury.config.maxRetries = 2; | ||
const check = () => { | ||
socketOpenStub.restore(); | ||
@@ -186,3 +185,2 @@ socketOpenStub = sinon.stub(Socket.prototype, 'open'); | ||
clock.tick(5 * mercury.config.backoffTimeReset); | ||
return assert.isRejected(promise); | ||
@@ -193,3 +191,34 @@ }) | ||
}); | ||
} | ||
// skipping due to apparent bug with lolex in all browsers but Chrome. | ||
// if initial retries is zero and mercury has never connected max retries is used | ||
skipInBrowser(it)('fails after `maxRetries` attempts', () => { | ||
mercury.config.maxRetries = 2; | ||
mercury.config.initialConnectionMaxRetries = 0; | ||
return check(); | ||
}); | ||
// initial retries is non-zero so takes precedence over maxRetries when mercury has never connected | ||
skipInBrowser(it)('fails after `initialConnectionMaxRetries` attempts', () => { | ||
mercury.config.maxRetries = 0; | ||
mercury.config.initialConnectionMaxRetries = 2; | ||
return check(); | ||
}); | ||
// initial retries is non-zero so takes precedence over maxRetries when mercury has never connected | ||
skipInBrowser(it)('fails after `initialConnectionMaxRetries` attempts', () => { | ||
mercury.config.initialConnectionMaxRetries = 2; | ||
mercury.config.maxRetries = 5; | ||
return check(); | ||
}); | ||
// when mercury has connected maxRetries is used and the initialConnectionMaxRetries is ignored | ||
skipInBrowser(it)('fails after `initialConnectionMaxRetries` attempts', () => { | ||
mercury.config.initialConnectionMaxRetries = 5; | ||
mercury.config.maxRetries = 2; | ||
mercury.hasEverConnected = true; | ||
return check(); | ||
}); | ||
}); | ||
@@ -387,3 +416,3 @@ | ||
describe.skip('when webSocketUrl is provided', () => { | ||
describe('when webSocketUrl is provided', () => { | ||
it('connects to Mercury with provided url', () => { | ||
@@ -410,3 +439,3 @@ const webSocketUrl = 'ws://providedurl.com'; | ||
describe.skip('Websocket proxy agent', () => { | ||
describe('Websocket proxy agent', () => { | ||
afterEach(() => { | ||
@@ -459,3 +488,3 @@ delete webex.config.defaultMercuryOptions; | ||
describe.skip('#disconnect()', () => { | ||
describe('#disconnect()', () => { | ||
it('disconnects the WebSocket', () => | ||
@@ -550,3 +579,6 @@ mercury | ||
return assert.isRejected(promise); | ||
return assert.isRejected(promise).then((error) => { | ||
// connection did not fail, so no last error | ||
assert.isUndefined(mercury.getLastError()); | ||
}); | ||
}); | ||
@@ -574,2 +606,26 @@ }); | ||
}); | ||
it('sets lastError when retrying', () => { | ||
const realError = new Error('FORCED'); | ||
socketOpenStub.restore(); | ||
socketOpenStub = sinon.stub(Socket.prototype, 'open'); | ||
socketOpenStub.onCall(0).returns(Promise.reject(realError)); | ||
const promise = mercury.connect(); | ||
// Wait for the connect call to setup | ||
return promiseTick(webex.internal.mercury.config.backoffTimeReset).then(() => { | ||
// Calling disconnect will abort the backoffCall, close the socket, and | ||
// reject the connect | ||
mercury.disconnect(); | ||
return assert.isRejected(promise).then((error) => { | ||
const lastError = mercury.getLastError(); | ||
assert.equal(error.message, "Mercury Connection Aborted"); | ||
assert.isDefined(lastError); | ||
assert.equal(lastError, realError); | ||
}); | ||
}); | ||
}); | ||
}); | ||
@@ -727,98 +783,16 @@ }); | ||
}); | ||
}); | ||
describe('ping pong latency event is forwarded', () => { | ||
let clock, mercury, mockWebSocket, socketOpenStub, webex; | ||
const statusStartTypingMessage = JSON.stringify({ | ||
id: uuid.v4(), | ||
data: { | ||
eventType: 'status.start_typing', | ||
actor: { | ||
id: 'actorId', | ||
}, | ||
conversationId: uuid.v4(), | ||
}, | ||
timestamp: Date.now(), | ||
trackingId: `suffix_${uuid.v4()}_${Date.now()}`, | ||
}); | ||
describe('ping pong latency event is forwarded', () => { | ||
it('should forward ping pong latency event', () => { | ||
const spy = sinon.spy(); | ||
beforeEach(() => { | ||
clock = FakeTimers.install({now: Date.now()}); | ||
}); | ||
mercury.on('ping-pong-latency', spy); | ||
afterEach(() => { | ||
clock.uninstall(); | ||
}); | ||
beforeEach(() => { | ||
webex = new MockWebex({ | ||
children: { | ||
mercury: Mercury, | ||
}, | ||
return mercury.connect().then(() => { | ||
assert.calledWith(spy, 0); | ||
assert.calledOnce(spy); | ||
}); | ||
}); | ||
webex.credentials = { | ||
refresh: sinon.stub().returns(Promise.resolve()), | ||
getUserToken: sinon.stub().returns( | ||
Promise.resolve({ | ||
toString() { | ||
return 'Bearer FAKE'; | ||
}, | ||
}) | ||
), | ||
}; | ||
webex.internal.device = { | ||
register: sinon.stub().returns(Promise.resolve()), | ||
refresh: sinon.stub().returns(Promise.resolve()), | ||
webSocketUrl: 'ws://example.com', | ||
getWebSocketUrl: sinon.stub().returns(Promise.resolve('ws://example-2.com')), | ||
useServiceCatalogUrl: sinon | ||
.stub() | ||
.returns(Promise.resolve('https://service-catalog-url.com')), | ||
}; | ||
webex.internal.services = { | ||
convertUrlToPriorityHostUrl: sinon.stub().returns(Promise.resolve('ws://example-2.com')), | ||
markFailedUrl: sinon.stub().returns(Promise.resolve()), | ||
}; | ||
webex.internal.metrics.submitClientMetrics = sinon.stub(); | ||
webex.trackingId = 'fakeTrackingId'; | ||
webex.config.mercury = mercuryConfig.mercury; | ||
webex.logger = console; | ||
mockWebSocket = new MockWebSocket(); | ||
sinon.stub(Socket, 'getWebSocketConstructor').returns(() => mockWebSocket); | ||
const origOpen = Socket.prototype.open; | ||
socketOpenStub = sinon.stub(Socket.prototype, 'open').callsFake(function (...args) { | ||
const promise = Reflect.apply(origOpen, this, args); | ||
process.nextTick(() => mockWebSocket.open()); | ||
return promise; | ||
}); | ||
mercury = webex.internal.mercury; | ||
}); | ||
afterEach(() => { | ||
if (socketOpenStub) { | ||
socketOpenStub.restore(); | ||
} | ||
if (Socket.getWebSocketConstructor.restore) { | ||
Socket.getWebSocketConstructor.restore(); | ||
} | ||
}); | ||
it('should forward ping pong latency event', () => { | ||
const spy = sinon.spy(); | ||
mercury.on('ping-pong-latency', spy); | ||
return mercury.connect().then(() => { | ||
assert.calledWith(spy, 0); | ||
assert.calledOnce(spy); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -43,4 +43,6 @@ /*! | ||
beforeEach(() => { | ||
sinon.stub(Socket, 'getWebSocketConstructor').callsFake(() => function (...args) { | ||
mockWebSocket = new MockWebSocket(...args); | ||
sinon.stub(Socket, 'getWebSocketConstructor').callsFake( | ||
() => | ||
function (...args) { | ||
mockWebSocket = new MockWebSocket(...args); | ||
@@ -73,3 +75,3 @@ return mockWebSocket; | ||
describe.skip('#open()', () => { | ||
describe('#open()', () => { | ||
let socket; | ||
@@ -218,3 +220,3 @@ | ||
describe.skip('#open()', () => { | ||
describe('#open()', () => { | ||
it('requires a url parameter', () => { | ||
@@ -572,3 +574,3 @@ const s = new Socket(); | ||
describe.skip('#onclose()', () => { | ||
describe('#onclose()', () => { | ||
it('stops further ping checks', () => { | ||
@@ -757,3 +759,3 @@ socket._ping.resetHistory(); | ||
describe.skip('#_ping()', () => { | ||
describe('#_ping()', () => { | ||
let id; | ||
@@ -760,0 +762,0 @@ |
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
242532
4213
78
10
2
+ Added@webex/common@3.1.0-next.1(transitive)
+ Added@webex/common-timers@3.1.0-next.1(transitive)
+ Added@webex/http-core@3.1.0-next.1(transitive)
+ Added@webex/internal-plugin-device@3.1.0-next.1(transitive)
+ Added@webex/internal-plugin-feature@3.1.0-next.1(transitive)
+ Added@webex/internal-plugin-metrics@3.1.0-next.1(transitive)
+ Added@webex/plugin-logger@3.1.0-next.1(transitive)
+ Added@webex/storage-adapter-spec@3.1.0-next.1(transitive)
+ Added@webex/test-helper-chai@3.1.0-next.1(transitive)
+ Added@webex/test-helper-file@3.1.0-next.1(transitive)
+ Added@webex/test-helper-make-local-url@3.1.0-next.1(transitive)
+ Added@webex/test-helper-mocha@3.1.0-next.1(transitive)
+ Added@webex/test-helper-mock-web-socket@3.1.0-next.1(transitive)
+ Added@webex/test-helper-mock-webex@3.1.0-next.1(transitive)
+ Added@webex/test-helper-refresh-callback@3.1.0-next.1(transitive)
+ Added@webex/test-helper-retry@3.1.0-next.1(transitive)
+ Added@webex/test-helper-test-users@3.1.0-next.1(transitive)
+ Added@webex/test-users@3.1.0-next.1(transitive)
+ Added@webex/webex-core@3.1.0-next.1(transitive)
- Removed@webex/common@3.0.0(transitive)
- Removed@webex/common-timers@3.0.0(transitive)
- Removed@webex/http-core@3.0.0(transitive)
- Removed@webex/internal-plugin-device@3.0.0(transitive)
- Removed@webex/internal-plugin-feature@3.0.0(transitive)
- Removed@webex/internal-plugin-metrics@3.0.0(transitive)
- Removed@webex/plugin-logger@3.0.0(transitive)
- Removed@webex/storage-adapter-spec@3.0.0(transitive)
- Removed@webex/test-helper-chai@3.0.0(transitive)
- Removed@webex/test-helper-file@3.0.0(transitive)
- Removed@webex/test-helper-make-local-url@3.0.0(transitive)
- Removed@webex/test-helper-mocha@3.0.0(transitive)
- Removed@webex/test-helper-mock-web-socket@3.0.0(transitive)
- Removed@webex/test-helper-mock-webex@3.0.0(transitive)
- Removed@webex/test-helper-refresh-callback@3.0.0(transitive)
- Removed@webex/test-helper-retry@3.0.0(transitive)
- Removed@webex/test-helper-test-users@3.0.0(transitive)
- Removed@webex/test-users@3.0.0(transitive)
- Removed@webex/webex-core@3.0.0(transitive)
Updated@webex/common@3.1.0-next.1