@webex/internal-plugin-device 3.11.0 → 3.12.0-next.2
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/dist/config.js +16 -10
- package/dist/config.js.map +1 -1
- package/dist/constants.js +6 -1
- package/dist/constants.js.map +1 -1
- package/dist/device.js +181 -79
- package/dist/device.js.map +1 -1
- package/dist/ipNetworkDetector.js +3 -3
- package/dist/ipNetworkDetector.js.map +1 -1
- package/package.json +10 -10
- package/src/config.js +16 -9
- package/src/constants.js +5 -0
- package/src/device.js +150 -26
- package/src/ipNetworkDetector.ts +1 -1
- package/test/unit/spec/device.js +641 -46
package/dist/config.js
CHANGED
|
@@ -59,15 +59,21 @@ var _default = exports.default = {
|
|
|
59
59
|
* energyForcast
|
|
60
60
|
* @type {boolean}
|
|
61
61
|
*/
|
|
62
|
-
energyForecast: false
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
62
|
+
energyForecast: false,
|
|
63
|
+
/**
|
|
64
|
+
* debugFeatureTogglesKey
|
|
65
|
+
* The session storage key for debug feature toggles
|
|
66
|
+
* @type {string}
|
|
67
|
+
*/
|
|
68
|
+
debugFeatureTogglesKey: undefined,
|
|
69
|
+
/**
|
|
70
|
+
* installationId is used exclusively as web client for fraud prevention,
|
|
71
|
+
* and is aliased to as machineId by CA.
|
|
72
|
+
*
|
|
73
|
+
* @alias device.machineId
|
|
74
|
+
* @type {string}
|
|
75
|
+
*/
|
|
76
|
+
installationId: undefined
|
|
77
|
+
}
|
|
72
78
|
};
|
|
73
79
|
//# sourceMappingURL=config.js.map
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_common","require","_default","exports","default","device","canRegisterWaitDuration","defaults","body","name","process","title","trim","undefined","inBrowser","deviceType","WEB","model","localizedModel","systemName","systemVersion","enableInactivityEnforcement","ephemeral","ephemeralDeviceTTL","energyForecast","installationId"],"sources":["config.js"],"sourcesContent":["import {inBrowser, deviceType} from '@webex/common';\n\nexport default {\n device: {\n /**\n * The duration to wait for the catalog to populate in seconds.\n *\n * @type {number}\n */\n canRegisterWaitDuration: 10,\n\n /**\n * The default configuration group when sending registration requests.\n *\n * @type {Object}\n */\n defaults: {\n /**\n * The default body configuration of registration requests.\n *\n * @type {Object}\n */\n body: {\n name:\n (typeof process.title === 'string' ? process.title.trim() : undefined) ||\n (inBrowser && 'browser') ||\n 'javascript',\n deviceType: deviceType.WEB,\n model: 'web-js-sdk',\n localizedModel: 'webex-js-sdk',\n systemName: 'WEBEX_JS_SDK',\n systemVersion: '1.0.0',\n },\n },\n\n /**\n * When true, the **wdm** service will enforce an inactivity duration.\n *\n * @type {boolean}\n */\n enableInactivityEnforcement: false,\n\n /**\n * When true, the device registration will include a ttl value of\n * {@link config.device.ephemeralDeviceTTL} and refresh on an interval of\n * {@link config.device.ephemeralDeviceTTL} / 2 + 60 seconds.\n *\n * @type {boolean}\n */\n ephemeral: false,\n\n /**\n * The ttl value to include in device registration if\n * {@link config.device.ephemeral} is true. Measured in seconds.\n *\n * @type {boolean}\n */\n ephemeralDeviceTTL: 30 * 60,\n\n /**\n * energyForcast\n * @type {boolean}\n */\n energyForecast: false,\n
|
|
1
|
+
{"version":3,"names":["_common","require","_default","exports","default","device","canRegisterWaitDuration","defaults","body","name","process","title","trim","undefined","inBrowser","deviceType","WEB","model","localizedModel","systemName","systemVersion","enableInactivityEnforcement","ephemeral","ephemeralDeviceTTL","energyForecast","debugFeatureTogglesKey","installationId"],"sources":["config.js"],"sourcesContent":["import {inBrowser, deviceType} from '@webex/common';\n\nexport default {\n device: {\n /**\n * The duration to wait for the catalog to populate in seconds.\n *\n * @type {number}\n */\n canRegisterWaitDuration: 10,\n\n /**\n * The default configuration group when sending registration requests.\n *\n * @type {Object}\n */\n defaults: {\n /**\n * The default body configuration of registration requests.\n *\n * @type {Object}\n */\n body: {\n name:\n (typeof process.title === 'string' ? process.title.trim() : undefined) ||\n (inBrowser && 'browser') ||\n 'javascript',\n deviceType: deviceType.WEB,\n model: 'web-js-sdk',\n localizedModel: 'webex-js-sdk',\n systemName: 'WEBEX_JS_SDK',\n systemVersion: '1.0.0',\n },\n },\n\n /**\n * When true, the **wdm** service will enforce an inactivity duration.\n *\n * @type {boolean}\n */\n enableInactivityEnforcement: false,\n\n /**\n * When true, the device registration will include a ttl value of\n * {@link config.device.ephemeralDeviceTTL} and refresh on an interval of\n * {@link config.device.ephemeralDeviceTTL} / 2 + 60 seconds.\n *\n * @type {boolean}\n */\n ephemeral: false,\n\n /**\n * The ttl value to include in device registration if\n * {@link config.device.ephemeral} is true. Measured in seconds.\n *\n * @type {boolean}\n */\n ephemeralDeviceTTL: 30 * 60,\n\n /**\n * energyForcast\n * @type {boolean}\n */\n energyForecast: false,\n\n /**\n * debugFeatureTogglesKey\n * The session storage key for debug feature toggles\n * @type {string}\n */\n debugFeatureTogglesKey: undefined,\n\n /**\n * installationId is used exclusively as web client for fraud prevention,\n * and is aliased to as machineId by CA.\n *\n * @alias device.machineId\n * @type {string}\n */\n installationId: undefined,\n },\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAAoD,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAErC;EACbC,MAAM,EAAE;IACN;AACJ;AACA;AACA;AACA;IACIC,uBAAuB,EAAE,EAAE;IAE3B;AACJ;AACA;AACA;AACA;IACIC,QAAQ,EAAE;MACR;AACN;AACA;AACA;AACA;MACMC,IAAI,EAAE;QACJC,IAAI,EACF,CAAC,OAAOC,OAAO,CAACC,KAAK,KAAK,QAAQ,GAAGD,OAAO,CAACC,KAAK,CAACC,IAAI,CAAC,CAAC,GAAGC,SAAS,KACpEC,iBAAS,IAAI,SAAU,IACxB,YAAY;QACdC,UAAU,EAAEA,kBAAU,CAACC,GAAG;QAC1BC,KAAK,EAAE,YAAY;QACnBC,cAAc,EAAE,cAAc;QAC9BC,UAAU,EAAE,cAAc;QAC1BC,aAAa,EAAE;MACjB;IACF,CAAC;IAED;AACJ;AACA;AACA;AACA;IACIC,2BAA2B,EAAE,KAAK;IAElC;AACJ;AACA;AACA;AACA;AACA;AACA;IACIC,SAAS,EAAE,KAAK;IAEhB;AACJ;AACA;AACA;AACA;AACA;IACIC,kBAAkB,EAAE,EAAE,GAAG,EAAE;IAE3B;AACJ;AACA;AACA;IACIC,cAAc,EAAE,KAAK;IAErB;AACJ;AACA;AACA;AACA;IACIC,sBAAsB,EAAEZ,SAAS;IAEjC;AACJ;AACA;AACA;AACA;AACA;AACA;IACIa,cAAc,EAAEb;EAClB;AACF,CAAC","ignoreList":[]}
|
package/dist/constants.js
CHANGED
|
@@ -4,7 +4,7 @@ var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/defi
|
|
|
4
4
|
_Object$defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.FEATURE_TYPES = exports.FEATURE_COLLECTION_USER = exports.FEATURE_COLLECTION_NAMES = exports.FEATURE_COLLECTION_ENTITLEMENT = exports.FEATURE_COLLECTION_DEVELOPER = exports.DEVICE_EVENT_REGISTRATION_SUCCESS = exports.DEVICE_EVENTS = exports.CISCO_DEVICE_URL = void 0;
|
|
7
|
+
exports.MIN_DEVICES_FOR_CLEANUP = exports.MAX_DELETION_CONFIRMATION_ATTEMPTS = exports.FEATURE_TYPES = exports.FEATURE_COLLECTION_USER = exports.FEATURE_COLLECTION_NAMES = exports.FEATURE_COLLECTION_ENTITLEMENT = exports.FEATURE_COLLECTION_DEVELOPER = exports.DEVICE_EVENT_REGISTRATION_SUCCESS = exports.DEVICE_EVENTS = exports.DELETION_CONFIRMATION_DELAY_MS = exports.CISCO_DEVICE_URL = void 0;
|
|
8
8
|
// Feature constants.
|
|
9
9
|
var FEATURE_COLLECTION_DEVELOPER = exports.FEATURE_COLLECTION_DEVELOPER = 'developer';
|
|
10
10
|
var FEATURE_COLLECTION_ENTITLEMENT = exports.FEATURE_COLLECTION_ENTITLEMENT = 'entitlement';
|
|
@@ -20,4 +20,9 @@ var FEATURE_TYPES = exports.FEATURE_TYPES = {
|
|
|
20
20
|
// Device constants.
|
|
21
21
|
var DEVICE_EVENT_REGISTRATION_SUCCESS = exports.DEVICE_EVENT_REGISTRATION_SUCCESS = 'registration:success';
|
|
22
22
|
var DEVICE_EVENTS = exports.DEVICE_EVENTS = [DEVICE_EVENT_REGISTRATION_SUCCESS];
|
|
23
|
+
|
|
24
|
+
// Device deletion constants.
|
|
25
|
+
var MIN_DEVICES_FOR_CLEANUP = exports.MIN_DEVICES_FOR_CLEANUP = 5;
|
|
26
|
+
var MAX_DELETION_CONFIRMATION_ATTEMPTS = exports.MAX_DELETION_CONFIRMATION_ATTEMPTS = 5;
|
|
27
|
+
var DELETION_CONFIRMATION_DELAY_MS = exports.DELETION_CONFIRMATION_DELAY_MS = 3000;
|
|
23
28
|
//# sourceMappingURL=constants.js.map
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["FEATURE_COLLECTION_DEVELOPER","exports","FEATURE_COLLECTION_ENTITLEMENT","FEATURE_COLLECTION_USER","CISCO_DEVICE_URL","FEATURE_COLLECTION_NAMES","FEATURE_TYPES","BOOLEAN","NUMBER","STRING","DEVICE_EVENT_REGISTRATION_SUCCESS","DEVICE_EVENTS"],"sources":["constants.js"],"sourcesContent":["// Feature constants.\nexport const FEATURE_COLLECTION_DEVELOPER = 'developer';\nexport const FEATURE_COLLECTION_ENTITLEMENT = 'entitlement';\nexport const FEATURE_COLLECTION_USER = 'user';\n\nexport const CISCO_DEVICE_URL = 'cisco-device-url';\n\nexport const FEATURE_COLLECTION_NAMES = [\n FEATURE_COLLECTION_DEVELOPER,\n FEATURE_COLLECTION_ENTITLEMENT,\n FEATURE_COLLECTION_USER,\n];\n\nexport const FEATURE_TYPES = {\n BOOLEAN: 'boolean',\n NUMBER: 'number',\n STRING: 'string',\n};\n\n// Device constants.\nexport const DEVICE_EVENT_REGISTRATION_SUCCESS = 'registration:success';\n\nexport const DEVICE_EVENTS = [DEVICE_EVENT_REGISTRATION_SUCCESS];\n"],"mappings":";;;;;;;AAAA;AACO,IAAMA,4BAA4B,GAAAC,OAAA,CAAAD,4BAAA,GAAG,WAAW;AAChD,IAAME,8BAA8B,GAAAD,OAAA,CAAAC,8BAAA,GAAG,aAAa;AACpD,IAAMC,uBAAuB,GAAAF,OAAA,CAAAE,uBAAA,GAAG,MAAM;AAEtC,IAAMC,gBAAgB,GAAAH,OAAA,CAAAG,gBAAA,GAAG,kBAAkB;AAE3C,IAAMC,wBAAwB,GAAAJ,OAAA,CAAAI,wBAAA,GAAG,CACtCL,4BAA4B,EAC5BE,8BAA8B,EAC9BC,uBAAuB,CACxB;AAEM,IAAMG,aAAa,GAAAL,OAAA,CAAAK,aAAA,GAAG;EAC3BC,OAAO,EAAE,SAAS;EAClBC,MAAM,EAAE,QAAQ;EAChBC,MAAM,EAAE;AACV,CAAC;;AAED;AACO,IAAMC,iCAAiC,GAAAT,OAAA,CAAAS,iCAAA,GAAG,sBAAsB;AAEhE,IAAMC,aAAa,GAAAV,OAAA,CAAAU,aAAA,GAAG,CAACD,iCAAiC,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["FEATURE_COLLECTION_DEVELOPER","exports","FEATURE_COLLECTION_ENTITLEMENT","FEATURE_COLLECTION_USER","CISCO_DEVICE_URL","FEATURE_COLLECTION_NAMES","FEATURE_TYPES","BOOLEAN","NUMBER","STRING","DEVICE_EVENT_REGISTRATION_SUCCESS","DEVICE_EVENTS","MIN_DEVICES_FOR_CLEANUP","MAX_DELETION_CONFIRMATION_ATTEMPTS","DELETION_CONFIRMATION_DELAY_MS"],"sources":["constants.js"],"sourcesContent":["// Feature constants.\nexport const FEATURE_COLLECTION_DEVELOPER = 'developer';\nexport const FEATURE_COLLECTION_ENTITLEMENT = 'entitlement';\nexport const FEATURE_COLLECTION_USER = 'user';\n\nexport const CISCO_DEVICE_URL = 'cisco-device-url';\n\nexport const FEATURE_COLLECTION_NAMES = [\n FEATURE_COLLECTION_DEVELOPER,\n FEATURE_COLLECTION_ENTITLEMENT,\n FEATURE_COLLECTION_USER,\n];\n\nexport const FEATURE_TYPES = {\n BOOLEAN: 'boolean',\n NUMBER: 'number',\n STRING: 'string',\n};\n\n// Device constants.\nexport const DEVICE_EVENT_REGISTRATION_SUCCESS = 'registration:success';\n\nexport const DEVICE_EVENTS = [DEVICE_EVENT_REGISTRATION_SUCCESS];\n\n// Device deletion constants.\nexport const MIN_DEVICES_FOR_CLEANUP = 5;\nexport const MAX_DELETION_CONFIRMATION_ATTEMPTS = 5;\nexport const DELETION_CONFIRMATION_DELAY_MS = 3000;\n"],"mappings":";;;;;;;AAAA;AACO,IAAMA,4BAA4B,GAAAC,OAAA,CAAAD,4BAAA,GAAG,WAAW;AAChD,IAAME,8BAA8B,GAAAD,OAAA,CAAAC,8BAAA,GAAG,aAAa;AACpD,IAAMC,uBAAuB,GAAAF,OAAA,CAAAE,uBAAA,GAAG,MAAM;AAEtC,IAAMC,gBAAgB,GAAAH,OAAA,CAAAG,gBAAA,GAAG,kBAAkB;AAE3C,IAAMC,wBAAwB,GAAAJ,OAAA,CAAAI,wBAAA,GAAG,CACtCL,4BAA4B,EAC5BE,8BAA8B,EAC9BC,uBAAuB,CACxB;AAEM,IAAMG,aAAa,GAAAL,OAAA,CAAAK,aAAA,GAAG;EAC3BC,OAAO,EAAE,SAAS;EAClBC,MAAM,EAAE,QAAQ;EAChBC,MAAM,EAAE;AACV,CAAC;;AAED;AACO,IAAMC,iCAAiC,GAAAT,OAAA,CAAAS,iCAAA,GAAG,sBAAsB;AAEhE,IAAMC,aAAa,GAAAV,OAAA,CAAAU,aAAA,GAAG,CAACD,iCAAiC,CAAC;;AAEhE;AACO,IAAME,uBAAuB,GAAAX,OAAA,CAAAW,uBAAA,GAAG,CAAC;AACjC,IAAMC,kCAAkC,GAAAZ,OAAA,CAAAY,kCAAA,GAAG,CAAC;AAC5C,IAAMC,8BAA8B,GAAAb,OAAA,CAAAa,8BAAA,GAAG,IAAI","ignoreList":[]}
|
package/dist/device.js
CHANGED
|
@@ -13,8 +13,11 @@ _Object$defineProperty(exports, "__esModule", {
|
|
|
13
13
|
exports.default = void 0;
|
|
14
14
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
|
|
15
15
|
var _apply = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/reflect/apply"));
|
|
16
|
+
var _entries = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/entries"));
|
|
16
17
|
var _now = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/date/now"));
|
|
17
18
|
var _getOwnPropertyDescriptor = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptor"));
|
|
19
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/toConsumableArray"));
|
|
20
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/slicedToArray"));
|
|
18
21
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
|
|
19
22
|
var _applyDecoratedDescriptor2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/applyDecoratedDescriptor"));
|
|
20
23
|
var _common = require("@webex/common");
|
|
@@ -406,51 +409,105 @@ var Device = _webexCore.WebexPlugin.extend((_dec = (0, _webexCore.waitForValue)(
|
|
|
406
409
|
});
|
|
407
410
|
},
|
|
408
411
|
/**
|
|
409
|
-
* Fetches
|
|
410
|
-
* @returns {Promise<
|
|
412
|
+
* Fetches devices matching the current device type.
|
|
413
|
+
* @returns {Promise<Array>} filtered device list
|
|
411
414
|
*/
|
|
412
|
-
|
|
413
|
-
var
|
|
414
|
-
|
|
415
|
+
_getDevicesOfCurrentType: function _getDevicesOfCurrentType() {
|
|
416
|
+
var _this$_getBody = this._getBody(),
|
|
417
|
+
deviceType = _this$_getBody.deviceType;
|
|
415
418
|
return this.request({
|
|
416
419
|
method: 'GET',
|
|
417
420
|
service: 'wdm',
|
|
418
421
|
resource: 'devices'
|
|
419
422
|
}).then(function (response) {
|
|
420
|
-
|
|
421
|
-
var _this2$_getBody = _this2._getBody(),
|
|
422
|
-
deviceType = _this2$_getBody.deviceType;
|
|
423
|
-
|
|
424
|
-
// Filter devices of type deviceType
|
|
425
|
-
var webDevices = devices.filter(function (item) {
|
|
423
|
+
return response.body.devices.filter(function (item) {
|
|
426
424
|
return item.deviceType === deviceType;
|
|
427
425
|
});
|
|
426
|
+
});
|
|
427
|
+
},
|
|
428
|
+
/**
|
|
429
|
+
* Waits until the server-side device count drops to or below targetCount,
|
|
430
|
+
* polling up to maxAttempts times with a delay between each check.
|
|
431
|
+
* @param {number} targetCount - resolve when device count drops to this value or below
|
|
432
|
+
* @param {number} [attempt=0]
|
|
433
|
+
* @returns {Promise<void>}
|
|
434
|
+
*/
|
|
435
|
+
_waitForDeviceCountBelowLimit: function _waitForDeviceCountBelowLimit(targetCount) {
|
|
436
|
+
var _this2 = this;
|
|
437
|
+
var attempt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
438
|
+
if (attempt >= _constants.MAX_DELETION_CONFIRMATION_ATTEMPTS) {
|
|
439
|
+
this.logger.warn('device: max confirmation attempts reached, proceeding anyway');
|
|
440
|
+
return _promise.default.resolve();
|
|
441
|
+
}
|
|
442
|
+
return new _promise.default(function (resolve) {
|
|
443
|
+
return setTimeout(resolve, _constants.DELETION_CONFIRMATION_DELAY_MS);
|
|
444
|
+
}).then(function () {
|
|
445
|
+
return _this2._getDevicesOfCurrentType();
|
|
446
|
+
}).then(function (devices) {
|
|
447
|
+
_this2.logger.info("device: confirmation check ".concat(attempt + 1, "/").concat(_constants.MAX_DELETION_CONFIRMATION_ATTEMPTS, ", ") + "".concat(devices.length, " devices remaining (target: \u2264 ").concat(targetCount, ")"));
|
|
448
|
+
if (devices.length <= targetCount) {
|
|
449
|
+
_this2.logger.info('device: device count is now safely below limit');
|
|
450
|
+
return _promise.default.resolve();
|
|
451
|
+
}
|
|
452
|
+
return _this2._waitForDeviceCountBelowLimit(targetCount, attempt + 1);
|
|
453
|
+
}).catch(function (error) {
|
|
454
|
+
_this2.logger.warn("device: confirmation check ".concat(attempt + 1, " failed, proceeding anyway:"), error);
|
|
455
|
+
return _promise.default.resolve();
|
|
456
|
+
});
|
|
457
|
+
},
|
|
458
|
+
/**
|
|
459
|
+
* Fetches the web devices and deletes the oldest third, then waits
|
|
460
|
+
* for the server to confirm the count is below the limit.
|
|
461
|
+
* @returns {Promise<void>}
|
|
462
|
+
*/
|
|
463
|
+
deleteDevices: function deleteDevices() {
|
|
464
|
+
var _this3 = this;
|
|
465
|
+
var targetCount;
|
|
466
|
+
return this._getDevicesOfCurrentType().then(function (webDevices) {
|
|
428
467
|
var sortedDevices = (0, _lodash.orderBy)(webDevices, [function (item) {
|
|
429
468
|
return new Date(item.modificationTime);
|
|
430
469
|
}]);
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
var totalItems = sortedDevices.length;
|
|
435
|
-
var countToDelete = Math.ceil(totalItems / 3);
|
|
436
|
-
var urlsToDelete = sortedDevices.slice(0, countToDelete).map(function (item) {
|
|
437
|
-
return item.url;
|
|
438
|
-
});
|
|
439
|
-
return _promise.default.race(urlsToDelete.map(function (url) {
|
|
440
|
-
return _this2.request({
|
|
441
|
-
uri: url,
|
|
442
|
-
method: 'DELETE'
|
|
443
|
-
});
|
|
444
|
-
}));
|
|
470
|
+
if (sortedDevices.length <= _constants.MIN_DEVICES_FOR_CLEANUP) {
|
|
471
|
+
_this3.logger.info("device: only ".concat(sortedDevices.length, " devices found (minimum ").concat(_constants.MIN_DEVICES_FOR_CLEANUP, "), skipping cleanup"));
|
|
472
|
+
return _promise.default.resolve();
|
|
445
473
|
}
|
|
446
|
-
|
|
474
|
+
var devicesToDelete = sortedDevices.slice(0, Math.ceil(sortedDevices.length / 3));
|
|
475
|
+
targetCount = sortedDevices.length - Math.min(5, devicesToDelete.length);
|
|
476
|
+
_this3.logger.info("device: deleting ".concat(devicesToDelete.length, " of ").concat(webDevices.length, " devices"));
|
|
477
|
+
return _promise.default.all(devicesToDelete.map(function (device) {
|
|
478
|
+
return _this3.request({
|
|
479
|
+
uri: device.url,
|
|
480
|
+
method: 'DELETE'
|
|
481
|
+
}).then(function () {
|
|
482
|
+
return {
|
|
483
|
+
status: 'fulfilled'
|
|
484
|
+
};
|
|
485
|
+
}).catch(function (reason) {
|
|
486
|
+
return {
|
|
487
|
+
status: 'rejected',
|
|
488
|
+
reason: reason
|
|
489
|
+
};
|
|
490
|
+
});
|
|
491
|
+
})).then(function (results) {
|
|
492
|
+
var failed = results.filter(function (r) {
|
|
493
|
+
return r.status === 'rejected';
|
|
494
|
+
});
|
|
495
|
+
if (failed.length > 0) {
|
|
496
|
+
_this3.logger.warn("device: ".concat(failed.length, " of ").concat(devicesToDelete.length, " deletions failed (best-effort, continuing)"));
|
|
497
|
+
}
|
|
498
|
+
_this3.logger.info("device: deleted ".concat(devicesToDelete.length - failed.length, " of ").concat(devicesToDelete.length, " devices"));
|
|
499
|
+
});
|
|
500
|
+
}).then(function () {
|
|
501
|
+
return targetCount !== undefined ? _this3._waitForDeviceCountBelowLimit(targetCount, 0) : _promise.default.resolve();
|
|
502
|
+
}).then(function () {
|
|
503
|
+
_this3.logger.info('device: device count confirmed below limit, cleanup successful');
|
|
447
504
|
}).catch(function (error) {
|
|
448
|
-
|
|
505
|
+
_this3.logger.error('device: failed to delete devices:', error);
|
|
449
506
|
return _promise.default.reject(error);
|
|
450
507
|
});
|
|
451
508
|
},
|
|
452
509
|
register: function register() {
|
|
453
|
-
var
|
|
510
|
+
var _this4 = this;
|
|
454
511
|
var deviceRegistrationOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
455
512
|
this.logger.info('device: registering');
|
|
456
513
|
this.webex.internal.newMetrics.callDiagnosticMetrics.setDeviceInfo(this);
|
|
@@ -458,15 +515,17 @@ var Device = _webexCore.WebexPlugin.extend((_dec = (0, _webexCore.waitForValue)(
|
|
|
458
515
|
// Validate that the device can be registered.
|
|
459
516
|
return this.canRegister().then(function () {
|
|
460
517
|
// Validate if the device is already registered and refresh instead.
|
|
461
|
-
if (
|
|
462
|
-
|
|
463
|
-
return
|
|
518
|
+
if (_this4.registered) {
|
|
519
|
+
_this4.logger.info('device: device already registered, refreshing');
|
|
520
|
+
return _this4.refresh(deviceRegistrationOptions);
|
|
464
521
|
}
|
|
465
|
-
return
|
|
522
|
+
return _this4._registerInternal(deviceRegistrationOptions).catch(function (error) {
|
|
466
523
|
var _error$body;
|
|
467
524
|
if ((error === null || error === void 0 ? void 0 : (_error$body = error.body) === null || _error$body === void 0 ? void 0 : _error$body.message) === 'User has excessive device registrations') {
|
|
468
|
-
|
|
469
|
-
|
|
525
|
+
_this4.logger.info('device: excessive device registrations detected, initiating cleanup');
|
|
526
|
+
return _this4.deleteDevices().then(function () {
|
|
527
|
+
_this4.logger.info('device: device cleanup complete, retrying registration');
|
|
528
|
+
return _this4._registerInternal(deviceRegistrationOptions);
|
|
470
529
|
});
|
|
471
530
|
}
|
|
472
531
|
throw error;
|
|
@@ -477,7 +536,7 @@ var Device = _webexCore.WebexPlugin.extend((_dec = (0, _webexCore.waitForValue)(
|
|
|
477
536
|
return _objectSpread(_objectSpread({}, this.config.defaults.body ? this.config.defaults.body : {}), this.config.body ? this.config.body : {});
|
|
478
537
|
},
|
|
479
538
|
_registerInternal: function _registerInternal() {
|
|
480
|
-
var
|
|
539
|
+
var _this5 = this;
|
|
481
540
|
var deviceRegistrationOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
482
541
|
this.logger.info('device: making registration request');
|
|
483
542
|
|
|
@@ -510,25 +569,25 @@ var Device = _webexCore.WebexPlugin.extend((_dec = (0, _webexCore.waitForValue)(
|
|
|
510
569
|
includeUpstreamServices: "".concat(includeDetails).concat(this.config.energyForecast && this.energyForecastConfig ? ',energyforecast' : '')
|
|
511
570
|
}
|
|
512
571
|
}).catch(function (error) {
|
|
513
|
-
|
|
572
|
+
_this5.webex.internal.newMetrics.submitInternalEvent({
|
|
514
573
|
name: 'internal.register.device.response'
|
|
515
574
|
});
|
|
516
575
|
throw error;
|
|
517
576
|
}).then(function (response) {
|
|
518
577
|
// If we've signed out in the mean time, the request ID will have changed
|
|
519
|
-
if (
|
|
520
|
-
|
|
578
|
+
if (_this5.get('register-request-id') !== requestId) {
|
|
579
|
+
_this5.logger.info('device: register request ID mismatch, ignoring response');
|
|
521
580
|
return _promise.default.resolve();
|
|
522
581
|
}
|
|
523
582
|
|
|
524
583
|
// Do not add any processing of response above this as that will affect timestamp
|
|
525
|
-
|
|
584
|
+
_this5.webex.internal.newMetrics.submitInternalEvent({
|
|
526
585
|
name: 'internal.register.device.response'
|
|
527
586
|
});
|
|
528
|
-
|
|
529
|
-
return
|
|
587
|
+
_this5.webex.internal.metrics.submitClientMetrics(_metrics.default.JS_SDK_WDM_REGISTRATION_SUCCESSFUL);
|
|
588
|
+
return _this5.processRegistrationSuccess(response);
|
|
530
589
|
}).catch(function (error) {
|
|
531
|
-
|
|
590
|
+
_this5.webex.internal.metrics.submitClientMetrics(_metrics.default.JS_SDK_WDM_REGISTRATION_FAILED, {
|
|
532
591
|
fields: {
|
|
533
592
|
error: error
|
|
534
593
|
}
|
|
@@ -537,7 +596,7 @@ var Device = _webexCore.WebexPlugin.extend((_dec = (0, _webexCore.waitForValue)(
|
|
|
537
596
|
});
|
|
538
597
|
},
|
|
539
598
|
unregister: function unregister() {
|
|
540
|
-
var
|
|
599
|
+
var _this6 = this;
|
|
541
600
|
this.logger.info('device: unregistering');
|
|
542
601
|
if (!this.registered) {
|
|
543
602
|
this.logger.warn('device: not registered');
|
|
@@ -547,11 +606,11 @@ var Device = _webexCore.WebexPlugin.extend((_dec = (0, _webexCore.waitForValue)(
|
|
|
547
606
|
uri: this.url,
|
|
548
607
|
method: 'DELETE'
|
|
549
608
|
}).then(function () {
|
|
550
|
-
return
|
|
609
|
+
return _this6.clear();
|
|
551
610
|
}).catch(function (reason) {
|
|
552
611
|
if (reason.statusCode === 404) {
|
|
553
|
-
|
|
554
|
-
|
|
612
|
+
_this6.logger.info('device: 404 when deleting device, device is already deleted, clearing device');
|
|
613
|
+
_this6.clear();
|
|
555
614
|
}
|
|
556
615
|
throw reason;
|
|
557
616
|
});
|
|
@@ -585,7 +644,7 @@ var Device = _webexCore.WebexPlugin.extend((_dec = (0, _webexCore.waitForValue)(
|
|
|
585
644
|
* @returns {Promise<void, Error>}
|
|
586
645
|
*/
|
|
587
646
|
checkNetworkReachability: function checkNetworkReachability() {
|
|
588
|
-
var
|
|
647
|
+
var _this7 = this;
|
|
589
648
|
this.logger.info('device: checking network reachability');
|
|
590
649
|
|
|
591
650
|
// Validate if the device has been checked and reset the logout timer.
|
|
@@ -613,13 +672,13 @@ var Device = _webexCore.WebexPlugin.extend((_dec = (0, _webexCore.waitForValue)(
|
|
|
613
672
|
method: 'GET',
|
|
614
673
|
uri: this.intranetInactivityCheckUrl
|
|
615
674
|
}).then(function () {
|
|
616
|
-
|
|
617
|
-
return _promise.default.resolve(
|
|
675
|
+
_this7.isInNetwork = true;
|
|
676
|
+
return _promise.default.resolve(_this7.resetLogoutTimer());
|
|
618
677
|
}).catch(function () {
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
return _promise.default.resolve(
|
|
678
|
+
_this7.logger.info('device: did not reach ping endpoint');
|
|
679
|
+
_this7.logger.info('device: triggering off-network timer');
|
|
680
|
+
_this7.isInNetwork = false;
|
|
681
|
+
return _promise.default.resolve(_this7.resetLogoutTimer());
|
|
623
682
|
});
|
|
624
683
|
},
|
|
625
684
|
/**
|
|
@@ -644,7 +703,7 @@ var Device = _webexCore.WebexPlugin.extend((_dec = (0, _webexCore.waitForValue)(
|
|
|
644
703
|
* @returns {Promise<string, Error>} - The priority-mapped web socket url.
|
|
645
704
|
*/
|
|
646
705
|
getWebSocketUrl: function getWebSocketUrl() {
|
|
647
|
-
var
|
|
706
|
+
var _this8 = this;
|
|
648
707
|
var wait = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
649
708
|
this.logger.info('device: getting the current websocket url');
|
|
650
709
|
|
|
@@ -654,9 +713,9 @@ var Device = _webexCore.WebexPlugin.extend((_dec = (0, _webexCore.waitForValue)(
|
|
|
654
713
|
// Validate if the method should wait for registration.
|
|
655
714
|
if (wait) {
|
|
656
715
|
return this.waitForRegistration().then(function () {
|
|
657
|
-
return services.convertUrlToPriorityHostUrl(
|
|
716
|
+
return services.convertUrlToPriorityHostUrl(_this8.webSocketUrl);
|
|
658
717
|
}).catch(function (error) {
|
|
659
|
-
|
|
718
|
+
_this8.logger.warn(error.message);
|
|
660
719
|
return _promise.default.reject(new Error('device: failed to get the current websocket url'));
|
|
661
720
|
});
|
|
662
721
|
}
|
|
@@ -675,6 +734,33 @@ var Device = _webexCore.WebexPlugin.extend((_dec = (0, _webexCore.waitForValue)(
|
|
|
675
734
|
}
|
|
676
735
|
return _promise.default.reject(new Error('device: failed to get the current websocket url'));
|
|
677
736
|
},
|
|
737
|
+
/**
|
|
738
|
+
* Get sanitized processed debug features from session storage
|
|
739
|
+
* these should be JSON encoded and in the form {feature1: true, feature2: false}
|
|
740
|
+
*
|
|
741
|
+
* @returns {Array<Object>} - Array of sanitized debug feature toggles
|
|
742
|
+
*/
|
|
743
|
+
getDebugFeatures: function getDebugFeatures() {
|
|
744
|
+
var sanitizedDebugFeatures = [];
|
|
745
|
+
if (this.config.debugFeatureTogglesKey) {
|
|
746
|
+
var debugFeaturesString = this.webex.getWindow().sessionStorage.getItem(this.config.debugFeatureTogglesKey);
|
|
747
|
+
if (debugFeaturesString) {
|
|
748
|
+
var debugFeatures = JSON.parse(debugFeaturesString);
|
|
749
|
+
(0, _entries.default)(debugFeatures).forEach(function (_ref) {
|
|
750
|
+
var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
|
|
751
|
+
key = _ref2[0],
|
|
752
|
+
value = _ref2[1];
|
|
753
|
+
sanitizedDebugFeatures.push({
|
|
754
|
+
key: key,
|
|
755
|
+
val: value ? 'true' : 'false',
|
|
756
|
+
mutable: true,
|
|
757
|
+
lastModified: new Date().toISOString()
|
|
758
|
+
});
|
|
759
|
+
});
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
return sanitizedDebugFeatures;
|
|
763
|
+
},
|
|
678
764
|
/**
|
|
679
765
|
* Process a successful device registration.
|
|
680
766
|
*
|
|
@@ -682,7 +768,8 @@ var Device = _webexCore.WebexPlugin.extend((_dec = (0, _webexCore.waitForValue)(
|
|
|
682
768
|
* @returns {void}
|
|
683
769
|
*/
|
|
684
770
|
processRegistrationSuccess: function processRegistrationSuccess(response) {
|
|
685
|
-
var
|
|
771
|
+
var _body$features,
|
|
772
|
+
_this9 = this;
|
|
686
773
|
this.logger.info('device: received registration payload');
|
|
687
774
|
|
|
688
775
|
// Clone the response body for service cleaning.
|
|
@@ -691,8 +778,8 @@ var Device = _webexCore.WebexPlugin.extend((_dec = (0, _webexCore.waitForValue)(
|
|
|
691
778
|
// Clean service data.
|
|
692
779
|
delete body.services;
|
|
693
780
|
delete body.serviceHostMap;
|
|
694
|
-
var
|
|
695
|
-
etag =
|
|
781
|
+
var _ref3 = response.headers || {},
|
|
782
|
+
etag = _ref3.etag;
|
|
696
783
|
if (this.etag && etag && this.etag === etag) {
|
|
697
784
|
// If current etag matches the previous one and we have sent
|
|
698
785
|
// If-None-Match header the developer and entitlement feature
|
|
@@ -702,6 +789,15 @@ var Device = _webexCore.WebexPlugin.extend((_dec = (0, _webexCore.waitForValue)(
|
|
|
702
789
|
// When using the etag feature cache, user and entitlement features are still returned
|
|
703
790
|
this.features.user.reset(features.user);
|
|
704
791
|
this.features.entitlement.reset(features.entitlement);
|
|
792
|
+
} else if (this.config.debugFeatureTogglesKey && body !== null && body !== void 0 && (_body$features = body.features) !== null && _body$features !== void 0 && _body$features.developer) {
|
|
793
|
+
// Add the debug feature toggles from session storage if available
|
|
794
|
+
try {
|
|
795
|
+
var _body$features$develo;
|
|
796
|
+
var debugFeatures = this.getDebugFeatures();
|
|
797
|
+
(_body$features$develo = body.features.developer).push.apply(_body$features$develo, (0, _toConsumableArray2.default)(debugFeatures));
|
|
798
|
+
} catch (error) {
|
|
799
|
+
this.logger.error('Failed to parse debug feature toggles from session storage:', error);
|
|
800
|
+
}
|
|
705
801
|
}
|
|
706
802
|
|
|
707
803
|
// Assign the recieved DTO from **WDM** to this device.
|
|
@@ -717,7 +813,7 @@ var Device = _webexCore.WebexPlugin.extend((_dec = (0, _webexCore.waitForValue)(
|
|
|
717
813
|
this.logger.info('device: enqueuing device refresh');
|
|
718
814
|
var delay = (this.config.ephemeralDeviceTTL / 2 + 60) * 1000;
|
|
719
815
|
this.refreshTimer = (0, _commonTimers.safeSetTimeout)(function () {
|
|
720
|
-
return
|
|
816
|
+
return _this9.refresh();
|
|
721
817
|
}, delay);
|
|
722
818
|
}
|
|
723
819
|
|
|
@@ -759,7 +855,7 @@ var Device = _webexCore.WebexPlugin.extend((_dec = (0, _webexCore.waitForValue)(
|
|
|
759
855
|
* @returns {void}
|
|
760
856
|
*/
|
|
761
857
|
setLogoutTimer: function setLogoutTimer(duration) {
|
|
762
|
-
var
|
|
858
|
+
var _this0 = this;
|
|
763
859
|
this.logger.info('device: setting logout timer');
|
|
764
860
|
if (!duration || duration <= 0) {
|
|
765
861
|
return;
|
|
@@ -767,12 +863,12 @@ var Device = _webexCore.WebexPlugin.extend((_dec = (0, _webexCore.waitForValue)(
|
|
|
767
863
|
|
|
768
864
|
// Setup user activity date event listener.
|
|
769
865
|
this.on('change:lastUserActivityDate', function () {
|
|
770
|
-
|
|
866
|
+
_this0.resetLogoutTimer();
|
|
771
867
|
});
|
|
772
868
|
|
|
773
869
|
// Initialize a new timer.
|
|
774
870
|
this.logoutTimer = (0, _commonTimers.safeSetTimeout)(function () {
|
|
775
|
-
|
|
871
|
+
_this0.webex.logout();
|
|
776
872
|
}, duration * 1000);
|
|
777
873
|
},
|
|
778
874
|
/**
|
|
@@ -782,17 +878,17 @@ var Device = _webexCore.WebexPlugin.extend((_dec = (0, _webexCore.waitForValue)(
|
|
|
782
878
|
* @returns {Promise<void, Error>}
|
|
783
879
|
*/
|
|
784
880
|
waitForRegistration: function waitForRegistration() {
|
|
785
|
-
var
|
|
881
|
+
var _this1 = this;
|
|
786
882
|
var timeout = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
|
|
787
883
|
this.logger.info('device: waiting for registration');
|
|
788
884
|
return new _promise.default(function (resolve, reject) {
|
|
789
|
-
if (
|
|
885
|
+
if (_this1.registered) {
|
|
790
886
|
resolve();
|
|
791
887
|
}
|
|
792
888
|
var timeoutTimer = (0, _commonTimers.safeSetTimeout)(function () {
|
|
793
889
|
return reject(new Error('device: timeout occured while waiting for registration'));
|
|
794
890
|
}, timeout * 1000);
|
|
795
|
-
|
|
891
|
+
_this1.once(_constants.DEVICE_EVENT_REGISTRATION_SUCCESS, function () {
|
|
796
892
|
clearTimeout(timeoutTimer);
|
|
797
893
|
resolve();
|
|
798
894
|
});
|
|
@@ -802,54 +898,60 @@ var Device = _webexCore.WebexPlugin.extend((_dec = (0, _webexCore.waitForValue)(
|
|
|
802
898
|
return _promise.default.resolve(this.webex.internal.services.markFailedUrl(url));
|
|
803
899
|
},
|
|
804
900
|
initialize: function initialize() {
|
|
805
|
-
var
|
|
901
|
+
var _this10 = this;
|
|
806
902
|
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
807
903
|
args[_key2] = arguments[_key2];
|
|
808
904
|
}
|
|
809
905
|
// Prototype the extended class in order to preserve the parent member.
|
|
810
906
|
(0, _apply.default)(_webexCore.WebexPlugin.prototype.initialize, this, args);
|
|
907
|
+
this.listenToOnce(this.webex, 'change:config', function () {
|
|
908
|
+
// If debug feature toggles exist, clear the etag to ensure developer feature toggles are fetched
|
|
909
|
+
if (_this10.getDebugFeatures(_this10.config.debugFeatureTogglesKey).length > 0) {
|
|
910
|
+
_this10.set('etag', undefined);
|
|
911
|
+
}
|
|
912
|
+
});
|
|
811
913
|
|
|
812
914
|
// Initialize feature events and listeners.
|
|
813
915
|
_constants.FEATURE_COLLECTION_NAMES.forEach(function (collectionName) {
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
916
|
+
_this10.features.on("change:".concat(collectionName), function (model, value, options) {
|
|
917
|
+
_this10.trigger('change', _this10, options);
|
|
918
|
+
_this10.trigger('change:features', _this10, _this10.features, options);
|
|
817
919
|
});
|
|
818
920
|
});
|
|
819
921
|
|
|
820
922
|
// Initialize network reachability checking event for url change.
|
|
821
923
|
this.on('change:intranetInactivityCheckUrl', function () {
|
|
822
|
-
|
|
924
|
+
_this10.checkNetworkReachability();
|
|
823
925
|
});
|
|
824
926
|
|
|
825
927
|
// Initialize network reachability checking event for duration change.
|
|
826
928
|
this.on('change:intranetInactivityDuration', function () {
|
|
827
|
-
|
|
929
|
+
_this10.checkNetworkReachability();
|
|
828
930
|
});
|
|
829
931
|
|
|
830
932
|
// Initialize network reachability checking event for duration change.
|
|
831
933
|
this.on('change:inNetworkInactivityDuration', function () {
|
|
832
|
-
|
|
934
|
+
_this10.checkNetworkReachability();
|
|
833
935
|
});
|
|
834
936
|
|
|
835
937
|
// Initialize listener for activity checking.
|
|
836
938
|
this.listenTo(this.webex, 'user-activity', function () {
|
|
837
|
-
|
|
939
|
+
_this10.lastUserActivityDate = (0, _now.default)();
|
|
838
940
|
});
|
|
839
941
|
|
|
840
942
|
// Initialize listener for meeting started event.
|
|
841
943
|
this.listenTo(this.webex, 'meeting started', function () {
|
|
842
|
-
|
|
843
|
-
|
|
944
|
+
_this10.isInMeeting = true;
|
|
945
|
+
_this10.resetLogoutTimer();
|
|
844
946
|
});
|
|
845
947
|
|
|
846
948
|
// Initialize listener for meeting ended event.
|
|
847
949
|
this.listenTo(this.webex, 'meeting ended', function () {
|
|
848
|
-
|
|
849
|
-
|
|
950
|
+
_this10.isInMeeting = false;
|
|
951
|
+
_this10.resetLogoutTimer();
|
|
850
952
|
});
|
|
851
953
|
} /* eslint-enable require-jsdoc */,
|
|
852
|
-
version: "
|
|
954
|
+
version: "3.12.0-next.2"
|
|
853
955
|
}, (0, _applyDecoratedDescriptor2.default)(_obj, "refresh", [_common.oneFlight, _dec], (0, _getOwnPropertyDescriptor.default)(_obj, "refresh"), _obj), (0, _applyDecoratedDescriptor2.default)(_obj, "register", [_dec2], (0, _getOwnPropertyDescriptor.default)(_obj, "register"), _obj), (0, _applyDecoratedDescriptor2.default)(_obj, "_registerInternal", [_common.oneFlight, _dec3], (0, _getOwnPropertyDescriptor.default)(_obj, "_registerInternal"), _obj), (0, _applyDecoratedDescriptor2.default)(_obj, "unregister", [_common.oneFlight, _dec4], (0, _getOwnPropertyDescriptor.default)(_obj, "unregister"), _obj), (0, _applyDecoratedDescriptor2.default)(_obj, "markUrlFailedAndGetNew", [_dec5], (0, _getOwnPropertyDescriptor.default)(_obj, "markUrlFailedAndGetNew"), _obj), (0, _applyDecoratedDescriptor2.default)(_obj, "initialize", [_dec6], (0, _getOwnPropertyDescriptor.default)(_obj, "initialize"), _obj), _obj));
|
|
854
956
|
var _default = exports.default = Device;
|
|
855
957
|
//# sourceMappingURL=device.js.map
|