Socket
Socket
Sign inDemoInstall

@webex/internal-plugin-mercury

Package Overview
Dependencies
Maintainers
0
Versions
1201
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@webex/internal-plugin-mercury - npm Package Compare versions

Comparing version 3.3.0 to 3.3.1-next.1

176

dist/mercury.js

@@ -65,2 +65,16 @@ "use strict";

},
initialize: function initialize() {
var _this = this;
/*
When one of these legacy feature gets updated, this event would be triggered
* group-message-notifications
* mention-notifications
* thread-notifications
*/
this.on('event:featureToggle_update', function (envelope) {
if (envelope && envelope.data) {
_this.webex.internal.feature.updateFeature(envelope.data.featureToggle);
}
});
},
/**

@@ -74,3 +88,3 @@ * Get the last error.

connect: function connect(webSocketUrl) {
var _this = this;
var _this2 = this;
if (this.connected) {

@@ -82,17 +96,17 @@ this.logger.info("".concat(this.namespace, ": already connected, will not connect again"));

return _promise.default.resolve(this.webex.internal.device.registered || this.webex.internal.device.register()).then(function () {
_this.logger.info("".concat(_this.namespace, ": connecting"));
return _this._connectWithBackoff(webSocketUrl);
_this2.logger.info("".concat(_this2.namespace, ": connecting"));
return _this2._connectWithBackoff(webSocketUrl);
});
},
disconnect: function disconnect() {
var _this2 = this;
var _this3 = this;
return new _promise.default(function (resolve) {
if (_this2.backoffCall) {
_this2.logger.info("".concat(_this2.namespace, ": aborting connection"));
_this2.backoffCall.abort();
if (_this3.backoffCall) {
_this3.logger.info("".concat(_this3.namespace, ": aborting connection"));
_this3.backoffCall.abort();
}
if (_this2.socket) {
_this2.socket.removeAllListeners('message');
_this2.once('offline', resolve);
resolve(_this2.socket.close());
if (_this3.socket) {
_this3.socket.removeAllListeners('message');
_this3.once('offline', resolve);
resolve(_this3.socket.close());
}

@@ -123,3 +137,3 @@ resolve();

_prepareUrl: function _prepareUrl(webSocketUrl) {
var _this3 = this;
var _this4 = this;
if (!webSocketUrl) {

@@ -130,3 +144,3 @@ webSocketUrl = this.webex.internal.device.webSocketUrl;

if (haMessagingEnabled) {
return _this3.webex.internal.services.convertUrlToPriorityHostUrl(webSocketUrl);
return _this4.webex.internal.services.convertUrlToPriorityHostUrl(webSocketUrl);
}

@@ -137,3 +151,3 @@ return webSocketUrl;

}).then(function () {
return _this3.webex.internal.feature.getFeature('developer', 'web-shared-mercury');
return _this4.webex.internal.feature.getFeature('developer', 'web-shared-mercury');
}).then(function (webSharedMercury) {

@@ -153,3 +167,3 @@ webSocketUrl = _url.default.parse(webSocketUrl, true);

}
if ((0, _lodash.get)(_this3, 'webex.config.device.ephemeral', false)) {
if ((0, _lodash.get)(_this4, 'webex.config.device.ephemeral', false)) {
webSocketUrl.query.multipleConnections = true;

@@ -161,10 +175,10 @@ }

_attemptConnection: function _attemptConnection(socketUrl, callback) {
var _this4 = this;
var _this5 = this;
var socket = new _socket.default();
var attemptWSUrl;
socket.on('close', function () {
return _this4._onclose.apply(_this4, arguments);
return _this5._onclose.apply(_this5, arguments);
});
socket.on('message', function () {
return _this4._onmessage.apply(_this4, arguments);
return _this5._onmessage.apply(_this5, arguments);
});

@@ -175,3 +189,3 @@ socket.on('sequence-mismatch', function () {

}
return _this4._emit.apply(_this4, ['sequence-mismatch'].concat(args));
return _this5._emit.apply(_this5, ['sequence-mismatch'].concat(args));
});

@@ -182,3 +196,3 @@ socket.on('ping-pong-latency', function () {

}
return _this4._emit.apply(_this4, ['ping-pong-latency'].concat(args));
return _this5._emit.apply(_this5, ['ping-pong-latency'].concat(args));
});

@@ -189,5 +203,5 @@ _promise.default.all([this._prepareUrl(socketUrl), this.webex.credentials.getUserToken()]).then(function (_ref) {

token = _ref2[1];
if (!_this4.backoffCall) {
var msg = "".concat(_this4.namespace, ": prevent socket open when backoffCall no longer defined");
_this4.logger.info(msg);
if (!_this5.backoffCall) {
var msg = "".concat(_this5.namespace, ": prevent socket open when backoffCall no longer defined");
_this5.logger.info(msg);
return _promise.default.reject(new Error(msg));

@@ -197,14 +211,14 @@ }

var options = {
forceCloseDelay: _this4.config.forceCloseDelay,
pingInterval: _this4.config.pingInterval,
pongTimeout: _this4.config.pongTimeout,
forceCloseDelay: _this5.config.forceCloseDelay,
pingInterval: _this5.config.pingInterval,
pongTimeout: _this5.config.pongTimeout,
token: token.toString(),
trackingId: "".concat(_this4.webex.sessionId, "_").concat((0, _now.default)()),
logger: _this4.logger
trackingId: "".concat(_this5.webex.sessionId, "_").concat((0, _now.default)()),
logger: _this5.logger
};
// if the consumer has supplied request options use them
if (_this4.webex.config.defaultMercuryOptions) {
_this4.logger.info("".concat(_this4.namespace, ": setting custom options"));
options = _objectSpread(_objectSpread({}, options), _this4.webex.config.defaultMercuryOptions);
if (_this5.webex.config.defaultMercuryOptions) {
_this5.logger.info("".concat(_this5.namespace, ": setting custom options"));
options = _objectSpread(_objectSpread({}, options), _this5.webex.config.defaultMercuryOptions);
}

@@ -214,11 +228,11 @@

// the socket if it is in the process of being opened.
_this4.socket = socket;
_this4.logger.info("".concat(_this4.namespace, " connection url: ").concat(webSocketUrl));
_this5.socket = socket;
_this5.logger.info("".concat(_this5.namespace, " connection url: ").concat(webSocketUrl));
return socket.open(webSocketUrl, options);
}).then(function () {
_this4.logger.info("".concat(_this4.namespace, ": connected to mercury, success, action: connected, url: ").concat(attemptWSUrl));
_this5.logger.info("".concat(_this5.namespace, ": connected to mercury, success, action: connected, url: ").concat(attemptWSUrl));
callback();
return _this4.webex.internal.feature.getFeature('developer', 'web-high-availability').then(function (haMessagingEnabled) {
return _this5.webex.internal.feature.getFeature('developer', 'web-high-availability').then(function (haMessagingEnabled) {
if (haMessagingEnabled) {
return _this4.webex.internal.device.refresh();
return _this5.webex.internal.device.refresh();
}

@@ -228,3 +242,3 @@ return _promise.default.resolve();

}).catch(function (reason) {
_this4.lastError = reason; // remember the last error
_this5.lastError = reason; // remember the last error

@@ -235,13 +249,13 @@ // Suppress connection errors that appear to be network related. This

// metrics can't be trusted).
if (reason.code !== 1006 && _this4.backoffCall && _this4.backoffCall.getNumRetries() > 0) {
_this4._emit('connection_failed', reason, {
retries: _this4.backoffCall.getNumRetries()
if (reason.code !== 1006 && _this5.backoffCall && _this5.backoffCall.getNumRetries() > 0) {
_this5._emit('connection_failed', reason, {
retries: _this5.backoffCall.getNumRetries()
});
}
_this4.logger.info("".concat(_this4.namespace, ": connection attempt failed"), reason);
_this5.logger.info("".concat(_this5.namespace, ": connection attempt failed"), reason);
// UnknownResponse is produced by IE for any 4XXX; treated it like a bad
// web socket url and let WDM handle the token checking
if (reason instanceof _errors.UnknownResponse) {
_this4.logger.info("".concat(_this4.namespace, ": received unknown response code, refreshing device registration"));
return _this4.webex.internal.device.refresh().then(function () {
_this5.logger.info("".concat(_this5.namespace, ": received unknown response code, refreshing device registration"));
return _this5.webex.internal.device.refresh().then(function () {
return callback(reason);

@@ -252,4 +266,4 @@ });

if (reason instanceof _errors.NotAuthorized) {
_this4.logger.info("".concat(_this4.namespace, ": received authorization error, reauthorizing"));
return _this4.webex.credentials.refresh({
_this5.logger.info("".concat(_this5.namespace, ": received authorization error, reauthorizing"));
return _this5.webex.credentials.refresh({
force: true

@@ -269,11 +283,11 @@ }).then(function () {

if (reason instanceof _errors.BadRequest || reason instanceof _errors.Forbidden) {
_this4.logger.warn("".concat(_this4.namespace, ": received unrecoverable response from mercury"));
_this4.backoffCall.abort();
_this5.logger.warn("".concat(_this5.namespace, ": received unrecoverable response from mercury"));
_this5.backoffCall.abort();
return callback(reason);
}
if (reason instanceof _errors.ConnectionError) {
return _this4.webex.internal.feature.getFeature('developer', 'web-high-availability').then(function (haMessagingEnabled) {
return _this5.webex.internal.feature.getFeature('developer', 'web-high-availability').then(function (haMessagingEnabled) {
if (haMessagingEnabled) {
_this4.logger.info("".concat(_this4.namespace, ": received a generic connection error, will try to connect to another datacenter. failed, action: 'failed', url: ").concat(attemptWSUrl, " error: ").concat(reason.message));
return _this4.webex.internal.services.markFailedUrl(attemptWSUrl);
_this5.logger.info("".concat(_this5.namespace, ": received a generic connection error, will try to connect to another datacenter. failed, action: 'failed', url: ").concat(attemptWSUrl, " error: ").concat(reason.message));
return _this5.webex.internal.services.markFailedUrl(attemptWSUrl);
}

@@ -287,3 +301,3 @@ return null;

}).catch(function (reason) {
_this4.logger.error("".concat(_this4.namespace, ": failed to handle connection failure"), reason);
_this5.logger.error("".concat(_this5.namespace, ": failed to handle connection failure"), reason);
callback(reason);

@@ -293,3 +307,3 @@ });

_connectWithBackoff: function _connectWithBackoff(webSocketUrl) {
var _this5 = this;
var _this6 = this;
return new _promise.default(function (resolve, reject) {

@@ -300,11 +314,11 @@ // eslint gets confused about whether or not call is actually used

var onComplete = function onComplete(err) {
_this5.connecting = false;
_this5.backoffCall = undefined;
_this6.connecting = false;
_this6.backoffCall = undefined;
if (err) {
_this5.logger.info("".concat(_this5.namespace, ": failed to connect after ").concat(call.getNumRetries(), " retries; log statement about next retry was inaccurate; ").concat(err));
_this6.logger.info("".concat(_this6.namespace, ": failed to connect after ").concat(call.getNumRetries(), " retries; log statement about next retry was inaccurate; ").concat(err));
return reject(err);
}
_this5.connected = true;
_this5.hasEverConnected = true;
_this5._emit('online');
_this6.connected = true;
_this6.hasEverConnected = true;
_this6._emit('online');
return resolve();

@@ -315,16 +329,16 @@ };

call = _backoff.default.call(function (callback) {
_this5.logger.info("".concat(_this5.namespace, ": executing connection attempt ").concat(call.getNumRetries()));
_this5._attemptConnection(webSocketUrl, callback);
_this6.logger.info("".concat(_this6.namespace, ": executing connection attempt ").concat(call.getNumRetries()));
_this6._attemptConnection(webSocketUrl, callback);
}, onComplete);
call.setStrategy(new _backoff.default.ExponentialStrategy({
initialDelay: _this5.config.backoffTimeReset,
maxDelay: _this5.config.backoffTimeMax
initialDelay: _this6.config.backoffTimeReset,
maxDelay: _this6.config.backoffTimeMax
}));
if (_this5.config.initialConnectionMaxRetries && !_this5.hasEverConnected) {
call.failAfter(_this5.config.initialConnectionMaxRetries);
} else if (_this5.config.maxRetries) {
call.failAfter(_this5.config.maxRetries);
if (_this6.config.initialConnectionMaxRetries && !_this6.hasEverConnected) {
call.failAfter(_this6.config.initialConnectionMaxRetries);
} else if (_this6.config.maxRetries) {
call.failAfter(_this6.config.maxRetries);
}
call.on('abort', function () {
_this5.logger.info("".concat(_this5.namespace, ": connection aborted"));
_this6.logger.info("".concat(_this6.namespace, ": connection aborted"));
reject(new Error('Mercury Connection Aborted'));

@@ -335,14 +349,14 @@ });

var number = call.getNumRetries();
var delay = Math.min(call.strategy_.nextBackoffDelay_, _this5.config.backoffTimeMax);
_this5.logger.info("".concat(_this5.namespace, ": failed to connect; attempting retry ").concat(number + 1, " in ").concat(delay, " ms"));
var delay = Math.min(call.strategy_.nextBackoffDelay_, _this6.config.backoffTimeMax);
_this6.logger.info("".concat(_this6.namespace, ": failed to connect; attempting retry ").concat(number + 1, " in ").concat(delay, " ms"));
/* istanbul ignore if */
if (process.env.NODE_ENV === 'development') {
_this5.logger.debug("".concat(_this5.namespace, ": "), err, err.stack);
_this6.logger.debug("".concat(_this6.namespace, ": "), err, err.stack);
}
return;
}
_this5.logger.info("".concat(_this5.namespace, ": connected"));
_this6.logger.info("".concat(_this6.namespace, ": connected"));
});
call.start();
_this5.backoffCall = call;
_this6.backoffCall = call;
});

