@webex/internal-plugin-mercury 3.0.0-bnr.5 → 3.0.0-next.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +6 -0
- package/README.md +14 -1
- package/babel.config.js +3 -0
- package/dist/config.js +1 -2
- package/dist/config.js.map +1 -1
- package/dist/errors.js +8 -11
- package/dist/errors.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/mercury.js +75 -63
- package/dist/mercury.js.map +1 -1
- package/dist/socket/index.js.map +1 -1
- package/dist/socket/socket-base.js +57 -42
- package/dist/socket/socket-base.js.map +1 -1
- package/dist/socket/socket.js +1 -2
- package/dist/socket/socket.js.map +1 -1
- package/dist/socket/socket.shim.js +1 -2
- package/dist/socket/socket.shim.js.map +1 -1
- package/jest.config.js +3 -0
- package/package.json +35 -16
- package/process +1 -0
- package/src/mercury.js +63 -52
- package/src/socket/socket-base.js +61 -28
- package/test/integration/spec/webex.js +3 -2
- package/test/unit/spec/mercury.js +87 -9
- package/test/unit/spec/socket.js +18 -1
- package/dist/types/config.d.ts +0 -10
- package/dist/types/errors.d.ts +0 -31
- package/dist/types/index.d.ts +0 -4
- package/dist/types/mercury.d.ts +0 -2
- package/dist/types/socket/index.d.ts +0 -1
- package/dist/types/socket/socket-base.d.ts +0 -120
- package/dist/types/socket/socket.d.ts +0 -2
- package/dist/types/socket/socket.shim.d.ts +0 -2
- package/test/unit/spec/_setup.js +0 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Socket","getWebSocketConstructor","WS"],"sources":["socket.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport WS from 'ws';\n\nimport Socket from './socket-base';\n\nSocket.getWebSocketConstructor = function getWebSocketConstructor() {\n return WS;\n};\n\nexport default Socket;\n"],"mappings":";;;;;;;;AAIA;AAEA;AANA;AACA;AACA;;
|
|
1
|
+
{"version":3,"names":["_ws","_interopRequireDefault","require","_socketBase","Socket","getWebSocketConstructor","WS","_default","exports","default"],"sources":["socket.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport WS from 'ws';\n\nimport Socket from './socket-base';\n\nSocket.getWebSocketConstructor = function getWebSocketConstructor() {\n return WS;\n};\n\nexport default Socket;\n"],"mappings":";;;;;;;;AAIA,IAAAA,GAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,WAAA,GAAAF,sBAAA,CAAAC,OAAA;AANA;AACA;AACA;;AAMAE,mBAAM,CAACC,uBAAuB,GAAG,SAASA,uBAAuBA,CAAA,EAAG;EAClE,OAAOC,WAAE;AACX,CAAC;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEaL,mBAAM"}
|
|
@@ -32,6 +32,5 @@ _socketBase.default.getWebSocketConstructor = function getWebSocketConstructor()
|
|
|
32
32
|
}
|
|
33
33
|
return ws;
|
|
34
34
|
};
|
|
35
|
-
var _default = _socketBase.default;
|
|
36
|
-
exports.default = _default;
|
|
35
|
+
var _default = exports.default = _socketBase.default;
|
|
37
36
|
//# sourceMappingURL=socket.shim.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Socket","getWebSocketConstructor","ws","WebSocket","MozWebSocket","global","window","self"],"sources":["socket.shim.js"],"sourcesContent":["/* eslint-disable no-restricted-globals */\n\n/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\n/* eslint-env browser */\n\nimport Socket from './socket-base';\n\nSocket.getWebSocketConstructor = function getWebSocketConstructor() {\n // Grabed from https://github.com/heineiuo/isomorphic-ws/blob/9b977394ac875638c045fd9cf774ed418484b394/browser.js\n let ws;\n\n if (typeof WebSocket !== 'undefined') {\n ws = WebSocket;\n } else if (typeof MozWebSocket !== 'undefined') {\n // eslint-disable-next-line no-undef\n ws = MozWebSocket;\n } else if (typeof global !== 'undefined') {\n ws = global.WebSocket || global.MozWebSocket;\n } else if (typeof window !== 'undefined') {\n ws = window.WebSocket || window.MozWebSocket;\n } else if (typeof self !== 'undefined') {\n ws = self.WebSocket || self.MozWebSocket;\n }\n\n return ws;\n};\n\nexport default Socket;\n"],"mappings":";;;;;;;;AAQA;AARA;;AAEA;AACA;AACA;;AAEA;;
|
|
1
|
+
{"version":3,"names":["_socketBase","_interopRequireDefault","require","Socket","getWebSocketConstructor","ws","WebSocket","MozWebSocket","global","window","self","_default","exports","default"],"sources":["socket.shim.js"],"sourcesContent":["/* eslint-disable no-restricted-globals */\n\n/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\n/* eslint-env browser */\n\nimport Socket from './socket-base';\n\nSocket.getWebSocketConstructor = function getWebSocketConstructor() {\n // Grabed from https://github.com/heineiuo/isomorphic-ws/blob/9b977394ac875638c045fd9cf774ed418484b394/browser.js\n let ws;\n\n if (typeof WebSocket !== 'undefined') {\n ws = WebSocket;\n } else if (typeof MozWebSocket !== 'undefined') {\n // eslint-disable-next-line no-undef\n ws = MozWebSocket;\n } else if (typeof global !== 'undefined') {\n ws = global.WebSocket || global.MozWebSocket;\n } else if (typeof window !== 'undefined') {\n ws = window.WebSocket || window.MozWebSocket;\n } else if (typeof self !== 'undefined') {\n ws = self.WebSocket || self.MozWebSocket;\n }\n\n return ws;\n};\n\nexport default Socket;\n"],"mappings":";;;;;;;;AAQA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AARA;;AAEA;AACA;AACA;;AAEA;;AAIAC,mBAAM,CAACC,uBAAuB,GAAG,SAASA,uBAAuBA,CAAA,EAAG;EAClE;EACA,IAAIC,EAAE;EAEN,IAAI,OAAOC,SAAS,KAAK,WAAW,EAAE;IACpCD,EAAE,GAAGC,SAAS;EAChB,CAAC,MAAM,IAAI,OAAOC,YAAY,KAAK,WAAW,EAAE;IAC9C;IACAF,EAAE,GAAGE,YAAY;EACnB,CAAC,MAAM,IAAI,OAAOC,MAAM,KAAK,WAAW,EAAE;IACxCH,EAAE,GAAGG,MAAM,CAACF,SAAS,IAAIE,MAAM,CAACD,YAAY;EAC9C,CAAC,MAAM,IAAI,OAAOE,MAAM,KAAK,WAAW,EAAE;IACxCJ,EAAE,GAAGI,MAAM,CAACH,SAAS,IAAIG,MAAM,CAACF,YAAY;EAC9C,CAAC,MAAM,IAAI,OAAOG,IAAI,KAAK,WAAW,EAAE;IACtCL,EAAE,GAAGK,IAAI,CAACJ,SAAS,IAAII,IAAI,CAACH,YAAY;EAC1C;EAEA,OAAOF,EAAE;AACX,CAAC;AAAC,IAAAM,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEaV,mBAAM"}
|
package/jest.config.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webex/internal-plugin-mercury",
|
|
3
|
-
"version": "3.0.0-bnr.5",
|
|
4
3
|
"description": "",
|
|
5
4
|
"license": "MIT",
|
|
6
5
|
"main": "dist/index.js",
|
|
@@ -24,26 +23,46 @@
|
|
|
24
23
|
]
|
|
25
24
|
},
|
|
26
25
|
"devDependencies": {
|
|
26
|
+
"@babel/core": "^7.17.10",
|
|
27
27
|
"@sinonjs/fake-timers": "^6.0.1",
|
|
28
|
+
"@webex/babel-config-legacy": "0.0.0",
|
|
29
|
+
"@webex/eslint-config-legacy": "0.0.0",
|
|
30
|
+
"@webex/jest-config-legacy": "0.0.0",
|
|
31
|
+
"@webex/legacy-tools": "0.0.0",
|
|
32
|
+
"@webex/test-helper-chai": "3.0.0-next.8",
|
|
33
|
+
"@webex/test-helper-mocha": "3.0.0-next.8",
|
|
34
|
+
"@webex/test-helper-mock-webex": "3.0.0-next.8",
|
|
35
|
+
"@webex/test-helper-test-users": "3.0.0-next.8",
|
|
36
|
+
"eslint": "^8.24.0",
|
|
37
|
+
"prettier": "^2.7.1",
|
|
28
38
|
"sinon": "^9.2.4"
|
|
29
39
|
},
|
|
30
40
|
"dependencies": {
|
|
31
|
-
"@webex/common": "3.0.0-
|
|
32
|
-
"@webex/common-timers": "3.0.0-
|
|
33
|
-
"@webex/internal-plugin-device": "3.0.0-
|
|
34
|
-
"@webex/internal-plugin-feature": "3.0.0-
|
|
35
|
-
"@webex/internal-plugin-
|
|
36
|
-
"@webex/
|
|
37
|
-
"@webex/test-helper-
|
|
38
|
-
"@webex/test-helper-
|
|
39
|
-
"@webex/test-helper-mock-
|
|
40
|
-
"@webex/test-helper-
|
|
41
|
-
"@webex/test-helper-
|
|
42
|
-
"@webex/
|
|
43
|
-
"@webex/webex-core": "3.0.0-bnr.5",
|
|
41
|
+
"@webex/common": "3.0.0-next.8",
|
|
42
|
+
"@webex/common-timers": "3.0.0-next.8",
|
|
43
|
+
"@webex/internal-plugin-device": "3.0.0-next.8",
|
|
44
|
+
"@webex/internal-plugin-feature": "3.0.0-next.10",
|
|
45
|
+
"@webex/internal-plugin-metrics": "3.0.0-next.8",
|
|
46
|
+
"@webex/test-helper-chai": "3.0.0-next.8",
|
|
47
|
+
"@webex/test-helper-mocha": "3.0.0-next.8",
|
|
48
|
+
"@webex/test-helper-mock-web-socket": "3.0.0-next.8",
|
|
49
|
+
"@webex/test-helper-mock-webex": "3.0.0-next.8",
|
|
50
|
+
"@webex/test-helper-refresh-callback": "3.0.0-next.8",
|
|
51
|
+
"@webex/test-helper-test-users": "3.0.0-next.8",
|
|
52
|
+
"@webex/webex-core": "3.0.0-next.8",
|
|
44
53
|
"backoff": "^2.5.0",
|
|
45
54
|
"lodash": "^4.17.21",
|
|
46
55
|
"uuid": "^3.3.2",
|
|
47
56
|
"ws": "^8.2.2"
|
|
48
|
-
}
|
|
49
|
-
|
|
57
|
+
},
|
|
58
|
+
"scripts": {
|
|
59
|
+
"build": "yarn build:src",
|
|
60
|
+
"build:src": "webex-legacy-tools build -dest \"./dist\" -src \"./src\" -js -ts -maps",
|
|
61
|
+
"deploy:npm": "yarn npm publish",
|
|
62
|
+
"test": "yarn test:style && yarn test:unit && yarn test:integration && yarn test:browser",
|
|
63
|
+
"test:browser": "webex-legacy-tools test --integration --unit --runner karma",
|
|
64
|
+
"test:style": "eslint ./src/**/*.*",
|
|
65
|
+
"test:unit": "webex-legacy-tools test --unit --runner mocha"
|
|
66
|
+
},
|
|
67
|
+
"version": "3.0.0-next.10"
|
|
68
|
+
}
|
package/process
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = {browser: true};
|
package/src/mercury.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable require-jsdoc */
|
|
1
2
|
/*!
|
|
2
3
|
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
3
4
|
*/
|
|
@@ -23,6 +24,7 @@ const normalReconnectReasons = ['idle', 'done (forced)', 'pong not received', 'p
|
|
|
23
24
|
|
|
24
25
|
const Mercury = WebexPlugin.extend({
|
|
25
26
|
namespace: 'Mercury',
|
|
27
|
+
lastError: undefined,
|
|
26
28
|
|
|
27
29
|
session: {
|
|
28
30
|
connected: {
|
|
@@ -33,6 +35,10 @@ const Mercury = WebexPlugin.extend({
|
|
|
33
35
|
default: false,
|
|
34
36
|
type: 'boolean',
|
|
35
37
|
},
|
|
38
|
+
hasEverConnected: {
|
|
39
|
+
default: false,
|
|
40
|
+
type: 'boolean',
|
|
41
|
+
},
|
|
36
42
|
socket: 'object',
|
|
37
43
|
localClusterServiceUrls: 'object',
|
|
38
44
|
},
|
|
@@ -46,10 +52,18 @@ const Mercury = WebexPlugin.extend({
|
|
|
46
52
|
},
|
|
47
53
|
},
|
|
48
54
|
|
|
55
|
+
/**
|
|
56
|
+
* Get the last error.
|
|
57
|
+
* @returns {any} The last error.
|
|
58
|
+
*/
|
|
59
|
+
getLastError() {
|
|
60
|
+
return this.lastError;
|
|
61
|
+
},
|
|
62
|
+
|
|
49
63
|
@oneFlight
|
|
50
64
|
connect(webSocketUrl) {
|
|
51
65
|
if (this.connected) {
|
|
52
|
-
this.logger.info(
|
|
66
|
+
this.logger.info(`${this.namespace}: already connected, will not connect again`);
|
|
53
67
|
|
|
54
68
|
return Promise.resolve();
|
|
55
69
|
}
|
|
@@ -59,7 +73,7 @@ const Mercury = WebexPlugin.extend({
|
|
|
59
73
|
return Promise.resolve(
|
|
60
74
|
this.webex.internal.device.registered || this.webex.internal.device.register()
|
|
61
75
|
).then(() => {
|
|
62
|
-
this.logger.info(
|
|
76
|
+
this.logger.info(`${this.namespace}: connecting`);
|
|
63
77
|
|
|
64
78
|
return this._connectWithBackoff(webSocketUrl);
|
|
65
79
|
});
|
|
@@ -69,16 +83,14 @@ const Mercury = WebexPlugin.extend({
|
|
|
69
83
|
disconnect() {
|
|
70
84
|
return new Promise((resolve) => {
|
|
71
85
|
if (this.backoffCall) {
|
|
72
|
-
this.logger.info(
|
|
86
|
+
this.logger.info(`${this.namespace}: aborting connection`);
|
|
73
87
|
this.backoffCall.abort();
|
|
74
88
|
}
|
|
75
89
|
|
|
76
90
|
if (this.socket) {
|
|
77
91
|
this.socket.removeAllListeners('message');
|
|
78
92
|
this.once('offline', resolve);
|
|
79
|
-
this.socket.close();
|
|
80
|
-
|
|
81
|
-
return;
|
|
93
|
+
resolve(this.socket.close());
|
|
82
94
|
}
|
|
83
95
|
|
|
84
96
|
resolve();
|
|
@@ -161,11 +173,12 @@ const Mercury = WebexPlugin.extend({
|
|
|
161
173
|
socket.on('close', (...args) => this._onclose(...args));
|
|
162
174
|
socket.on('message', (...args) => this._onmessage(...args));
|
|
163
175
|
socket.on('sequence-mismatch', (...args) => this._emit('sequence-mismatch', ...args));
|
|
176
|
+
socket.on('ping-pong-latency', (...args) => this._emit('ping-pong-latency', ...args));
|
|
164
177
|
|
|
165
178
|
Promise.all([this._prepareUrl(socketUrl), this.webex.credentials.getUserToken()])
|
|
166
179
|
.then(([webSocketUrl, token]) => {
|
|
167
180
|
if (!this.backoffCall) {
|
|
168
|
-
const msg =
|
|
181
|
+
const msg = `${this.namespace}: prevent socket open when backoffCall no longer defined`;
|
|
169
182
|
|
|
170
183
|
this.logger.info(msg);
|
|
171
184
|
|
|
@@ -185,7 +198,7 @@ const Mercury = WebexPlugin.extend({
|
|
|
185
198
|
|
|
186
199
|
// if the consumer has supplied request options use them
|
|
187
200
|
if (this.webex.config.defaultMercuryOptions) {
|
|
188
|
-
this.logger.info(
|
|
201
|
+
this.logger.info(`${this.namespace}: setting custom options`);
|
|
189
202
|
options = {...options, ...this.webex.config.defaultMercuryOptions};
|
|
190
203
|
}
|
|
191
204
|
|
|
@@ -193,18 +206,14 @@ const Mercury = WebexPlugin.extend({
|
|
|
193
206
|
// the socket if it is in the process of being opened.
|
|
194
207
|
this.socket = socket;
|
|
195
208
|
|
|
209
|
+
this.logger.info(`${this.namespace} connection url: ${webSocketUrl}`);
|
|
210
|
+
|
|
196
211
|
return socket.open(webSocketUrl, options);
|
|
197
212
|
})
|
|
198
213
|
.then(() => {
|
|
199
|
-
this.
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
},
|
|
203
|
-
tags: {
|
|
204
|
-
action: 'connected',
|
|
205
|
-
url: attemptWSUrl,
|
|
206
|
-
},
|
|
207
|
-
});
|
|
214
|
+
this.logger.info(
|
|
215
|
+
`${this.namespace}: connected to mercury, success, action: connected, url: ${attemptWSUrl}`
|
|
216
|
+
);
|
|
208
217
|
callback();
|
|
209
218
|
|
|
210
219
|
return this.webex.internal.feature
|
|
@@ -218,6 +227,8 @@ const Mercury = WebexPlugin.extend({
|
|
|
218
227
|
});
|
|
219
228
|
})
|
|
220
229
|
.catch((reason) => {
|
|
230
|
+
this.lastError = reason; // remember the last error
|
|
231
|
+
|
|
221
232
|
// Suppress connection errors that appear to be network related. This
|
|
222
233
|
// may end up suppressing metrics during outages, but we might not care
|
|
223
234
|
// (especially since many of our outages happen in a way that client
|
|
@@ -225,19 +236,19 @@ const Mercury = WebexPlugin.extend({
|
|
|
225
236
|
if (reason.code !== 1006 && this.backoffCall && this.backoffCall.getNumRetries() > 0) {
|
|
226
237
|
this._emit('connection_failed', reason, {retries: this.backoffCall.getNumRetries()});
|
|
227
238
|
}
|
|
228
|
-
this.logger.info(
|
|
239
|
+
this.logger.info(`${this.namespace}: connection attempt failed`, reason);
|
|
229
240
|
// UnknownResponse is produced by IE for any 4XXX; treated it like a bad
|
|
230
241
|
// web socket url and let WDM handle the token checking
|
|
231
242
|
if (reason instanceof UnknownResponse) {
|
|
232
243
|
this.logger.info(
|
|
233
|
-
|
|
244
|
+
`${this.namespace}: received unknown response code, refreshing device registration`
|
|
234
245
|
);
|
|
235
246
|
|
|
236
247
|
return this.webex.internal.device.refresh().then(() => callback(reason));
|
|
237
248
|
}
|
|
238
249
|
// NotAuthorized implies expired token
|
|
239
250
|
if (reason instanceof NotAuthorized) {
|
|
240
|
-
this.logger.info(
|
|
251
|
+
this.logger.info(`${this.namespace}: received authorization error, reauthorizing`);
|
|
241
252
|
|
|
242
253
|
return this.webex.credentials.refresh({force: true}).then(() => callback(reason));
|
|
243
254
|
}
|
|
@@ -250,7 +261,7 @@ const Mercury = WebexPlugin.extend({
|
|
|
250
261
|
// BadRequest implies current credentials are for a Service Account
|
|
251
262
|
// Forbidden implies current user is not entitle for Webex
|
|
252
263
|
if (reason instanceof BadRequest || reason instanceof Forbidden) {
|
|
253
|
-
this.logger.warn(
|
|
264
|
+
this.logger.warn(`${this.namespace}: received unrecoverable response from mercury`);
|
|
254
265
|
this.backoffCall.abort();
|
|
255
266
|
|
|
256
267
|
return callback(reason);
|
|
@@ -261,18 +272,8 @@ const Mercury = WebexPlugin.extend({
|
|
|
261
272
|
.then((haMessagingEnabled) => {
|
|
262
273
|
if (haMessagingEnabled) {
|
|
263
274
|
this.logger.info(
|
|
264
|
-
|
|
275
|
+
`${this.namespace}: received a generic connection error, will try to connect to another datacenter. failed, action: 'failed', url: ${attemptWSUrl} error: ${reason.message}`
|
|
265
276
|
);
|
|
266
|
-
this.webex.internal.metrics.submitClientMetrics('web-ha-mercury', {
|
|
267
|
-
fields: {
|
|
268
|
-
success: false,
|
|
269
|
-
},
|
|
270
|
-
tags: {
|
|
271
|
-
action: 'failed',
|
|
272
|
-
error: reason.message,
|
|
273
|
-
url: attemptWSUrl,
|
|
274
|
-
},
|
|
275
|
-
});
|
|
276
277
|
|
|
277
278
|
return this.webex.internal.services.markFailedUrl(attemptWSUrl);
|
|
278
279
|
}
|
|
@@ -285,7 +286,7 @@ const Mercury = WebexPlugin.extend({
|
|
|
285
286
|
return callback(reason);
|
|
286
287
|
})
|
|
287
288
|
.catch((reason) => {
|
|
288
|
-
this.logger.error(
|
|
289
|
+
this.logger.error(`${this.namespace}: failed to handle connection failure`, reason);
|
|
289
290
|
callback(reason);
|
|
290
291
|
});
|
|
291
292
|
},
|
|
@@ -301,12 +302,15 @@ const Mercury = WebexPlugin.extend({
|
|
|
301
302
|
this.backoffCall = undefined;
|
|
302
303
|
if (err) {
|
|
303
304
|
this.logger.info(
|
|
304
|
-
|
|
305
|
+
`${
|
|
306
|
+
this.namespace
|
|
307
|
+
}: failed to connect after ${call.getNumRetries()} retries; log statement about next retry was inaccurate; ${err}`
|
|
305
308
|
);
|
|
306
309
|
|
|
307
310
|
return reject(err);
|
|
308
311
|
}
|
|
309
312
|
this.connected = true;
|
|
313
|
+
this.hasEverConnected = true;
|
|
310
314
|
this._emit('online');
|
|
311
315
|
|
|
312
316
|
return resolve();
|
|
@@ -314,7 +318,7 @@ const Mercury = WebexPlugin.extend({
|
|
|
314
318
|
|
|
315
319
|
// eslint-disable-next-line prefer-reflect
|
|
316
320
|
call = backoff.call((callback) => {
|
|
317
|
-
this.logger.info(
|
|
321
|
+
this.logger.info(`${this.namespace}: executing connection attempt ${call.getNumRetries()}`);
|
|
318
322
|
this._attemptConnection(webSocketUrl, callback);
|
|
319
323
|
}, onComplete);
|
|
320
324
|
|
|
@@ -325,12 +329,14 @@ const Mercury = WebexPlugin.extend({
|
|
|
325
329
|
})
|
|
326
330
|
);
|
|
327
331
|
|
|
328
|
-
if (this.config.
|
|
332
|
+
if (this.config.initialConnectionMaxRetries && !this.hasEverConnected) {
|
|
333
|
+
call.failAfter(this.config.initialConnectionMaxRetries);
|
|
334
|
+
} else if (this.config.maxRetries) {
|
|
329
335
|
call.failAfter(this.config.maxRetries);
|
|
330
336
|
}
|
|
331
337
|
|
|
332
338
|
call.on('abort', () => {
|
|
333
|
-
this.logger.info(
|
|
339
|
+
this.logger.info(`${this.namespace}: connection aborted`);
|
|
334
340
|
reject(new Error('Mercury Connection Aborted'));
|
|
335
341
|
});
|
|
336
342
|
|
|
@@ -340,16 +346,16 @@ const Mercury = WebexPlugin.extend({
|
|
|
340
346
|
const delay = Math.min(call.strategy_.nextBackoffDelay_, this.config.backoffTimeMax);
|
|
341
347
|
|
|
342
348
|
this.logger.info(
|
|
343
|
-
|
|
349
|
+
`${this.namespace}: failed to connect; attempting retry ${number + 1} in ${delay} ms`
|
|
344
350
|
);
|
|
345
351
|
/* istanbul ignore if */
|
|
346
352
|
if (process.env.NODE_ENV === 'development') {
|
|
347
|
-
this.logger.debug(
|
|
353
|
+
this.logger.debug(`${this.namespace}: `, err, err.stack);
|
|
348
354
|
}
|
|
349
355
|
|
|
350
356
|
return;
|
|
351
357
|
}
|
|
352
|
-
this.logger.info(
|
|
358
|
+
this.logger.info(`${this.namespace}: connected`);
|
|
353
359
|
});
|
|
354
360
|
|
|
355
361
|
call.start();
|
|
@@ -362,7 +368,10 @@ const Mercury = WebexPlugin.extend({
|
|
|
362
368
|
try {
|
|
363
369
|
this.trigger(...args);
|
|
364
370
|
} catch (error) {
|
|
365
|
-
this.logger.error(
|
|
371
|
+
this.logger.error(`${this.namespace}: error occurred in event handler`, {
|
|
372
|
+
error,
|
|
373
|
+
arguments: args,
|
|
374
|
+
});
|
|
366
375
|
}
|
|
367
376
|
},
|
|
368
377
|
|
|
@@ -403,20 +412,20 @@ const Mercury = WebexPlugin.extend({
|
|
|
403
412
|
case 1003:
|
|
404
413
|
// metric: disconnect
|
|
405
414
|
this.logger.info(
|
|
406
|
-
|
|
415
|
+
`${this.namespace}: Mercury service rejected last message; will not reconnect: ${event.reason}`
|
|
407
416
|
);
|
|
408
417
|
this._emit('offline.permanent', event);
|
|
409
418
|
break;
|
|
410
419
|
case 4000:
|
|
411
420
|
// metric: disconnect
|
|
412
|
-
this.logger.info(
|
|
421
|
+
this.logger.info(`${this.namespace}: socket replaced; will not reconnect`);
|
|
413
422
|
this._emit('offline.replaced', event);
|
|
414
423
|
break;
|
|
415
424
|
case 1001:
|
|
416
425
|
case 1005:
|
|
417
426
|
case 1006:
|
|
418
427
|
case 1011:
|
|
419
|
-
this.logger.info(
|
|
428
|
+
this.logger.info(`${this.namespace}: socket disconnected; reconnecting`);
|
|
420
429
|
this._emit('offline.transient', event);
|
|
421
430
|
this._reconnect(socketUrl);
|
|
422
431
|
// metric: disconnect
|
|
@@ -424,23 +433,25 @@ const Mercury = WebexPlugin.extend({
|
|
|
424
433
|
break;
|
|
425
434
|
case 1000:
|
|
426
435
|
if (normalReconnectReasons.includes(reason)) {
|
|
427
|
-
this.logger.info(
|
|
436
|
+
this.logger.info(`${this.namespace}: socket disconnected; reconnecting`);
|
|
428
437
|
this._emit('offline.transient', event);
|
|
429
438
|
this._reconnect(socketUrl);
|
|
430
439
|
// metric: disconnect
|
|
431
440
|
// if (reason === done forced) metric: force closure
|
|
432
441
|
} else {
|
|
433
|
-
this.logger.info(
|
|
442
|
+
this.logger.info(`${this.namespace}: socket disconnected; will not reconnect`);
|
|
434
443
|
this._emit('offline.permanent', event);
|
|
435
444
|
}
|
|
436
445
|
break;
|
|
437
446
|
default:
|
|
438
|
-
this.logger.info(
|
|
447
|
+
this.logger.info(
|
|
448
|
+
`${this.namespace}: socket disconnected unexpectedly; will not reconnect`
|
|
449
|
+
);
|
|
439
450
|
// unexpected disconnect
|
|
440
451
|
this._emit('offline.permanent', event);
|
|
441
452
|
}
|
|
442
453
|
} catch (error) {
|
|
443
|
-
this.logger.error(
|
|
454
|
+
this.logger.error(`${this.namespace}: error occurred in close handler`, error);
|
|
444
455
|
}
|
|
445
456
|
},
|
|
446
457
|
|
|
@@ -448,7 +459,7 @@ const Mercury = WebexPlugin.extend({
|
|
|
448
459
|
const envelope = event.data;
|
|
449
460
|
|
|
450
461
|
if (process.env.ENABLE_MERCURY_LOGGING) {
|
|
451
|
-
this.logger.debug(
|
|
462
|
+
this.logger.debug(`${this.namespace}: message envelope: `, envelope);
|
|
452
463
|
}
|
|
453
464
|
|
|
454
465
|
const {data} = envelope;
|
|
@@ -465,7 +476,7 @@ const Mercury = WebexPlugin.extend({
|
|
|
465
476
|
resolve((this.webex[namespace] || this.webex.internal[namespace])[name](data))
|
|
466
477
|
).catch((reason) =>
|
|
467
478
|
this.logger.error(
|
|
468
|
-
|
|
479
|
+
`${this.namespace}: error occurred in autowired event handler for ${data.eventType}`,
|
|
469
480
|
reason
|
|
470
481
|
)
|
|
471
482
|
);
|
|
@@ -484,12 +495,12 @@ const Mercury = WebexPlugin.extend({
|
|
|
484
495
|
}
|
|
485
496
|
})
|
|
486
497
|
.catch((reason) => {
|
|
487
|
-
this.logger.error(
|
|
498
|
+
this.logger.error(`${this.namespace}: error occurred processing socket message`, reason);
|
|
488
499
|
});
|
|
489
500
|
},
|
|
490
501
|
|
|
491
502
|
_reconnect(webSocketUrl) {
|
|
492
|
-
this.logger.info(
|
|
503
|
+
this.logger.info(`${this.namespace}: reconnecting`);
|
|
493
504
|
|
|
494
505
|
return this.connect(webSocketUrl);
|
|
495
506
|
},
|