@webex/internal-plugin-mercury 2.59.8 → 2.60.0-next.1

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.
@@ -1 +1 @@
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,GAEaH,mBAAM;AAAAI,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
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":["_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,GAEaR,mBAAM;AAAAS,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
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/package.json CHANGED
@@ -1,6 +1,5 @@
1
1
  {
2
2
  "name": "@webex/internal-plugin-mercury",
3
- "version": "2.59.8",
4
3
  "description": "",
5
4
  "license": "MIT",
6
5
  "main": "dist/index.js",
@@ -11,7 +10,7 @@
11
10
  "directory": "packages/@webex/internal-plugin-mercury"
12
11
  },
13
12
  "engines": {
14
- "node": ">=14"
13
+ "node": ">=16"
15
14
  },
16
15
  "browser": {
17
16
  "./dist/socket/socket.js": "./dist/socket/socket.shim.js",
@@ -26,31 +25,31 @@
26
25
  "devDependencies": {
27
26
  "@babel/core": "^7.17.10",
28
27
  "@sinonjs/fake-timers": "^6.0.1",
29
- "@webex/babel-config-legacy": "2.59.8",
30
- "@webex/eslint-config-legacy": "2.59.8",
31
- "@webex/jest-config-legacy": "2.59.8",
32
- "@webex/legacy-tools": "2.59.8",
33
- "@webex/test-helper-chai": "2.59.8",
34
- "@webex/test-helper-mocha": "2.59.8",
35
- "@webex/test-helper-mock-webex": "2.59.8",
36
- "@webex/test-helper-test-users": "2.59.8",
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": "^2.60.0-next.1",
33
+ "@webex/test-helper-mocha": "^2.60.0-next.1",
34
+ "@webex/test-helper-mock-webex": "^2.60.0-next.1",
35
+ "@webex/test-helper-test-users": "^2.60.0-next.1",
37
36
  "eslint": "^8.24.0",
38
37
  "prettier": "^2.7.1",
39
38
  "sinon": "^9.2.4"
40
39
  },
41
40
  "dependencies": {
42
- "@webex/common": "2.59.8",
43
- "@webex/common-timers": "2.59.8",
44
- "@webex/internal-plugin-device": "2.59.8",
45
- "@webex/internal-plugin-feature": "2.59.8",
46
- "@webex/internal-plugin-metrics": "2.59.8",
47
- "@webex/test-helper-chai": "2.59.8",
48
- "@webex/test-helper-mocha": "2.59.8",
49
- "@webex/test-helper-mock-web-socket": "2.59.8",
50
- "@webex/test-helper-mock-webex": "2.59.8",
51
- "@webex/test-helper-refresh-callback": "2.59.8",
52
- "@webex/test-helper-test-users": "2.59.8",
53
- "@webex/webex-core": "2.59.8",
41
+ "@webex/common": "^2.60.0-next.1",
42
+ "@webex/common-timers": "^2.60.0-next.1",
43
+ "@webex/internal-plugin-device": "^2.60.0-next.1",
44
+ "@webex/internal-plugin-feature": "^2.60.0-next.1",
45
+ "@webex/internal-plugin-metrics": "^2.60.0-next.1",
46
+ "@webex/test-helper-chai": "^2.60.0-next.1",
47
+ "@webex/test-helper-mocha": "^2.60.0-next.1",
48
+ "@webex/test-helper-mock-web-socket": "^2.60.0-next.1",
49
+ "@webex/test-helper-mock-webex": "^2.60.0-next.1",
50
+ "@webex/test-helper-refresh-callback": "^2.60.0-next.1",
51
+ "@webex/test-helper-test-users": "^2.60.0-next.1",
52
+ "@webex/webex-core": "^2.60.0-next.1",
54
53
  "backoff": "^2.5.0",
55
54
  "lodash": "^4.17.21",
56
55
  "uuid": "^3.3.2",
@@ -59,10 +58,12 @@
59
58
  "scripts": {
60
59
  "build": "yarn build:src",
61
60
  "build:src": "webex-legacy-tools build -dest \"./dist\" -src \"./src\" -js -ts -maps",
61
+ "deploy:npm": "yarn npm publish",
62
62
  "test": "yarn test:style && yarn test:unit && yarn test:integration && yarn test:browser",
63
63
  "test:browser:broken": "webex-legacy-tools test --integration --unit --runner karma",
64
64
  "test:integration:broken": "webex-legacy-tools test --integration --runner mocha",
65
65
  "test:style": "eslint ./src/**/*.*",
66
66
  "test:unit": "webex-legacy-tools test --unit --runner jest"
67
- }
68
- }
67
+ },
68
+ "version": "2.60.0-next.1"
69
+ }
package/src/mercury.js CHANGED
@@ -49,7 +49,7 @@ const Mercury = WebexPlugin.extend({
49
49
  @oneFlight
50
50
  connect(webSocketUrl) {
51
51
  if (this.connected) {
52
- this.logger.info('mercury: already connected, will not connect again');
52
+ this.logger.info(`${this.namespace}: already connected, will not connect again`);
53
53
 
54
54
  return Promise.resolve();
55
55
  }
@@ -59,7 +59,7 @@ const Mercury = WebexPlugin.extend({
59
59
  return Promise.resolve(
60
60
  this.webex.internal.device.registered || this.webex.internal.device.register()
61
61
  ).then(() => {
62
- this.logger.info('mercury: connecting');
62
+ this.logger.info(`${this.namespace}: connecting`);
63
63
 
64
64
  return this._connectWithBackoff(webSocketUrl);
65
65
  });
@@ -69,16 +69,14 @@ const Mercury = WebexPlugin.extend({
69
69
  disconnect() {
70
70
  return new Promise((resolve) => {
71
71
  if (this.backoffCall) {
72
- this.logger.info('mercury: aborting connection');
72
+ this.logger.info(`${this.namespace}: aborting connection`);
73
73
  this.backoffCall.abort();
74
74
  }
75
75
 
76
76
  if (this.socket) {
77
77
  this.socket.removeAllListeners('message');
78
78
  this.once('offline', resolve);
79
- this.socket.close();
80
-
81
- return;
79
+ resolve(this.socket.close());
82
80
  }
83
81
 
84
82
  resolve();
@@ -165,7 +163,7 @@ const Mercury = WebexPlugin.extend({
165
163
  Promise.all([this._prepareUrl(socketUrl), this.webex.credentials.getUserToken()])
166
164
  .then(([webSocketUrl, token]) => {
167
165
  if (!this.backoffCall) {
168
- const msg = 'mercury: prevent socket open when backoffCall no longer defined';
166
+ const msg = `${this.namespace}: prevent socket open when backoffCall no longer defined`;
169
167
 
170
168
  this.logger.info(msg);
171
169
 
@@ -185,7 +183,7 @@ const Mercury = WebexPlugin.extend({
185
183
 
186
184
  // if the consumer has supplied request options use them
187
185
  if (this.webex.config.defaultMercuryOptions) {
188
- this.logger.info('mercury: setting custom options');
186
+ this.logger.info(`${this.namespace}: setting custom options`);
189
187
  options = {...options, ...this.webex.config.defaultMercuryOptions};
190
188
  }
191
189
 
@@ -193,6 +191,8 @@ const Mercury = WebexPlugin.extend({
193
191
  // the socket if it is in the process of being opened.
194
192
  this.socket = socket;
195
193
 
194
+ this.logger.info(`${this.namespace} connection url: ${webSocketUrl}`);
195
+
196
196
  return socket.open(webSocketUrl, options);
197
197
  })
198
198
  .then(() => {
@@ -201,6 +201,7 @@ const Mercury = WebexPlugin.extend({
201
201
  success: true,
202
202
  },
203
203
  tags: {
204
+ namespace: this.namespace,
204
205
  action: 'connected',
205
206
  url: attemptWSUrl,
206
207
  },
@@ -225,19 +226,19 @@ const Mercury = WebexPlugin.extend({
225
226
  if (reason.code !== 1006 && this.backoffCall && this.backoffCall.getNumRetries() > 0) {
226
227
  this._emit('connection_failed', reason, {retries: this.backoffCall.getNumRetries()});
227
228
  }
228
- this.logger.info('mercury: connection attempt failed', reason);
229
+ this.logger.info(`${this.namespace}: connection attempt failed`, reason);
229
230
  // UnknownResponse is produced by IE for any 4XXX; treated it like a bad
230
231
  // web socket url and let WDM handle the token checking
231
232
  if (reason instanceof UnknownResponse) {
232
233
  this.logger.info(
233
- 'mercury: received unknown response code, refreshing device registration'
234
+ `${this.namespace}: received unknown response code, refreshing device registration`
234
235
  );
235
236
 
236
237
  return this.webex.internal.device.refresh().then(() => callback(reason));
237
238
  }
238
239
  // NotAuthorized implies expired token
239
240
  if (reason instanceof NotAuthorized) {
240
- this.logger.info('mercury: received authorization error, reauthorizing');
241
+ this.logger.info(`${this.namespace}: received authorization error, reauthorizing`);
241
242
 
242
243
  return this.webex.credentials.refresh({force: true}).then(() => callback(reason));
243
244
  }
@@ -250,7 +251,7 @@ const Mercury = WebexPlugin.extend({
250
251
  // BadRequest implies current credentials are for a Service Account
251
252
  // Forbidden implies current user is not entitle for Webex
252
253
  if (reason instanceof BadRequest || reason instanceof Forbidden) {
253
- this.logger.warn('mercury: received unrecoverable response from mercury');
254
+ this.logger.warn(`${this.namespace}: received unrecoverable response from mercury`);
254
255
  this.backoffCall.abort();
255
256
 
256
257
  return callback(reason);
@@ -261,13 +262,14 @@ const Mercury = WebexPlugin.extend({
261
262
  .then((haMessagingEnabled) => {
262
263
  if (haMessagingEnabled) {
263
264
  this.logger.info(
264
- 'mercury: received a generic connection error, will try to connect to another datacenter'
265
+ `${this.namespace}: received a generic connection error, will try to connect to another datacenter`
265
266
  );
266
267
  this.webex.internal.metrics.submitClientMetrics('web-ha-mercury', {
267
268
  fields: {
268
269
  success: false,
269
270
  },
270
271
  tags: {
272
+ namespace: this.namespace,
271
273
  action: 'failed',
272
274
  error: reason.message,
273
275
  url: attemptWSUrl,
@@ -285,7 +287,7 @@ const Mercury = WebexPlugin.extend({
285
287
  return callback(reason);
286
288
  })
287
289
  .catch((reason) => {
288
- this.logger.error('mercury: failed to handle connection failure', reason);
290
+ this.logger.error(`${this.namespace}: failed to handle connection failure`, reason);
289
291
  callback(reason);
290
292
  });
291
293
  },
@@ -301,7 +303,9 @@ const Mercury = WebexPlugin.extend({
301
303
  this.backoffCall = undefined;
302
304
  if (err) {
303
305
  this.logger.info(
304
- `mercury: failed to connect after ${call.getNumRetries()} retries; log statement about next retry was inaccurate; ${err}`
306
+ `${
307
+ this.namespace
308
+ }: failed to connect after ${call.getNumRetries()} retries; log statement about next retry was inaccurate; ${err}`
305
309
  );
306
310
 
307
311
  return reject(err);
@@ -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(`mercury: executing connection attempt ${call.getNumRetries()}`);
321
+ this.logger.info(`${this.namespace}: executing connection attempt ${call.getNumRetries()}`);
318
322
  this._attemptConnection(webSocketUrl, callback);
319
323
  }, onComplete);
320
324
 
@@ -330,7 +334,7 @@ const Mercury = WebexPlugin.extend({
330
334
  }
331
335
 
332
336
  call.on('abort', () => {
333
- this.logger.info('mercury: connection aborted');
337
+ this.logger.info(`${this.namespace}: connection aborted`);
334
338
  reject(new Error('Mercury Connection Aborted'));
335
339
  });
336
340
 
@@ -340,16 +344,16 @@ const Mercury = WebexPlugin.extend({
340
344
  const delay = Math.min(call.strategy_.nextBackoffDelay_, this.config.backoffTimeMax);
341
345
 
342
346
  this.logger.info(
343
- `mercury: failed to connect; attempting retry ${number + 1} in ${delay} ms`
347
+ `${this.namespace}: failed to connect; attempting retry ${number + 1} in ${delay} ms`
344
348
  );
345
349
  /* istanbul ignore if */
346
350
  if (process.env.NODE_ENV === 'development') {
347
- this.logger.debug('mercury: ', err, err.stack);
351
+ this.logger.debug(`${this.namespace}: `, err, err.stack);
348
352
  }
349
353
 
350
354
  return;
351
355
  }
352
- this.logger.info('mercury: connected');
356
+ this.logger.info(`${this.namespace}: connected`);
353
357
  });
354
358
 
355
359
  call.start();
@@ -362,7 +366,10 @@ const Mercury = WebexPlugin.extend({
362
366
  try {
363
367
  this.trigger(...args);
364
368
  } catch (error) {
365
- this.logger.error('mercury: error occurred in event handler', error);
369
+ this.logger.error(`${this.namespace}: error occurred in event handler`, {
370
+ error,
371
+ arguments: args,
372
+ });
366
373
  }
367
374
  },
368
375
 
@@ -403,20 +410,20 @@ const Mercury = WebexPlugin.extend({
403
410
  case 1003:
404
411
  // metric: disconnect
405
412
  this.logger.info(
406
- `mercury: Mercury service rejected last message; will not reconnect: ${event.reason}`
413
+ `${this.namespace}: Mercury service rejected last message; will not reconnect: ${event.reason}`
407
414
  );
408
415
  this._emit('offline.permanent', event);
409
416
  break;
410
417
  case 4000:
411
418
  // metric: disconnect
412
- this.logger.info('mercury: socket replaced; will not reconnect');
419
+ this.logger.info(`${this.namespace}: socket replaced; will not reconnect`);
413
420
  this._emit('offline.replaced', event);
414
421
  break;
415
422
  case 1001:
416
423
  case 1005:
417
424
  case 1006:
418
425
  case 1011:
419
- this.logger.info('mercury: socket disconnected; reconnecting');
426
+ this.logger.info(`${this.namespace}: socket disconnected; reconnecting`);
420
427
  this._emit('offline.transient', event);
421
428
  this._reconnect(socketUrl);
422
429
  // metric: disconnect
@@ -424,23 +431,25 @@ const Mercury = WebexPlugin.extend({
424
431
  break;
425
432
  case 1000:
426
433
  if (normalReconnectReasons.includes(reason)) {
427
- this.logger.info('mercury: socket disconnected; reconnecting');
434
+ this.logger.info(`${this.namespace}: socket disconnected; reconnecting`);
428
435
  this._emit('offline.transient', event);
429
436
  this._reconnect(socketUrl);
430
437
  // metric: disconnect
431
438
  // if (reason === done forced) metric: force closure
432
439
  } else {
433
- this.logger.info('mercury: socket disconnected; will not reconnect');
440
+ this.logger.info(`${this.namespace}: socket disconnected; will not reconnect`);
434
441
  this._emit('offline.permanent', event);
435
442
  }
436
443
  break;
437
444
  default:
438
- this.logger.info('mercury: socket disconnected unexpectedly; will not reconnect');
445
+ this.logger.info(
446
+ `${this.namespace}: socket disconnected unexpectedly; will not reconnect`
447
+ );
439
448
  // unexpected disconnect
440
449
  this._emit('offline.permanent', event);
441
450
  }
442
451
  } catch (error) {
443
- this.logger.error('mercury: error occurred in close handler', error);
452
+ this.logger.error(`${this.namespace}: error occurred in close handler`, error);
444
453
  }
445
454
  },
446
455
 
@@ -448,7 +457,7 @@ const Mercury = WebexPlugin.extend({
448
457
  const envelope = event.data;
449
458
 
450
459
  if (process.env.ENABLE_MERCURY_LOGGING) {
451
- this.logger.debug('mercury: message envelope: ', envelope);
460
+ this.logger.debug(`${this.namespace}: message envelope: `, envelope);
452
461
  }
453
462
 
454
463
  const {data} = envelope;
@@ -465,7 +474,7 @@ const Mercury = WebexPlugin.extend({
465
474
  resolve((this.webex[namespace] || this.webex.internal[namespace])[name](data))
466
475
  ).catch((reason) =>
467
476
  this.logger.error(
468
- `mercury: error occurred in autowired event handler for ${data.eventType}`,
477
+ `${this.namespace}: error occurred in autowired event handler for ${data.eventType}`,
469
478
  reason
470
479
  )
471
480
  );
@@ -484,12 +493,12 @@ const Mercury = WebexPlugin.extend({
484
493
  }
485
494
  })
486
495
  .catch((reason) => {
487
- this.logger.error('mercury: error occurred processing socket message', reason);
496
+ this.logger.error(`${this.namespace}: error occurred processing socket message`, reason);
488
497
  });
489
498
  },
490
499
 
491
500
  _reconnect(webSocketUrl) {
492
- this.logger.info('mercury: reconnecting');
501
+ this.logger.info(`${this.namespace}: reconnecting`);
493
502
 
494
503
  return this.connect(webSocketUrl);
495
504
  },
@@ -30,6 +30,7 @@ export default class Socket extends EventEmitter {
30
30
  */
31
31
  constructor() {
32
32
  super();
33
+ this._domain = 'unknown-domain';
33
34
  this.onmessage = this.onmessage.bind(this);
34
35
  this.onclose = this.onclose.bind(this);
35
36
  }
@@ -111,10 +112,10 @@ export default class Socket extends EventEmitter {
111
112
  return;
112
113
  }
113
114
  // logger is defined once open is called
114
- this.logger.info('socket: closing');
115
+ this.logger.info(`socket,${this._domain}: closing`);
115
116
 
116
117
  if (socket.readyState === 2 || socket.readyState === 3) {
117
- this.logger.info('socket: already closed');
118
+ this.logger.info(`socket,${this._domain}: already closed`);
118
119
  resolve();
119
120
 
120
121
  return;
@@ -134,7 +135,7 @@ export default class Socket extends EventEmitter {
134
135
 
135
136
  const closeTimer = safeSetTimeout(() => {
136
137
  try {
137
- this.logger.info('socket: no close event received, forcing closure');
138
+ this.logger.info(`socket,${this._domain}: no close event received, forcing closure`);
138
139
  resolve(
139
140
  this.onclose({
140
141
  code: 1000,
@@ -142,12 +143,12 @@ export default class Socket extends EventEmitter {
142
143
  })
143
144
  );
144
145
  } catch (error) {
145
- this.logger.warn('socket: force-close failed', error);
146
+ this.logger.warn(`socket,${this._domain}: force-close failed`, error);
146
147
  }
147
148
  }, this.forceCloseDelay);
148
149
 
149
150
  socket.onclose = (event) => {
150
- this.logger.info('socket: close event fired', event.code, event.reason);
151
+ this.logger.info(`socket,${this._domain}: close event fired`, event.code, event.reason);
151
152
  clearTimeout(closeTimer);
152
153
  this.onclose(event);
153
154
  resolve(event);
@@ -171,6 +172,12 @@ export default class Socket extends EventEmitter {
171
172
  * @returns {Promise}
172
173
  */
173
174
  open(url, options) {
175
+ try {
176
+ this._domain = new URL(url).hostname;
177
+ } catch {
178
+ this._domain = url;
179
+ }
180
+
174
181
  return new Promise((resolve, reject) => {
175
182
  /* eslint complexity: [0] */
176
183
  if (!url) {
@@ -201,7 +208,7 @@ export default class Socket extends EventEmitter {
201
208
 
202
209
  const WebSocket = Socket.getWebSocketConstructor();
203
210
 
204
- this.logger.info('socket: creating WebSocket');
211
+ this.logger.info(`socket,${this._domain}: creating WebSocket`);
205
212
  const socket = new WebSocket(url, [], options);
206
213
 
207
214
  socket.binaryType = 'arraybuffer';
@@ -209,7 +216,7 @@ export default class Socket extends EventEmitter {
209
216
 
210
217
  socket.onclose = (event) => {
211
218
  event = this._fixCloseCode(event);
212
- this.logger.info('socket: closed before open', event.code, event.reason);
219
+ this.logger.info(`socket,${this._domain}: closed before open`, event.code, event.reason);
213
220
  switch (event.code) {
214
221
  case 1005:
215
222
  // IE 11 doesn't seem to allow 4XXX codes, so if we get a 1005, assume
@@ -231,10 +238,10 @@ export default class Socket extends EventEmitter {
231
238
  };
232
239
 
233
240
  socket.onopen = () => {
234
- this.logger.info('socket: connected');
241
+ this.logger.info(`socket,${this._domain}: connected`);
235
242
  this._authorize()
236
243
  .then(() => {
237
- this.logger.info('socket: authorized');
244
+ this.logger.info(`socket,${this._domain}: authorized`);
238
245
  socket.onclose = this.onclose;
239
246
  resolve();
240
247
  })
@@ -242,11 +249,11 @@ export default class Socket extends EventEmitter {
242
249
  };
243
250
 
244
251
  socket.onerror = (event) => {
245
- this.logger.warn('socket: error event fired', event);
252
+ this.logger.warn(`socket,${this._domain}: error event fired`, event);
246
253
  };
247
254
 
248
255
  sockets.set(this, socket);
249
- this.logger.info('socket: waiting for server');
256
+ this.logger.info(`socket,${this._domain}: waiting for server`);
250
257
  });
251
258
  }
252
259
 
@@ -256,7 +263,7 @@ export default class Socket extends EventEmitter {
256
263
  * @returns {undefined}
257
264
  */
258
265
  onclose(event) {
259
- this.logger.info('socket: closed', event.code, event.reason);
266
+ this.logger.info(`socket,${this._domain}: closed`, event.code, event.reason);
260
267
  clearTimeout(this.pongTimer);
261
268
  clearTimeout(this.pingTimer);
262
269
 
@@ -278,10 +285,10 @@ export default class Socket extends EventEmitter {
278
285
  const data = JSON.parse(event.data);
279
286
  const sequenceNumber = parseInt(data.sequenceNumber, 10);
280
287
 
281
- this.logger.debug('socket: sequence number: ', sequenceNumber);
288
+ this.logger.debug(`socket,${this._domain}: sequence number: `, sequenceNumber);
282
289
  if (this.expectedSequenceNumber && sequenceNumber !== this.expectedSequenceNumber) {
283
290
  this.logger.debug(
284
- `socket: sequence number mismatch indicates lost mercury message. expected: ${this.expectedSequenceNumber}, actual: ${sequenceNumber}`
291
+ `socket,${this._domain}: sequence number mismatch indicates lost mercury message. expected: ${this.expectedSequenceNumber}, actual: ${sequenceNumber}`
285
292
  );
286
293
  this.emit('sequence-mismatch', sequenceNumber, this.expectedSequenceNumber);
287
294
  }
@@ -303,7 +310,7 @@ export default class Socket extends EventEmitter {
303
310
  // message from Mercury. At this time, the only action we have is to
304
311
  // ignore it and move on.
305
312
  /* istanbul ignore next */
306
- this.logger.warn('socket: error while receiving WebSocket message', error);
313
+ this.logger.warn(`socket,${this._domain}: error while receiving WebSocket message`, error);
307
314
  }
308
315
  }
309
316
 
@@ -357,7 +364,7 @@ export default class Socket extends EventEmitter {
357
364
  */
358
365
  _authorize() {
359
366
  return new Promise((resolve) => {
360
- this.logger.info('socket: authorizing');
367
+ this.logger.info(`socket,${this._domain}: authorizing`);
361
368
  this.send({
362
369
  id: uuid.v4(),
363
370
  type: 'authorization',
@@ -395,12 +402,18 @@ export default class Socket extends EventEmitter {
395
402
  if (event.code === 1005 && event.reason) {
396
403
  switch (event.reason.toLowerCase()) {
397
404
  case 'replaced':
398
- this.logger.info('socket: fixing CloseEvent code for reason: ', event.reason);
405
+ this.logger.info(
406
+ `socket,${this._domain}: fixing CloseEvent code for reason: `,
407
+ event.reason
408
+ );
399
409
  event.code = 4000;
400
410
  break;
401
411
  case 'authentication failed':
402
412
  case 'authentication did not happen within the timeout window of 30000 seconds.':
403
- this.logger.info('socket: fixing CloseEvent code for reason: ', event.reason);
413
+ this.logger.info(
414
+ `socket,${this._domain}: fixing CloseEvent code for reason: `,
415
+ event.reason
416
+ );
404
417
  event.code = 1008;
405
418
  break;
406
419
  default:
@@ -420,10 +433,12 @@ export default class Socket extends EventEmitter {
420
433
  _ping(id) {
421
434
  const confirmPongId = (event) => {
422
435
  try {
423
- this.logger.debug('socket: pong', event.data.id);
436
+ this.logger.debug(`socket,${this._domain}: pong`, event.data.id);
424
437
  if (event.data && event.data.id !== id) {
425
- this.logger.info('socket: received pong for wrong ping id, closing socket');
426
- this.logger.debug('socket: expected', id, 'received', event.data.id);
438
+ this.logger.info(
439
+ `socket,${this._domain}: received pong for wrong ping id, closing socket`
440
+ );
441
+ this.logger.debug(`socket,${this._domain}: expected`, id, 'received', event.data.id);
427
442
  this.close({
428
443
  code: 1000,
429
444
  reason: 'Pong mismatch',
@@ -433,24 +448,29 @@ export default class Socket extends EventEmitter {
433
448
  // This try/catch block was added as a debugging step; to the best of my
434
449
  // knowledge, the above can never throw.
435
450
  /* istanbul ignore next */
436
- this.logger.error('socket: error occurred in confirmPongId', error);
451
+ this.logger.error(`socket,${this._domain}: error occurred in confirmPongId`, error);
437
452
  }
438
453
  };
439
454
 
440
455
  const onPongNotReceived = () => {
441
456
  try {
442
- this.logger.info('socket: pong not receive in expected period, closing socket');
457
+ this.logger.info(
458
+ `socket,${this._domain}: pong not receive in expected period, closing socket`
459
+ );
443
460
  this.close({
444
461
  code: 1000,
445
462
  reason: 'Pong not received',
446
463
  }).catch((reason) => {
447
- this.logger.warn('socket: failed to close socket after missed pong', reason);
464
+ this.logger.warn(
465
+ `socket,${this._domain}: failed to close socket after missed pong`,
466
+ reason
467
+ );
448
468
  });
449
469
  } catch (error) {
450
470
  // This try/catch block was added as a debugging step; to the best of my
451
471
  // knowledge, the above can never throw.
452
472
  /* istanbul ignore next */
453
- this.logger.error('socket: error occurred in onPongNotReceived', error);
473
+ this.logger.error(`socket,${this._domain}: error occurred in onPongNotReceived`, error);
454
474
  }
455
475
  };
456
476
 
@@ -462,7 +482,10 @@ export default class Socket extends EventEmitter {
462
482
  // This try/catch block was added as a debugging step; to the best of my
463
483
  // knowledge, the above can never throw.
464
484
  /* istanbul ignore next */
465
- this.logger.error('socket: error occurred in scheduleNextPingAndCancelPongTimer', error);
485
+ this.logger.error(
486
+ `socket,${this._domain}: error occurred in scheduleNextPingAndCancelPongTimer`,
487
+ error
488
+ );
466
489
  }
467
490
  };
468
491
 
@@ -471,7 +494,7 @@ export default class Socket extends EventEmitter {
471
494
  this.once('pong', scheduleNextPingAndCancelPongTimer);
472
495
  this.once('pong', confirmPongId);
473
496
 
474
- this.logger.debug(`socket: ping ${id}`);
497
+ this.logger.debug(`socket,${this._domain}: ping ${id}`);
475
498
 
476
499
  return this.send({
477
500
  id,
@@ -32,12 +32,13 @@ describe('plugin-mercury', function () {
32
32
  );
33
33
 
34
34
  describe('onBeforeLogout()', () => {
35
- it('disconnects the web socket', () =>
35
+ it('disconnects the web socket', () => {
36
36
  webex.logout({noRedirect: true}).then(() => {
37
37
  assert.called(webex.internal.mercury.disconnect);
38
38
  assert.isFalse(webex.internal.mercury.connected);
39
39
  assert.called(webex.internal.device.unregister);
40
40
  assert.isFalse(webex.internal.device.registered);
41
- }));
41
+ });
42
+ });
42
43
  });
43
44
  });
@@ -558,7 +558,7 @@ describe('plugin-mercury', () => {
558
558
  return promiseTick(webex.internal.mercury.config.backoffTimeReset).then(() => {
559
559
  assert.equal(
560
560
  reason.message,
561
- 'mercury: prevent socket open when backoffCall no longer defined'
561
+ 'Mercury: prevent socket open when backoffCall no longer defined'
562
562
  );
563
563
  });
564
564
  });
@@ -566,12 +566,21 @@ describe('plugin-mercury', () => {
566
566
  });
567
567
 
568
568
  describe('#_emit()', () => {
569
- it('emits Error-safe events', () => {
569
+ it('emits Error-safe events and log the error with the call parameters', () => {
570
+ const error = 'error';
571
+ const event = {data: 'some data'};
570
572
  mercury.on('break', () => {
571
- throw new Error();
573
+ throw error;
572
574
  });
575
+ sinon.stub(mercury.logger, 'error');
573
576
 
574
- return Promise.resolve(mercury._emit('break'));
577
+ return Promise.resolve(mercury._emit('break', event)).then((res) => {
578
+ assert.calledWith(mercury.logger.error, 'Mercury: error occurred in event handler', {
579
+ error,
580
+ arguments: ['break', event],
581
+ });
582
+ return res;
583
+ });
575
584
  });
576
585
  });
577
586