@@ -435,3 +449,3 @@ },

_onmessage: function _onmessage(event) {
var _this6 = this;
var _this7 = this;
var envelope = event.data;

@@ -448,9 +462,9 @@ if (process.env.ENABLE_MERCURY_LOGGING) {

return new _promise.default(function (resolve) {
return resolve((_this6.webex[namespace] || _this6.webex.internal[namespace])[name](data));
return resolve((_this7.webex[namespace] || _this7.webex.internal[namespace])[name](data));
}).catch(function (reason) {
return _this6.logger.error("".concat(_this6.namespace, ": error occurred in autowired event handler for ").concat(data.eventType), reason);
return _this7.logger.error("".concat(_this7.namespace, ": error occurred in autowired event handler for ").concat(data.eventType), reason);
});
});
}, _promise.default.resolve()).then(function () {
_this6._emit('event', event.data);
_this7._emit('event', event.data);
var _data$eventType$split = data.eventType.split('.'),

@@ -460,9 +474,9 @@ _data$eventType$split2 = (0, _slicedToArray2.default)(_data$eventType$split, 1),

if (namespace === data.eventType) {
_this6._emit("event:".concat(namespace), envelope);
_this7._emit("event:".concat(namespace), envelope);
} else {
_this6._emit("event:".concat(namespace), envelope);
_this6._emit("event:".concat(data.eventType), envelope);
_this7._emit("event:".concat(namespace), envelope);
_this7._emit("event:".concat(data.eventType), envelope);
}
}).catch(function (reason) {
_this6.logger.error("".concat(_this6.namespace, ": error occurred processing socket message"), reason);
_this7.logger.error("".concat(_this7.namespace, ": error occurred processing socket message"), reason);
});

@@ -474,5 +488,5 @@ },

},
version: "3.3.0"
version: "3.3.1-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.3.0",
"@webex/test-helper-mocha": "3.3.0",
"@webex/test-helper-mock-webex": "3.3.0",
"@webex/test-helper-test-users": "3.3.0",
"@webex/test-helper-chai": "3.1.0-next.3",
"@webex/test-helper-mocha": "3.1.0-next.3",
"@webex/test-helper-mock-webex": "3.1.0-next.3",
"@webex/test-helper-test-users": "3.1.0-next.3",
"eslint": "^8.24.0",

@@ -42,14 +42,14 @@ "prettier": "^2.7.1",

"dependencies": {
"@webex/common": "3.3.0",
"@webex/common-timers": "3.3.0",
"@webex/internal-plugin-device": "3.3.0",
"@webex/internal-plugin-feature": "3.3.0",
"@webex/internal-plugin-metrics": "3.3.0",
"@webex/test-helper-chai": "3.3.0",
"@webex/test-helper-mocha": "3.3.0",
"@webex/test-helper-mock-web-socket": "3.3.0",
"@webex/test-helper-mock-webex": "3.3.0",
"@webex/test-helper-refresh-callback": "3.3.0",
"@webex/test-helper-test-users": "3.3.0",
"@webex/webex-core": "3.3.0",
"@webex/common": "3.1.0-next.3",
"@webex/common-timers": "3.1.0-next.3",
"@webex/internal-plugin-device": "3.1.0-next.3",
"@webex/internal-plugin-feature": "3.3.1-next.1",
"@webex/internal-plugin-metrics": "3.1.0-next.3",
"@webex/test-helper-chai": "3.1.0-next.3",
"@webex/test-helper-mocha": "3.1.0-next.3",
"@webex/test-helper-mock-web-socket": "3.1.0-next.3",
"@webex/test-helper-mock-webex": "3.1.0-next.3",
"@webex/test-helper-refresh-callback": "3.1.0-next.3",
"@webex/test-helper-test-users": "3.1.0-next.3",
"@webex/webex-core": "3.1.0-next.3",
"backoff": "^2.5.0",

@@ -69,3 +69,3 @@ "lodash": "^4.17.21",

},
"version": "3.3.0"
"version": "3.3.1-next.1"
}

@@ -55,2 +55,16 @@ /* eslint-disable require-jsdoc */

initialize() {
/*
When one of these legacy feature gets updated, this event would be triggered
* group-message-notifications
* mention-notifications
* thread-notifications
*/
this.on('event:featureToggle_update', (envelope) => {
if (envelope && envelope.data) {
this.webex.internal.feature.updateFeature(envelope.data.featureToggle);
}
});
},
/**

@@ -57,0 +71,0 @@ * Get the last error.

@@ -141,3 +141,11 @@ /*!

it('connects to Mercury using default url', () => {
webex.internal.feature.updateFeature = sinon.stub();
const promise = mercury.connect();
const envelope = {
data: {
featureToggle: {
'feature-name': true
}
}
};

@@ -152,5 +160,20 @@ assert.isFalse(mercury.connected, 'Mercury is not connected');

assert.calledWith(socketOpenStub, sinon.match(/ws:\/\/example.com/), sinon.match.any);
mercury._emit('event:featureToggle_update', envelope);
assert.calledOnceWithExactly(webex.internal.feature.updateFeature, envelope.data.featureToggle);
sinon.restore();
});
});
it('connects to Mercury but does not call updateFeature', () => {
webex.internal.feature.updateFeature = sinon.stub();
const promise = mercury.connect();
const envelope = {};
return promise.then(() => {
mercury._emit('event:featureToggle_update', envelope);
assert.notCalled(webex.internal.feature.updateFeature);
sinon.restore();
});
});
describe('when `maxRetries` is set', () => {

@@ -157,0 +180,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc