@webex/calling 3.10.0 → 3.11.0

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.
Files changed (221) hide show
  1. package/dist/module/CallHistory/CallHistory.js +20 -11
  2. package/dist/module/CallSettings/UcmBackendConnector.js +21 -8
  3. package/dist/module/CallSettings/WxCallBackendConnector.js +10 -15
  4. package/dist/module/CallingClient/CallingClient.js +83 -123
  5. package/dist/module/CallingClient/calling/call.js +73 -58
  6. package/dist/module/CallingClient/calling/callManager.js +7 -0
  7. package/dist/module/CallingClient/constants.js +3 -0
  8. package/dist/module/CallingClient/registration/register.js +85 -5
  9. package/dist/module/CallingClient/registration/webWorker.js +2 -2
  10. package/dist/module/CallingClient/registration/webWorkerStr.js +2 -2
  11. package/dist/module/Contacts/ContactsClient.js +19 -25
  12. package/dist/module/Events/impl/index.js +1 -1
  13. package/dist/module/Logger/index.js +2 -2
  14. package/dist/module/Voicemail/BroadworksBackendConnector.js +10 -18
  15. package/dist/module/Voicemail/UcmBackendConnector.js +7 -11
  16. package/dist/module/Voicemail/Voicemail.js +42 -68
  17. package/dist/module/Voicemail/WxCallBackendConnector.js +14 -28
  18. package/dist/module/common/Utils.js +31 -5
  19. package/dist/module/common/constants.js +2 -0
  20. package/dist/module/common/testUtil.js +1 -0
  21. package/dist/types/CallHistory/CallHistory.d.ts.map +1 -1
  22. package/dist/types/CallSettings/UcmBackendConnector.d.ts +1 -0
  23. package/dist/types/CallSettings/UcmBackendConnector.d.ts.map +1 -1
  24. package/dist/types/CallSettings/WxCallBackendConnector.d.ts.map +1 -1
  25. package/dist/types/CallingClient/CallingClient.d.ts.map +1 -1
  26. package/dist/types/CallingClient/calling/call.d.ts +4 -0
  27. package/dist/types/CallingClient/calling/call.d.ts.map +1 -1
  28. package/dist/types/CallingClient/calling/callManager.d.ts.map +1 -1
  29. package/dist/types/CallingClient/constants.d.ts +3 -0
  30. package/dist/types/CallingClient/constants.d.ts.map +1 -1
  31. package/dist/types/CallingClient/registration/register.d.ts +4 -0
  32. package/dist/types/CallingClient/registration/register.d.ts.map +1 -1
  33. package/dist/types/CallingClient/registration/types.d.ts +6 -0
  34. package/dist/types/CallingClient/registration/types.d.ts.map +1 -1
  35. package/dist/types/CallingClient/registration/webWorkerStr.d.ts +1 -1
  36. package/dist/types/CallingClient/registration/webWorkerStr.d.ts.map +1 -1
  37. package/dist/types/Contacts/ContactsClient.d.ts +1 -0
  38. package/dist/types/Contacts/ContactsClient.d.ts.map +1 -1
  39. package/dist/types/Logger/index.d.ts +1 -2
  40. package/dist/types/Logger/index.d.ts.map +1 -1
  41. package/dist/types/SDKConnector/types.d.ts +16 -0
  42. package/dist/types/SDKConnector/types.d.ts.map +1 -1
  43. package/dist/types/Voicemail/BroadworksBackendConnector.d.ts.map +1 -1
  44. package/dist/types/Voicemail/UcmBackendConnector.d.ts.map +1 -1
  45. package/dist/types/Voicemail/Voicemail.d.ts.map +1 -1
  46. package/dist/types/Voicemail/WxCallBackendConnector.d.ts.map +1 -1
  47. package/dist/types/common/Utils.d.ts +1 -1
  48. package/dist/types/common/Utils.d.ts.map +1 -1
  49. package/dist/types/common/constants.d.ts +2 -0
  50. package/dist/types/common/constants.d.ts.map +1 -1
  51. package/dist/types/common/testUtil.d.ts +1 -0
  52. package/dist/types/common/testUtil.d.ts.map +1 -1
  53. package/package.json +4 -4
  54. package/dist/CallHistory/CallHistory.js +0 -584
  55. package/dist/CallHistory/CallHistory.js.map +0 -1
  56. package/dist/CallHistory/CallHistory.test.js +0 -813
  57. package/dist/CallHistory/CallHistory.test.js.map +0 -1
  58. package/dist/CallHistory/callHistoryFixtures.js +0 -650
  59. package/dist/CallHistory/callHistoryFixtures.js.map +0 -1
  60. package/dist/CallHistory/constants.js +0 -38
  61. package/dist/CallHistory/constants.js.map +0 -1
  62. package/dist/CallHistory/types.js +0 -7
  63. package/dist/CallHistory/types.js.map +0 -1
  64. package/dist/CallSettings/CallSettings.js +0 -312
  65. package/dist/CallSettings/CallSettings.js.map +0 -1
  66. package/dist/CallSettings/CallSettings.test.js +0 -122
  67. package/dist/CallSettings/CallSettings.test.js.map +0 -1
  68. package/dist/CallSettings/UcmBackendConnector.js +0 -261
  69. package/dist/CallSettings/UcmBackendConnector.js.map +0 -1
  70. package/dist/CallSettings/UcmBackendConnector.test.js +0 -321
  71. package/dist/CallSettings/UcmBackendConnector.test.js.map +0 -1
  72. package/dist/CallSettings/WxCallBackendConnector.js +0 -604
  73. package/dist/CallSettings/WxCallBackendConnector.js.map +0 -1
  74. package/dist/CallSettings/WxCallBackendConnector.test.js +0 -905
  75. package/dist/CallSettings/WxCallBackendConnector.test.js.map +0 -1
  76. package/dist/CallSettings/constants.js +0 -31
  77. package/dist/CallSettings/constants.js.map +0 -1
  78. package/dist/CallSettings/testFixtures.js +0 -68
  79. package/dist/CallSettings/testFixtures.js.map +0 -1
  80. package/dist/CallSettings/types.js +0 -7
  81. package/dist/CallSettings/types.js.map +0 -1
  82. package/dist/CallingClient/CallingClient.js +0 -1071
  83. package/dist/CallingClient/CallingClient.js.map +0 -1
  84. package/dist/CallingClient/CallingClient.test.js +0 -1289
  85. package/dist/CallingClient/CallingClient.test.js.map +0 -1
  86. package/dist/CallingClient/callRecordFixtures.js +0 -101
  87. package/dist/CallingClient/callRecordFixtures.js.map +0 -1
  88. package/dist/CallingClient/calling/CallerId/index.js +0 -276
  89. package/dist/CallingClient/calling/CallerId/index.js.map +0 -1
  90. package/dist/CallingClient/calling/CallerId/index.test.js +0 -275
  91. package/dist/CallingClient/calling/CallerId/index.test.js.map +0 -1
  92. package/dist/CallingClient/calling/CallerId/types.js +0 -7
  93. package/dist/CallingClient/calling/CallerId/types.js.map +0 -1
  94. package/dist/CallingClient/calling/call.js +0 -3444
  95. package/dist/CallingClient/calling/call.js.map +0 -1
  96. package/dist/CallingClient/calling/call.test.js +0 -3260
  97. package/dist/CallingClient/calling/call.test.js.map +0 -1
  98. package/dist/CallingClient/calling/callManager.js +0 -456
  99. package/dist/CallingClient/calling/callManager.js.map +0 -1
  100. package/dist/CallingClient/calling/callManager.test.js +0 -741
  101. package/dist/CallingClient/calling/callManager.test.js.map +0 -1
  102. package/dist/CallingClient/calling/index.js +0 -30
  103. package/dist/CallingClient/calling/index.js.map +0 -1
  104. package/dist/CallingClient/calling/types.js +0 -74
  105. package/dist/CallingClient/calling/types.js.map +0 -1
  106. package/dist/CallingClient/callingClientFixtures.js +0 -143
  107. package/dist/CallingClient/callingClientFixtures.js.map +0 -1
  108. package/dist/CallingClient/constants.js +0 -237
  109. package/dist/CallingClient/constants.js.map +0 -1
  110. package/dist/CallingClient/line/index.js +0 -349
  111. package/dist/CallingClient/line/index.js.map +0 -1
  112. package/dist/CallingClient/line/line.test.js +0 -327
  113. package/dist/CallingClient/line/line.test.js.map +0 -1
  114. package/dist/CallingClient/line/types.js +0 -21
  115. package/dist/CallingClient/line/types.js.map +0 -1
  116. package/dist/CallingClient/registration/index.js +0 -19
  117. package/dist/CallingClient/registration/index.js.map +0 -1
  118. package/dist/CallingClient/registration/register.js +0 -1538
  119. package/dist/CallingClient/registration/register.js.map +0 -1
  120. package/dist/CallingClient/registration/register.test.js +0 -1537
  121. package/dist/CallingClient/registration/register.test.js.map +0 -1
  122. package/dist/CallingClient/registration/registerFixtures.js +0 -36
  123. package/dist/CallingClient/registration/registerFixtures.js.map +0 -1
  124. package/dist/CallingClient/registration/types.js +0 -7
  125. package/dist/CallingClient/registration/types.js.map +0 -1
  126. package/dist/CallingClient/registration/webWorker.js +0 -130
  127. package/dist/CallingClient/registration/webWorker.js.map +0 -1
  128. package/dist/CallingClient/registration/webWorker.test.js +0 -303
  129. package/dist/CallingClient/registration/webWorker.test.js.map +0 -1
  130. package/dist/CallingClient/registration/webWorkerStr.js +0 -15
  131. package/dist/CallingClient/registration/webWorkerStr.js.map +0 -1
  132. package/dist/CallingClient/types.js +0 -7
  133. package/dist/CallingClient/types.js.map +0 -1
  134. package/dist/CallingClient/windowsChromiumIceWarmupUtils.js +0 -142
  135. package/dist/CallingClient/windowsChromiumIceWarmupUtils.js.map +0 -1
  136. package/dist/Contacts/ContactsClient.js +0 -1215
  137. package/dist/Contacts/ContactsClient.js.map +0 -1
  138. package/dist/Contacts/ContactsClient.test.js +0 -1003
  139. package/dist/Contacts/ContactsClient.test.js.map +0 -1
  140. package/dist/Contacts/constants.js +0 -40
  141. package/dist/Contacts/constants.js.map +0 -1
  142. package/dist/Contacts/contactFixtures.js +0 -430
  143. package/dist/Contacts/contactFixtures.js.map +0 -1
  144. package/dist/Contacts/types.js +0 -43
  145. package/dist/Contacts/types.js.map +0 -1
  146. package/dist/Errors/catalog/CallError.js +0 -92
  147. package/dist/Errors/catalog/CallError.js.map +0 -1
  148. package/dist/Errors/catalog/CallingDeviceError.js +0 -86
  149. package/dist/Errors/catalog/CallingDeviceError.js.map +0 -1
  150. package/dist/Errors/catalog/ExtendedError.js +0 -44
  151. package/dist/Errors/catalog/ExtendedError.js.map +0 -1
  152. package/dist/Errors/catalog/LineError.js +0 -88
  153. package/dist/Errors/catalog/LineError.js.map +0 -1
  154. package/dist/Errors/index.js +0 -28
  155. package/dist/Errors/index.js.map +0 -1
  156. package/dist/Errors/types.js +0 -59
  157. package/dist/Errors/types.js.map +0 -1
  158. package/dist/Events/impl/index.js +0 -81
  159. package/dist/Events/impl/index.js.map +0 -1
  160. package/dist/Events/types.js +0 -107
  161. package/dist/Events/types.js.map +0 -1
  162. package/dist/Logger/index.js +0 -228
  163. package/dist/Logger/index.js.map +0 -1
  164. package/dist/Logger/index.test.js +0 -87
  165. package/dist/Logger/index.test.js.map +0 -1
  166. package/dist/Logger/types.js +0 -34
  167. package/dist/Logger/types.js.map +0 -1
  168. package/dist/Metrics/index.js +0 -535
  169. package/dist/Metrics/index.js.map +0 -1
  170. package/dist/Metrics/index.test.js +0 -463
  171. package/dist/Metrics/index.test.js.map +0 -1
  172. package/dist/Metrics/types.js +0 -64
  173. package/dist/Metrics/types.js.map +0 -1
  174. package/dist/SDKConnector/index.js +0 -103
  175. package/dist/SDKConnector/index.js.map +0 -1
  176. package/dist/SDKConnector/index.test.js +0 -9
  177. package/dist/SDKConnector/index.test.js.map +0 -1
  178. package/dist/SDKConnector/types.js +0 -7
  179. package/dist/SDKConnector/types.js.map +0 -1
  180. package/dist/SDKConnector/utils.js +0 -39
  181. package/dist/SDKConnector/utils.js.map +0 -1
  182. package/dist/SDKConnector/utils.test.js +0 -9
  183. package/dist/SDKConnector/utils.test.js.map +0 -1
  184. package/dist/Voicemail/BroadworksBackendConnector.js +0 -707
  185. package/dist/Voicemail/BroadworksBackendConnector.js.map +0 -1
  186. package/dist/Voicemail/BroadworksBackendConnector.test.js +0 -812
  187. package/dist/Voicemail/BroadworksBackendConnector.test.js.map +0 -1
  188. package/dist/Voicemail/UcmBackendConnector.js +0 -632
  189. package/dist/Voicemail/UcmBackendConnector.js.map +0 -1
  190. package/dist/Voicemail/UcmBackendConnector.test.js +0 -738
  191. package/dist/Voicemail/UcmBackendConnector.test.js.map +0 -1
  192. package/dist/Voicemail/Voicemail.js +0 -500
  193. package/dist/Voicemail/Voicemail.js.map +0 -1
  194. package/dist/Voicemail/Voicemail.test.js +0 -391
  195. package/dist/Voicemail/Voicemail.test.js.map +0 -1
  196. package/dist/Voicemail/WxCallBackendConnector.js +0 -671
  197. package/dist/Voicemail/WxCallBackendConnector.js.map +0 -1
  198. package/dist/Voicemail/WxCallBackendConnector.test.js +0 -1199
  199. package/dist/Voicemail/WxCallBackendConnector.test.js.map +0 -1
  200. package/dist/Voicemail/constants.js +0 -61
  201. package/dist/Voicemail/constants.js.map +0 -1
  202. package/dist/Voicemail/types.js +0 -7
  203. package/dist/Voicemail/types.js.map +0 -1
  204. package/dist/Voicemail/voicemailFixture.js +0 -524
  205. package/dist/Voicemail/voicemailFixture.js.map +0 -1
  206. package/dist/api.js +0 -157
  207. package/dist/api.js.map +0 -1
  208. package/dist/common/Utils.js +0 -1451
  209. package/dist/common/Utils.js.map +0 -1
  210. package/dist/common/Utils.test.js +0 -1744
  211. package/dist/common/Utils.test.js.map +0 -1
  212. package/dist/common/constants.js +0 -60
  213. package/dist/common/constants.js.map +0 -1
  214. package/dist/common/index.js +0 -19
  215. package/dist/common/index.js.map +0 -1
  216. package/dist/common/testUtil.js +0 -982
  217. package/dist/common/testUtil.js.map +0 -1
  218. package/dist/common/types.js +0 -75
  219. package/dist/common/types.js.map +0 -1
  220. package/dist/index.js +0 -321
  221. package/dist/index.js.map +0 -1
@@ -1,1538 +0,0 @@
1
- "use strict";
2
-
3
- var _Object$keys2 = require("@babel/runtime-corejs2/core-js/object/keys");
4
- var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs2/core-js/object/get-own-property-symbols");
5
- var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptor");
6
- var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptors");
7
- var _Object$defineProperties = require("@babel/runtime-corejs2/core-js/object/define-properties");
8
- var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
9
- var _Array$from = require("@babel/runtime-corejs2/core-js/array/from");
10
- var _Symbol = require("@babel/runtime-corejs2/core-js/symbol");
11
- var _Symbol$iterator = require("@babel/runtime-corejs2/core-js/symbol/iterator");
12
- var _Array$isArray = require("@babel/runtime-corejs2/core-js/array/is-array");
13
- var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
14
- _Object$defineProperty(exports, "__esModule", {
15
- value: true
16
- });
17
- exports.createRegistration = exports.Registration = void 0;
18
- var _now = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/date/now"));
19
- var _keys = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/keys"));
20
- var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs2/regenerator"));
21
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/asyncToGenerator"));
22
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/classCallCheck"));
23
- var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/createClass"));
24
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
25
- var _uuid = require("uuid");
26
- var _constants = require("../../common/constants");
27
- var _common = require("../../common");
28
- var _webWorkerStr = _interopRequireDefault(require("./webWorkerStr"));
29
- var _types = require("../../Metrics/types");
30
- var _Metrics = require("../../Metrics");
31
- var _calling = require("../calling");
32
- var _Logger = _interopRequireDefault(require("../../Logger"));
33
- var _SDKConnector = _interopRequireDefault(require("../../SDKConnector"));
34
- var _types2 = require("../../common/types");
35
- var _constants2 = require("../constants");
36
- var _types3 = require("../line/types");
37
- function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof _Symbol && r[_Symbol$iterator] || r["@@iterator"]; if (!t) { if (_Array$isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
38
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? _Array$from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
39
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
40
- function ownKeys(e, r) { var t = _Object$keys2(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
41
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
42
- /**
43
- *
44
- */
45
- var Registration = exports.Registration = /*#__PURE__*/function () {
46
- /**
47
- */
48
- function Registration(webex, serviceData, mutex, lineEmitter, logLevel, jwe) {
49
- (0, _classCallCheck2.default)(this, Registration);
50
- (0, _defineProperty2.default)(this, "sdkConnector", void 0);
51
- (0, _defineProperty2.default)(this, "webex", void 0);
52
- (0, _defineProperty2.default)(this, "userId", '');
53
- (0, _defineProperty2.default)(this, "serviceData", void 0);
54
- (0, _defineProperty2.default)(this, "failback429RetryAttempts", void 0);
55
- (0, _defineProperty2.default)(this, "registrationStatus", void 0);
56
- (0, _defineProperty2.default)(this, "failbackTimer", void 0);
57
- (0, _defineProperty2.default)(this, "activeMobiusUrl", void 0);
58
- (0, _defineProperty2.default)(this, "rehomingIntervalMin", void 0);
59
- (0, _defineProperty2.default)(this, "rehomingIntervalMax", void 0);
60
- (0, _defineProperty2.default)(this, "mutex", void 0);
61
- (0, _defineProperty2.default)(this, "metricManager", void 0);
62
- (0, _defineProperty2.default)(this, "lineEmitter", void 0);
63
- (0, _defineProperty2.default)(this, "callManager", void 0);
64
- (0, _defineProperty2.default)(this, "deviceInfo", {});
65
- (0, _defineProperty2.default)(this, "primaryMobiusUris", void 0);
66
- (0, _defineProperty2.default)(this, "backupMobiusUris", void 0);
67
- (0, _defineProperty2.default)(this, "registerRetry", false);
68
- (0, _defineProperty2.default)(this, "reconnectPending", false);
69
- (0, _defineProperty2.default)(this, "jwe", void 0);
70
- (0, _defineProperty2.default)(this, "isCCFlow", false);
71
- (0, _defineProperty2.default)(this, "failoverImmediately", false);
72
- (0, _defineProperty2.default)(this, "retryAfter", void 0);
73
- (0, _defineProperty2.default)(this, "scheduled429Retry", false);
74
- (0, _defineProperty2.default)(this, "webWorker", void 0);
75
- this.jwe = jwe;
76
- this.sdkConnector = _SDKConnector.default;
77
- this.serviceData = serviceData;
78
- this.isCCFlow = serviceData.indicator === _types2.ServiceIndicator.CONTACT_CENTER;
79
- if (!this.sdkConnector.getWebex()) {
80
- _SDKConnector.default.setWebex(webex);
81
- }
82
- this.webex = this.sdkConnector.getWebex();
83
- this.userId = this.webex.internal.device.userId;
84
- this.registrationStatus = _types2.RegistrationStatus.IDLE;
85
- this.failback429RetryAttempts = 0;
86
- _Logger.default.setLogger(logLevel, _constants2.REGISTRATION_FILE);
87
- this.rehomingIntervalMin = _constants2.DEFAULT_REHOMING_INTERVAL_MIN;
88
- this.rehomingIntervalMax = _constants2.DEFAULT_REHOMING_INTERVAL_MAX;
89
- this.mutex = mutex;
90
- this.callManager = (0, _calling.getCallManager)(this.webex, serviceData.indicator);
91
- this.metricManager = (0, _Metrics.getMetricManager)(this.webex, serviceData.indicator);
92
- this.lineEmitter = lineEmitter;
93
- this.primaryMobiusUris = [];
94
- this.backupMobiusUris = [];
95
- }
96
- (0, _createClass2.default)(Registration, [{
97
- key: "getActiveMobiusUrl",
98
- value: function getActiveMobiusUrl() {
99
- return this.activeMobiusUrl;
100
- }
101
- }, {
102
- key: "setActiveMobiusUrl",
103
- value: function setActiveMobiusUrl(url) {
104
- _Logger.default.info("".concat(_constants.METHOD_START_MESSAGE, " with ").concat(url), {
105
- method: _constants2.METHODS.UPDATE_ACTIVE_MOBIUS,
106
- file: _constants2.REGISTRATION_FILE
107
- });
108
- this.activeMobiusUrl = url;
109
- this.callManager.updateActiveMobius(url);
110
- }
111
- }, {
112
- key: "setMobiusServers",
113
- value: function setMobiusServers(primaryMobiusUris, backupMobiusUris) {
114
- _Logger.default.log(_constants.METHOD_START_MESSAGE, {
115
- method: _constants2.METHODS.SET_MOBIUS_SERVERS,
116
- file: _constants2.REGISTRATION_FILE
117
- });
118
- this.primaryMobiusUris = primaryMobiusUris;
119
- this.backupMobiusUris = backupMobiusUris;
120
- }
121
-
122
- /**
123
- * Implementation of delete device.
124
- *
125
- */
126
- }, {
127
- key: "deleteRegistration",
128
- value: (function () {
129
- var _deleteRegistration = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee(url, deviceId, deviceUrl) {
130
- var _response;
131
- var response;
132
- return _regenerator.default.wrap(function _callee$(_context) {
133
- while (1) switch (_context.prev = _context.next) {
134
- case 0:
135
- _context.prev = 0;
136
- _context.t0 = fetch;
137
- _context.t1 = "".concat(url).concat(_constants2.DEVICES_ENDPOINT_RESOURCE, "/").concat(deviceId);
138
- _context.t2 = _types2.HTTP_METHODS.DELETE;
139
- _context.t3 = _defineProperty2.default;
140
- _context.t4 = _defineProperty2.default;
141
- _context.t5 = _defineProperty2.default;
142
- _context.t6 = (0, _defineProperty2.default)({}, _constants2.CISCO_DEVICE_URL, deviceUrl);
143
- _context.next = 10;
144
- return this.webex.credentials.getUserToken();
145
- case 10:
146
- _context.t7 = _context.sent;
147
- _context.t8 = (0, _context.t5)(_context.t6, "Authorization", _context.t7);
148
- _context.t9 = "".concat(_constants2.WEBEX_WEB_CLIENT, "_").concat((0, _uuid.v4)());
149
- _context.t10 = (0, _context.t4)(_context.t8, "trackingId", _context.t9);
150
- _context.t11 = _constants2.SPARK_USER_AGENT;
151
- _context.t12 = _constants2.CALLING_USER_AGENT;
152
- _context.t13 = (0, _context.t3)(_context.t10, _context.t11, _context.t12);
153
- _context.t14 = {
154
- method: _context.t2,
155
- headers: _context.t13
156
- };
157
- _context.next = 20;
158
- return (0, _context.t0)(_context.t1, _context.t14);
159
- case 20:
160
- response = _context.sent;
161
- _context.next = 28;
162
- break;
163
- case 23:
164
- _context.prev = 23;
165
- _context.t15 = _context["catch"](0);
166
- _Logger.default.warn("Delete failed with Mobius ".concat(_context.t15), {
167
- file: _constants2.REGISTRATION_FILE,
168
- method: _constants2.METHODS.DELETE_REGISTRATION
169
- });
170
- _context.next = 28;
171
- return (0, _common.uploadLogs)();
172
- case 28:
173
- this.setStatus(_types2.RegistrationStatus.INACTIVE);
174
- this.lineEmitter(_types3.LINE_EVENTS.UNREGISTERED);
175
- return _context.abrupt("return", (_response = response) === null || _response === void 0 ? void 0 : _response.json());
176
- case 31:
177
- case "end":
178
- return _context.stop();
179
- }
180
- }, _callee, this, [[0, 23]]);
181
- }));
182
- function deleteRegistration(_x, _x2, _x3) {
183
- return _deleteRegistration.apply(this, arguments);
184
- }
185
- return deleteRegistration;
186
- }()
187
- /**
188
- * Implementation of POST request for device registration.
189
- *
190
- */
191
- )
192
- }, {
193
- key: "postRegistration",
194
- value: (function () {
195
- var _postRegistration = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee2(url) {
196
- var deviceInfo;
197
- return _regenerator.default.wrap(function _callee2$(_context2) {
198
- while (1) switch (_context2.prev = _context2.next) {
199
- case 0:
200
- deviceInfo = {
201
- userId: this.userId,
202
- clientDeviceUri: this.webex.internal.device.url,
203
- serviceData: this.jwe ? _objectSpread(_objectSpread({}, this.serviceData), {}, {
204
- jwe: this.jwe
205
- }) : this.serviceData
206
- };
207
- return _context2.abrupt("return", this.webex.request({
208
- uri: "".concat(url, "device"),
209
- method: _types2.HTTP_METHODS.POST,
210
- headers: (0, _defineProperty2.default)((0, _defineProperty2.default)({}, _constants2.CISCO_DEVICE_URL, deviceInfo.clientDeviceUri), _constants2.SPARK_USER_AGENT, _constants2.CALLING_USER_AGENT),
211
- body: deviceInfo,
212
- service: _types2.ALLOWED_SERVICES.MOBIUS
213
- }));
214
- case 2:
215
- case "end":
216
- return _context2.stop();
217
- }
218
- }, _callee2, this);
219
- }));
220
- function postRegistration(_x4) {
221
- return _postRegistration.apply(this, arguments);
222
- }
223
- return postRegistration;
224
- }()
225
- /**
226
- * Re-attempts registration with the mobius url it was last registered
227
- * to, that mobius url is expected to be updated already in this.activeMobiusUrl.
228
- */
229
- )
230
- }, {
231
- key: "restorePreviousRegistration",
232
- value: (function () {
233
- var _restorePreviousRegistration = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee3(caller) {
234
- var abort;
235
- return _regenerator.default.wrap(function _callee3$(_context3) {
236
- while (1) switch (_context3.prev = _context3.next) {
237
- case 0:
238
- abort = false;
239
- if (!this.activeMobiusUrl) {
240
- _context3.next = 5;
241
- break;
242
- }
243
- _context3.next = 4;
244
- return this.attemptRegistrationWithServers(caller, [this.activeMobiusUrl]);
245
- case 4:
246
- abort = _context3.sent;
247
- case 5:
248
- return _context3.abrupt("return", abort);
249
- case 6:
250
- case "end":
251
- return _context3.stop();
252
- }
253
- }, _callee3, this);
254
- }));
255
- function restorePreviousRegistration(_x5) {
256
- return _restorePreviousRegistration.apply(this, arguments);
257
- }
258
- return restorePreviousRegistration;
259
- }()
260
- /**
261
- * Callback for handling 404 response from the server for register keepalive
262
- */
263
- )
264
- }, {
265
- key: "handle404KeepaliveFailure",
266
- value: (function () {
267
- var _handle404KeepaliveFailure = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee4(caller) {
268
- var abort;
269
- return _regenerator.default.wrap(function _callee4$(_context4) {
270
- while (1) switch (_context4.prev = _context4.next) {
271
- case 0:
272
- if (!(caller === _constants2.KEEPALIVE_UTIL)) {
273
- _context4.next = 7;
274
- break;
275
- }
276
- _context4.next = 3;
277
- return this.attemptRegistrationWithServers(caller);
278
- case 3:
279
- abort = _context4.sent;
280
- if (!(!abort && !this.isDeviceRegistered())) {
281
- _context4.next = 7;
282
- break;
283
- }
284
- _context4.next = 7;
285
- return this.startFailoverTimer();
286
- case 7:
287
- case "end":
288
- return _context4.stop();
289
- }
290
- }, _callee4, this);
291
- }));
292
- function handle404KeepaliveFailure(_x6) {
293
- return _handle404KeepaliveFailure.apply(this, arguments);
294
- }
295
- return handle404KeepaliveFailure;
296
- }()
297
- /**
298
- * Callback for handling 429 retry response from the server
299
- */
300
- )
301
- }, {
302
- key: "handle429Retry",
303
- value: (function () {
304
- var _handle429Retry = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee6(retryAfter, caller) {
305
- var _this = this;
306
- var interval, abort;
307
- return _regenerator.default.wrap(function _callee6$(_context6) {
308
- while (1) switch (_context6.prev = _context6.next) {
309
- case 0:
310
- if (!(caller === _constants2.FAILBACK_UTIL)) {
311
- _context6.next = 17;
312
- break;
313
- }
314
- if (!(this.failback429RetryAttempts >= _constants2.REG_FAILBACK_429_MAX_RETRIES)) {
315
- _context6.next = 3;
316
- break;
317
- }
318
- return _context6.abrupt("return");
319
- case 3:
320
- this.clearFailbackTimer();
321
- this.failback429RetryAttempts += 1;
322
- _Logger.default.log("Received 429 while rehoming, 429 retry count : ".concat(this.failback429RetryAttempts), {
323
- file: _constants2.REGISTRATION_FILE,
324
- method: _constants2.REG_429_RETRY_UTIL
325
- });
326
- interval = this.getRegRetryInterval(this.failback429RetryAttempts);
327
- this.startFailbackTimer(interval);
328
- this.scheduled429Retry = true;
329
- _context6.next = 11;
330
- return this.restorePreviousRegistration(_constants2.REG_429_RETRY_UTIL);
331
- case 11:
332
- abort = _context6.sent;
333
- if (!(!abort && !this.isDeviceRegistered())) {
334
- _context6.next = 15;
335
- break;
336
- }
337
- _context6.next = 15;
338
- return this.restartRegistration(_constants2.REG_429_RETRY_UTIL);
339
- case 15:
340
- _context6.next = 18;
341
- break;
342
- case 17:
343
- if (caller === _constants2.KEEPALIVE_UTIL) {
344
- this.clearKeepaliveTimer();
345
- setTimeout(/*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee5() {
346
- var _this$deviceInfo$devi;
347
- return _regenerator.default.wrap(function _callee5$(_context5) {
348
- while (1) switch (_context5.prev = _context5.next) {
349
- case 0:
350
- _Logger.default.log("Resuming keepalive after ".concat(retryAfter, " seconds"), {
351
- file: _constants2.REGISTRATION_FILE,
352
- method: _constants2.REG_429_RETRY_UTIL
353
- });
354
-
355
- // Resume the keepalive after waiting for the retry after period
356
- _context5.next = 3;
357
- return _this.startKeepaliveTimer((_this$deviceInfo$devi = _this.deviceInfo.device) === null || _this$deviceInfo$devi === void 0 ? void 0 : _this$deviceInfo$devi.uri, _this.deviceInfo.keepaliveInterval, 'UNKNOWN');
358
- case 3:
359
- case "end":
360
- return _context5.stop();
361
- }
362
- }, _callee5);
363
- })), retryAfter * 1000);
364
- } else {
365
- this.retryAfter = retryAfter;
366
- }
367
- case 18:
368
- case "end":
369
- return _context6.stop();
370
- }
371
- }, _callee6, this);
372
- }));
373
- function handle429Retry(_x7, _x8) {
374
- return _handle429Retry.apply(this, arguments);
375
- }
376
- return handle429Retry;
377
- }()
378
- /**
379
- * Calculates and returns a random interval value using input argument
380
- * attempt as the variable factor.
381
- *
382
- * attempted already.
383
- */
384
- )
385
- }, {
386
- key: "getRegRetryInterval",
387
- value: function getRegRetryInterval() {
388
- var attempt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
389
- return _constants2.BASE_REG_RETRY_TIMER_VAL_IN_SEC + Math.pow(_constants2.BASE_REG_TIMER_MFACTOR, attempt) + Math.floor((Math.random() * (_constants2.REG_RANDOM_T_FACTOR_UPPER_LIMIT - _constants2.SEC_TO_MSEC_MFACTOR + 1) + _constants2.SEC_TO_MSEC_MFACTOR) / _constants2.SEC_TO_MSEC_MFACTOR);
390
- }
391
-
392
- /**
393
- * Schedules registration retry with primary mobius servers at a random
394
- * interval calculated based on the number of times registration retry is already done
395
- * Once the time taken since the beginning of retry attempt exceeds the
396
- * retry threshold, it switches over to backup mobius servers.
397
- *
398
- */
399
- }, {
400
- key: "startFailoverTimer",
401
- value: (function () {
402
- var _startFailoverTimer = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee1() {
403
- var _this2 = this;
404
- var attempt,
405
- timeElapsed,
406
- loggerContext,
407
- interval,
408
- TIMER_THRESHOLD,
409
- excessVal,
410
- abort,
411
- scheduledTime,
412
- _args1 = arguments;
413
- return _regenerator.default.wrap(function _callee1$(_context1) {
414
- while (1) switch (_context1.prev = _context1.next) {
415
- case 0:
416
- attempt = _args1.length > 0 && _args1[0] !== undefined ? _args1[0] : 1;
417
- timeElapsed = _args1.length > 1 && _args1[1] !== undefined ? _args1[1] : 0;
418
- loggerContext = {
419
- file: _constants2.REGISTRATION_FILE,
420
- method: _constants2.FAILOVER_UTIL
421
- };
422
- interval = this.getRegRetryInterval(attempt);
423
- TIMER_THRESHOLD = _constants2.REG_TRY_BACKUP_TIMER_VAL_IN_SEC;
424
- if (timeElapsed + interval > TIMER_THRESHOLD) {
425
- excessVal = timeElapsed + interval - TIMER_THRESHOLD;
426
- interval -= excessVal;
427
- }
428
- if (this.retryAfter != null && interval < this.retryAfter) {
429
- this.failoverImmediately = this.retryAfter + timeElapsed > TIMER_THRESHOLD;
430
- }
431
- if (!(interval > _constants2.BASE_REG_RETRY_TIMER_VAL_IN_SEC && !this.failoverImmediately)) {
432
- _context1.next = 14;
433
- break;
434
- }
435
- scheduledTime = Math.floor((0, _now.default)() / 1000);
436
- if (this.retryAfter != null) {
437
- interval = Math.max(interval, this.retryAfter);
438
- }
439
- setTimeout(/*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee8() {
440
- return _regenerator.default.wrap(function _callee8$(_context8) {
441
- while (1) switch (_context8.prev = _context8.next) {
442
- case 0:
443
- _context8.next = 2;
444
- return _this2.mutex.runExclusive(/*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee7() {
445
- var currentTime;
446
- return _regenerator.default.wrap(function _callee7$(_context7) {
447
- while (1) switch (_context7.prev = _context7.next) {
448
- case 0:
449
- _context7.next = 2;
450
- return _this2.attemptRegistrationWithServers(_constants2.FAILOVER_UTIL);
451
- case 2:
452
- abort = _context7.sent;
453
- currentTime = Math.floor((0, _now.default)() / 1000);
454
- if (!(!abort && !_this2.isDeviceRegistered())) {
455
- _context7.next = 7;
456
- break;
457
- }
458
- _context7.next = 7;
459
- return _this2.startFailoverTimer(attempt + 1, timeElapsed + (currentTime - scheduledTime));
460
- case 7:
461
- case "end":
462
- return _context7.stop();
463
- }
464
- }, _callee7);
465
- })));
466
- case 2:
467
- case "end":
468
- return _context8.stop();
469
- }
470
- }, _callee8);
471
- })), interval * _constants2.SEC_TO_MSEC_MFACTOR);
472
- _Logger.default.log("Scheduled retry with primary in ".concat(interval, " seconds, number of attempts : ").concat(attempt), loggerContext);
473
- _context1.next = 26;
474
- break;
475
- case 14:
476
- if (!this.backupMobiusUris.length) {
477
- _context1.next = 23;
478
- break;
479
- }
480
- _Logger.default.info('Failing over to backup servers.', loggerContext);
481
- this.failoverImmediately = false;
482
- _context1.next = 19;
483
- return this.attemptRegistrationWithServers(_constants2.FAILOVER_UTIL, this.backupMobiusUris);
484
- case 19:
485
- abort = _context1.sent;
486
- if (!abort && !this.isDeviceRegistered()) {
487
- interval = this.getRegRetryInterval();
488
- if (this.retryAfter != null && this.retryAfter < _constants2.RETRY_TIMER_UPPER_LIMIT) {
489
- interval = interval < this.retryAfter ? this.retryAfter : interval;
490
- }
491
- setTimeout(/*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee0() {
492
- return _regenerator.default.wrap(function _callee0$(_context0) {
493
- while (1) switch (_context0.prev = _context0.next) {
494
- case 0:
495
- _context0.next = 2;
496
- return _this2.mutex.runExclusive(/*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee9() {
497
- return _regenerator.default.wrap(function _callee9$(_context9) {
498
- while (1) switch (_context9.prev = _context9.next) {
499
- case 0:
500
- _context9.next = 2;
501
- return _this2.attemptRegistrationWithServers(_constants2.FAILOVER_UTIL, _this2.backupMobiusUris);
502
- case 2:
503
- abort = _context9.sent;
504
- if (!(!abort && !_this2.isDeviceRegistered())) {
505
- _context9.next = 7;
506
- break;
507
- }
508
- _context9.next = 6;
509
- return (0, _common.uploadLogs)();
510
- case 6:
511
- (0, _common.emitFinalFailure)(function (clientError) {
512
- _this2.lineEmitter(_types3.LINE_EVENTS.ERROR, undefined, clientError);
513
- }, loggerContext);
514
- case 7:
515
- case "end":
516
- return _context9.stop();
517
- }
518
- }, _callee9);
519
- })));
520
- case 2:
521
- case "end":
522
- return _context0.stop();
523
- }
524
- }, _callee0);
525
- })), interval * _constants2.SEC_TO_MSEC_MFACTOR);
526
- _Logger.default.log("Scheduled retry with backup servers in ".concat(interval, " seconds."), loggerContext);
527
- }
528
- _context1.next = 26;
529
- break;
530
- case 23:
531
- _context1.next = 25;
532
- return (0, _common.uploadLogs)();
533
- case 25:
534
- (0, _common.emitFinalFailure)(function (clientError) {
535
- _this2.lineEmitter(_types3.LINE_EVENTS.ERROR, undefined, clientError);
536
- }, loggerContext);
537
- case 26:
538
- case "end":
539
- return _context1.stop();
540
- }
541
- }, _callee1, this);
542
- }));
543
- function startFailoverTimer() {
544
- return _startFailoverTimer.apply(this, arguments);
545
- }
546
- return startFailoverTimer;
547
- }()
548
- /**
549
- * Clears the failback timer if running.
550
- */
551
- )
552
- }, {
553
- key: "clearFailbackTimer",
554
- value: function clearFailbackTimer() {
555
- if (this.failbackTimer) {
556
- clearTimeout(this.failbackTimer);
557
- this.failbackTimer = undefined;
558
- }
559
- }
560
- }, {
561
- key: "isPrimaryActive",
562
- value: function () {
563
- var _isPrimaryActive = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee10() {
564
- var status, _iterator, _step, mobiusUrl, baseUri, response, _ref6, statusCode;
565
- return _regenerator.default.wrap(function _callee10$(_context10) {
566
- while (1) switch (_context10.prev = _context10.next) {
567
- case 0:
568
- _iterator = _createForOfIteratorHelper(this.primaryMobiusUris);
569
- _context10.prev = 1;
570
- _iterator.s();
571
- case 3:
572
- if ((_step = _iterator.n()).done) {
573
- _context10.next = 23;
574
- break;
575
- }
576
- mobiusUrl = _step.value;
577
- _context10.prev = 5;
578
- baseUri = mobiusUrl.replace(_constants2.URL_ENDPOINT, '/'); // eslint-disable-next-line no-await-in-loop
579
- _context10.next = 9;
580
- return this.webex.request({
581
- uri: "".concat(baseUri, "ping"),
582
- method: _types2.HTTP_METHODS.GET,
583
- headers: (0, _defineProperty2.default)((0, _defineProperty2.default)({}, _constants2.CISCO_DEVICE_URL, this.webex.internal.device.url), _constants2.SPARK_USER_AGENT, _constants2.CALLING_USER_AGENT),
584
- service: _types2.ALLOWED_SERVICES.MOBIUS
585
- });
586
- case 9:
587
- response = _context10.sent;
588
- _ref6 = response, statusCode = _ref6.statusCode;
589
- if (!(statusCode === 200)) {
590
- _context10.next = 15;
591
- break;
592
- }
593
- _Logger.default.info("Ping successful for primary Mobius: ".concat(mobiusUrl), {
594
- file: _constants2.REGISTRATION_FILE,
595
- method: _constants2.FAILBACK_UTIL
596
- });
597
- status = 'up';
598
- return _context10.abrupt("break", 23);
599
- case 15:
600
- _context10.next = 21;
601
- break;
602
- case 17:
603
- _context10.prev = 17;
604
- _context10.t0 = _context10["catch"](5);
605
- _Logger.default.warn("Ping failed for primary Mobius: ".concat(mobiusUrl, " with error: ").concat(_context10.t0), {
606
- file: _constants2.REGISTRATION_FILE,
607
- method: _constants2.FAILBACK_UTIL
608
- });
609
- status = 'down';
610
- case 21:
611
- _context10.next = 3;
612
- break;
613
- case 23:
614
- _context10.next = 28;
615
- break;
616
- case 25:
617
- _context10.prev = 25;
618
- _context10.t1 = _context10["catch"](1);
619
- _iterator.e(_context10.t1);
620
- case 28:
621
- _context10.prev = 28;
622
- _iterator.f();
623
- return _context10.finish(28);
624
- case 31:
625
- return _context10.abrupt("return", status === 'up');
626
- case 32:
627
- case "end":
628
- return _context10.stop();
629
- }
630
- }, _callee10, this, [[1, 25, 28, 31], [5, 17]]);
631
- }));
632
- function isPrimaryActive() {
633
- return _isPrimaryActive.apply(this, arguments);
634
- }
635
- return isPrimaryActive;
636
- }()
637
- /**
638
- * Returns true if device is registered with a backup mobius.
639
- */
640
- }, {
641
- key: "isFailbackRequired",
642
- value: function isFailbackRequired() {
643
- return this.isDeviceRegistered() && this.primaryMobiusUris.indexOf(this.activeMobiusUrl) === -1;
644
- }
645
-
646
- /**
647
- * Calculates and returns a random value between rehomingIntervalMin and
648
- * rehomingIntervalMax.
649
- */
650
- }, {
651
- key: "getFailbackInterval",
652
- value: function getFailbackInterval() {
653
- return Math.floor(Math.random() * (this.rehomingIntervalMax - this.rehomingIntervalMin + 1) + this.rehomingIntervalMin);
654
- }
655
-
656
- /**
657
- * Starts failback timer to move to primary mobius if device
658
- * is registered with a backup mobius.
659
- */
660
- }, {
661
- key: "initiateFailback",
662
- value: function initiateFailback() {
663
- if (this.isFailbackRequired()) {
664
- if (!this.failbackTimer) {
665
- this.failback429RetryAttempts = 0;
666
- var intervalInMinutes = this.getFailbackInterval();
667
- this.startFailbackTimer(intervalInMinutes * _constants2.MINUTES_TO_SEC_MFACTOR);
668
- }
669
- } else {
670
- this.failback429RetryAttempts = 0;
671
- this.clearFailbackTimer();
672
- }
673
- }
674
-
675
- /**
676
- * Starts failback timer with the interval value received.
677
- *
678
- */
679
- }, {
680
- key: "startFailbackTimer",
681
- value: function startFailbackTimer(intervalInSeconds) {
682
- var _this3 = this;
683
- this.failbackTimer = setTimeout(/*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee11() {
684
- return _regenerator.default.wrap(function _callee11$(_context11) {
685
- while (1) switch (_context11.prev = _context11.next) {
686
- case 0:
687
- return _context11.abrupt("return", _this3.executeFailback());
688
- case 1:
689
- case "end":
690
- return _context11.stop();
691
- }
692
- }, _callee11);
693
- })), intervalInSeconds * _constants2.SEC_TO_MSEC_MFACTOR);
694
- _Logger.default.log("Failback scheduled after ".concat(intervalInSeconds, " seconds."), {
695
- file: _constants2.REGISTRATION_FILE,
696
- method: this.startFailbackTimer.name
697
- });
698
- }
699
-
700
- /**
701
- * Core logic for the failback processing, scheduled and executed
702
- * at failback timer expiry.
703
- */
704
- }, {
705
- key: "executeFailback",
706
- value: (function () {
707
- var _executeFailback = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee13() {
708
- var _this4 = this;
709
- return _regenerator.default.wrap(function _callee13$(_context13) {
710
- while (1) switch (_context13.prev = _context13.next) {
711
- case 0:
712
- _context13.next = 2;
713
- return this.mutex.runExclusive(/*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee12() {
714
- var primaryServerStatus, abort, abortNew;
715
- return _regenerator.default.wrap(function _callee12$(_context12) {
716
- while (1) switch (_context12.prev = _context12.next) {
717
- case 0:
718
- if (!_this4.isFailbackRequired()) {
719
- _context12.next = 31;
720
- break;
721
- }
722
- _context12.next = 3;
723
- return _this4.isPrimaryActive();
724
- case 3:
725
- primaryServerStatus = _context12.sent;
726
- if (!((0, _keys.default)(_this4.callManager.getActiveCalls()).length === 0 && primaryServerStatus)) {
727
- _context12.next = 28;
728
- break;
729
- }
730
- _Logger.default.info("Attempting failback to primary.", {
731
- file: _constants2.REGISTRATION_FILE,
732
- method: _this4.executeFailback.name
733
- });
734
- _context12.next = 8;
735
- return _this4.deregister();
736
- case 8:
737
- _context12.next = 10;
738
- return _this4.attemptRegistrationWithServers(_constants2.FAILBACK_UTIL);
739
- case 10:
740
- abort = _context12.sent;
741
- if (!(_this4.scheduled429Retry || abort || _this4.isDeviceRegistered())) {
742
- _context12.next = 13;
743
- break;
744
- }
745
- return _context12.abrupt("return");
746
- case 13:
747
- _context12.next = 15;
748
- return _this4.restorePreviousRegistration(_constants2.FAILBACK_UTIL);
749
- case 15:
750
- abortNew = _context12.sent;
751
- if (!abortNew) {
752
- _context12.next = 19;
753
- break;
754
- }
755
- _this4.clearFailbackTimer();
756
- return _context12.abrupt("return");
757
- case 19:
758
- if (_this4.isDeviceRegistered()) {
759
- _context12.next = 24;
760
- break;
761
- }
762
- _context12.next = 22;
763
- return _this4.restartRegistration(_this4.executeFailback.name);
764
- case 22:
765
- _context12.next = 26;
766
- break;
767
- case 24:
768
- _this4.failbackTimer = undefined;
769
- _this4.initiateFailback();
770
- case 26:
771
- _context12.next = 31;
772
- break;
773
- case 28:
774
- _Logger.default.info('Active calls present or primary Mobius is down, deferring failback to next cycle.', {
775
- file: _constants2.REGISTRATION_FILE,
776
- method: _this4.executeFailback.name
777
- });
778
- _this4.failbackTimer = undefined;
779
- _this4.initiateFailback();
780
- case 31:
781
- case "end":
782
- return _context12.stop();
783
- }
784
- }, _callee12);
785
- })));
786
- case 2:
787
- case "end":
788
- return _context13.stop();
789
- }
790
- }, _callee13, this);
791
- }));
792
- function executeFailback() {
793
- return _executeFailback.apply(this, arguments);
794
- }
795
- return executeFailback;
796
- }()
797
- /**
798
- * Updates rehomingIntervalMin and rehomingIntervalMax values
799
- * if received in registration response from a primary mobius
800
- * server.
801
- *
802
- */
803
- )
804
- }, {
805
- key: "setIntervalValues",
806
- value: function setIntervalValues(deviceInfo) {
807
- if (this.primaryMobiusUris.indexOf(this.activeMobiusUrl) !== -1) {
808
- this.rehomingIntervalMin = deviceInfo !== null && deviceInfo !== void 0 && deviceInfo.rehomingIntervalMin ? deviceInfo.rehomingIntervalMin : _constants2.DEFAULT_REHOMING_INTERVAL_MIN;
809
- this.rehomingIntervalMax = deviceInfo !== null && deviceInfo !== void 0 && deviceInfo.rehomingIntervalMax ? deviceInfo.rehomingIntervalMax : _constants2.DEFAULT_REHOMING_INTERVAL_MAX;
810
- }
811
- }
812
-
813
- /**
814
- * Retrieves information about the device as {@link IDeviceInfo}.
815
- *
816
- */
817
- }, {
818
- key: "getDeviceInfo",
819
- value: function getDeviceInfo() {
820
- return this.deviceInfo;
821
- }
822
-
823
- /**
824
- * Checks if the device is currently registered.
825
- *
826
- * by checking if isRegistered state is set to
827
- * ACTIVE, else false.
828
- */
829
- }, {
830
- key: "isDeviceRegistered",
831
- value: function isDeviceRegistered() {
832
- return this.registrationStatus === _types2.RegistrationStatus.ACTIVE;
833
- }
834
- }, {
835
- key: "getStatus",
836
- value: function getStatus() {
837
- return this.registrationStatus;
838
- }
839
- }, {
840
- key: "setStatus",
841
- value: function setStatus(value) {
842
- this.registrationStatus = value;
843
- }
844
-
845
- /**
846
- * Start fresh registration cycle with the mobius
847
- * server list already present.
848
- *
849
- */
850
- }, {
851
- key: "restartRegistration",
852
- value: (function () {
853
- var _restartRegistration = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee14(caller) {
854
- var abort;
855
- return _regenerator.default.wrap(function _callee14$(_context14) {
856
- while (1) switch (_context14.prev = _context14.next) {
857
- case 0:
858
- /*
859
- * Cancel any failback timer running
860
- * and start fresh registration attempt with retry as true.
861
- */
862
- this.clearFailbackTimer();
863
- this.failback429RetryAttempts = 0;
864
- _context14.next = 4;
865
- return this.attemptRegistrationWithServers(caller, this.primaryMobiusUris);
866
- case 4:
867
- abort = _context14.sent;
868
- if (!(!abort && !this.isDeviceRegistered())) {
869
- _context14.next = 8;
870
- break;
871
- }
872
- _context14.next = 8;
873
- return this.startFailoverTimer();
874
- case 8:
875
- case "end":
876
- return _context14.stop();
877
- }
878
- }, _callee14, this);
879
- }));
880
- function restartRegistration(_x9) {
881
- return _restartRegistration.apply(this, arguments);
882
- }
883
- return restartRegistration;
884
- }()
885
- /**
886
- * Restores the connection and attempts refreshing existing registration with server.
887
- * Allows retry if not restored in the first attempt.
888
- *
889
- */
890
- )
891
- }, {
892
- key: "handleConnectionRestoration",
893
- value: (function () {
894
- var _handleConnectionRestoration = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee16(retry) {
895
- var _this5 = this;
896
- return _regenerator.default.wrap(function _callee16$(_context16) {
897
- while (1) switch (_context16.prev = _context16.next) {
898
- case 0:
899
- _Logger.default.info(_constants.METHOD_START_MESSAGE, {
900
- method: _constants2.METHODS.HANDLE_CONNECTION_RESTORATION,
901
- file: _constants2.REGISTRATION_FILE
902
- });
903
- _context16.next = 3;
904
- return this.mutex.runExclusive(/*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee15() {
905
- var abort;
906
- return _regenerator.default.wrap(function _callee15$(_context15) {
907
- while (1) switch (_context15.prev = _context15.next) {
908
- case 0:
909
- if (!retry) {
910
- _context15.next = 14;
911
- break;
912
- }
913
- _Logger.default.log('Network is up again, re-registering with Webex Calling if needed', {
914
- file: _constants2.REGISTRATION_FILE,
915
- method: _constants2.METHODS.HANDLE_CONNECTION_RESTORATION
916
- });
917
- _this5.clearKeepaliveTimer();
918
- if (!_this5.isDeviceRegistered()) {
919
- _context15.next = 6;
920
- break;
921
- }
922
- _context15.next = 6;
923
- return _this5.deregister();
924
- case 6:
925
- if (!_this5.activeMobiusUrl) {
926
- _context15.next = 13;
927
- break;
928
- }
929
- _context15.next = 9;
930
- return _this5.restorePreviousRegistration(_constants2.METHODS.HANDLE_CONNECTION_RESTORATION);
931
- case 9:
932
- abort = _context15.sent;
933
- if (!(!abort && !_this5.isDeviceRegistered())) {
934
- _context15.next = 13;
935
- break;
936
- }
937
- _context15.next = 13;
938
- return _this5.restartRegistration(_constants2.METHODS.HANDLE_CONNECTION_RESTORATION);
939
- case 13:
940
- retry = false;
941
- case 14:
942
- case "end":
943
- return _context15.stop();
944
- }
945
- }, _callee15);
946
- })));
947
- case 3:
948
- return _context16.abrupt("return", retry);
949
- case 4:
950
- case "end":
951
- return _context16.stop();
952
- }
953
- }, _callee16, this);
954
- }));
955
- function handleConnectionRestoration(_x0) {
956
- return _handleConnectionRestoration.apply(this, arguments);
957
- }
958
- return handleConnectionRestoration;
959
- }()
960
- /**
961
- * Callback function for restoring registration in case of failure during initial registration
962
- * due to device registration already exists.
963
- *
964
- */
965
- )
966
- }, {
967
- key: "restoreRegistrationCallBack",
968
- value: function restoreRegistrationCallBack() {
969
- var _this6 = this;
970
- return /*#__PURE__*/function () {
971
- var _ref0 = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee17(restoreData, caller) {
972
- var logContext, restore, finalError;
973
- return _regenerator.default.wrap(function _callee17$(_context17) {
974
- while (1) switch (_context17.prev = _context17.next) {
975
- case 0:
976
- logContext = {
977
- file: _constants2.REGISTRATION_FILE,
978
- method: caller
979
- };
980
- if (_this6.isRegRetry()) {
981
- _context17.next = 17;
982
- break;
983
- }
984
- _Logger.default.info('Registration restoration in progress.', logContext);
985
- restore = _this6.getExistingDevice(restoreData);
986
- if (!restore) {
987
- _context17.next = 14;
988
- break;
989
- }
990
- _this6.setRegRetry(true);
991
- _context17.next = 8;
992
- return _this6.deregister();
993
- case 8:
994
- _context17.next = 10;
995
- return _this6.restorePreviousRegistration(caller);
996
- case 10:
997
- finalError = _context17.sent;
998
- _this6.setRegRetry(false);
999
- if (_this6.isDeviceRegistered()) {
1000
- _Logger.default.info('Registration restored successfully.', logContext);
1001
- }
1002
- return _context17.abrupt("return", finalError);
1003
- case 14:
1004
- _this6.lineEmitter(_types3.LINE_EVENTS.UNREGISTERED);
1005
- _context17.next = 18;
1006
- break;
1007
- case 17:
1008
- _this6.lineEmitter(_types3.LINE_EVENTS.UNREGISTERED);
1009
- case 18:
1010
- return _context17.abrupt("return", false);
1011
- case 19:
1012
- case "end":
1013
- return _context17.stop();
1014
- }
1015
- }, _callee17);
1016
- }));
1017
- return function (_x1, _x10) {
1018
- return _ref0.apply(this, arguments);
1019
- };
1020
- }();
1021
- }
1022
-
1023
- /**
1024
- * Triggers the registration with the given list of Mobius servers
1025
- * Registration is attempted with primary and backup until it succeeds or the list is exhausted
1026
- */
1027
- }, {
1028
- key: "triggerRegistration",
1029
- value: (function () {
1030
- var _triggerRegistration = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee18() {
1031
- var abort;
1032
- return _regenerator.default.wrap(function _callee18$(_context18) {
1033
- while (1) switch (_context18.prev = _context18.next) {
1034
- case 0:
1035
- if (!(this.primaryMobiusUris.length > 0)) {
1036
- _context18.next = 7;
1037
- break;
1038
- }
1039
- _context18.next = 3;
1040
- return this.attemptRegistrationWithServers(_constants2.REGISTRATION_UTIL, this.primaryMobiusUris);
1041
- case 3:
1042
- abort = _context18.sent;
1043
- if (!(!this.isDeviceRegistered() && !abort)) {
1044
- _context18.next = 7;
1045
- break;
1046
- }
1047
- _context18.next = 7;
1048
- return this.startFailoverTimer();
1049
- case 7:
1050
- case "end":
1051
- return _context18.stop();
1052
- }
1053
- }, _callee18, this);
1054
- }));
1055
- function triggerRegistration() {
1056
- return _triggerRegistration.apply(this, arguments);
1057
- }
1058
- return triggerRegistration;
1059
- }()
1060
- /**
1061
- * Attempts registration with the server list received in
1062
- * argument one by one until registration either succeeds with
1063
- * one or all of them are tried.
1064
- *
1065
- * attempt has hit a final error and a retry should not be scheduled
1066
- * else false.
1067
- */
1068
- )
1069
- }, {
1070
- key: "attemptRegistrationWithServers",
1071
- value: (function () {
1072
- var _attemptRegistrationWithServers = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee19(caller) {
1073
- var _this7 = this;
1074
- var servers,
1075
- abort,
1076
- _iterator2,
1077
- _step2,
1078
- _loop,
1079
- _ret,
1080
- _args20 = arguments;
1081
- return _regenerator.default.wrap(function _callee19$(_context20) {
1082
- while (1) switch (_context20.prev = _context20.next) {
1083
- case 0:
1084
- servers = _args20.length > 1 && _args20[1] !== undefined ? _args20[1] : this.primaryMobiusUris;
1085
- abort = false;
1086
- this.retryAfter = undefined;
1087
- if (!this.failoverImmediately) {
1088
- _context20.next = 5;
1089
- break;
1090
- }
1091
- return _context20.abrupt("return", abort);
1092
- case 5:
1093
- if (!this.isDeviceRegistered()) {
1094
- _context20.next = 8;
1095
- break;
1096
- }
1097
- _Logger.default.info("[".concat(caller, "] : Device already registered with : ").concat(this.activeMobiusUrl), {
1098
- file: _constants2.REGISTRATION_FILE,
1099
- method: _constants2.REGISTER_UTIL
1100
- });
1101
- return _context20.abrupt("return", abort);
1102
- case 8:
1103
- _iterator2 = _createForOfIteratorHelper(servers);
1104
- _context20.prev = 9;
1105
- _loop = /*#__PURE__*/_regenerator.default.mark(function _loop() {
1106
- var _this7$backupMobiusUr;
1107
- var url, serverType, _this7$deviceInfo$dev, _resp$headers, _resp$headers$trackin, _resp$headers2, _this7$deviceInfo$dev2, resp, body;
1108
- return _regenerator.default.wrap(function _loop$(_context19) {
1109
- while (1) switch (_context19.prev = _context19.next) {
1110
- case 0:
1111
- url = _step2.value;
1112
- serverType = _this7.primaryMobiusUris.includes(url) && 'PRIMARY' || ((_this7$backupMobiusUr = _this7.backupMobiusUris) === null || _this7$backupMobiusUr === void 0 ? void 0 : _this7$backupMobiusUr.includes(url)) && 'BACKUP' || 'UNKNOWN';
1113
- _context19.prev = 2;
1114
- abort = false;
1115
- _this7.registrationStatus = _types2.RegistrationStatus.INACTIVE;
1116
- _this7.lineEmitter(_types3.LINE_EVENTS.CONNECTING);
1117
- _Logger.default.info("[".concat(caller, "] : Mobius url to contact: ").concat(url), {
1118
- file: _constants2.REGISTRATION_FILE,
1119
- method: _constants2.REGISTER_UTIL
1120
- });
1121
- // eslint-disable-next-line no-await-in-loop
1122
- _context19.next = 9;
1123
- return _this7.postRegistration(url);
1124
- case 9:
1125
- resp = _context19.sent;
1126
- _this7.deviceInfo = resp.body;
1127
- _this7.registrationStatus = _types2.RegistrationStatus.ACTIVE;
1128
- _this7.setActiveMobiusUrl(url);
1129
- _this7.lineEmitter(_types3.LINE_EVENTS.REGISTERED, resp.body);
1130
- _Logger.default.log("Registration successful for deviceId: ".concat((_this7$deviceInfo$dev = _this7.deviceInfo.device) === null || _this7$deviceInfo$dev === void 0 ? void 0 : _this7$deviceInfo$dev.deviceId, " userId: ").concat(_this7.userId, " responseTrackingId: ").concat((_resp$headers = resp.headers) === null || _resp$headers === void 0 ? void 0 : _resp$headers.trackingid), {
1131
- file: _constants2.REGISTRATION_FILE,
1132
- method: _constants2.METHODS.REGISTER
1133
- });
1134
- _this7.setIntervalValues(_this7.deviceInfo);
1135
- _this7.metricManager.setDeviceInfo(_this7.deviceInfo);
1136
- _this7.metricManager.submitRegistrationMetric(_types.METRIC_EVENT.REGISTRATION, _types.REG_ACTION.REGISTER, _types.METRIC_TYPE.BEHAVIORAL, caller, serverType, (_resp$headers$trackin = (_resp$headers2 = resp.headers) === null || _resp$headers2 === void 0 ? void 0 : _resp$headers2.trackingid) !== null && _resp$headers$trackin !== void 0 ? _resp$headers$trackin : '', undefined, undefined);
1137
- _this7.startKeepaliveTimer((_this7$deviceInfo$dev2 = _this7.deviceInfo.device) === null || _this7$deviceInfo$dev2 === void 0 ? void 0 : _this7$deviceInfo$dev2.uri, _this7.deviceInfo.keepaliveInterval, serverType);
1138
- _this7.initiateFailback();
1139
- return _context19.abrupt("return", 0);
1140
- case 23:
1141
- _context19.prev = 23;
1142
- _context19.t0 = _context19["catch"](2);
1143
- body = _context19.t0; // eslint-disable-next-line no-await-in-loop, @typescript-eslint/no-unused-vars
1144
- _context19.next = 28;
1145
- return (0, _common.handleRegistrationErrors)(body, function (clientError, finalError) {
1146
- var _body$headers$trackin, _body$headers;
1147
- if (finalError) {
1148
- _this7.lineEmitter(_types3.LINE_EVENTS.ERROR, undefined, clientError);
1149
- } else {
1150
- _this7.lineEmitter(_types3.LINE_EVENTS.UNREGISTERED);
1151
- }
1152
- _this7.metricManager.submitRegistrationMetric(_types.METRIC_EVENT.REGISTRATION_ERROR, _types.REG_ACTION.REGISTER, _types.METRIC_TYPE.BEHAVIORAL, caller, serverType, (_body$headers$trackin = (_body$headers = body.headers) === null || _body$headers === void 0 ? void 0 : _body$headers.trackingid) !== null && _body$headers$trackin !== void 0 ? _body$headers$trackin : '', undefined, clientError);
1153
- }, {
1154
- method: caller,
1155
- file: _constants2.REGISTRATION_FILE
1156
- }, function (retryAfter, retryCaller) {
1157
- return _this7.handle429Retry(retryAfter, retryCaller);
1158
- }, _this7.restoreRegistrationCallBack());
1159
- case 28:
1160
- abort = _context19.sent;
1161
- if (!(_this7.registrationStatus === _types2.RegistrationStatus.ACTIVE)) {
1162
- _context19.next = 32;
1163
- break;
1164
- }
1165
- _Logger.default.info("[".concat(caller, "] : Device is already restored, active mobius url: ").concat(_this7.activeMobiusUrl), {
1166
- file: _constants2.REGISTRATION_FILE,
1167
- method: _this7.attemptRegistrationWithServers.name
1168
- });
1169
- return _context19.abrupt("return", 0);
1170
- case 32:
1171
- if (!abort) {
1172
- _context19.next = 37;
1173
- break;
1174
- }
1175
- _this7.setStatus(_types2.RegistrationStatus.INACTIVE);
1176
- // eslint-disable-next-line no-await-in-loop
1177
- _context19.next = 36;
1178
- return (0, _common.uploadLogs)();
1179
- case 36:
1180
- return _context19.abrupt("return", 0);
1181
- case 37:
1182
- case "end":
1183
- return _context19.stop();
1184
- }
1185
- }, _loop, null, [[2, 23]]);
1186
- });
1187
- _iterator2.s();
1188
- case 12:
1189
- if ((_step2 = _iterator2.n()).done) {
1190
- _context20.next = 19;
1191
- break;
1192
- }
1193
- return _context20.delegateYield(_loop(), "t0", 14);
1194
- case 14:
1195
- _ret = _context20.t0;
1196
- if (!(_ret === 0)) {
1197
- _context20.next = 17;
1198
- break;
1199
- }
1200
- return _context20.abrupt("break", 19);
1201
- case 17:
1202
- _context20.next = 12;
1203
- break;
1204
- case 19:
1205
- _context20.next = 24;
1206
- break;
1207
- case 21:
1208
- _context20.prev = 21;
1209
- _context20.t1 = _context20["catch"](9);
1210
- _iterator2.e(_context20.t1);
1211
- case 24:
1212
- _context20.prev = 24;
1213
- _iterator2.f();
1214
- return _context20.finish(24);
1215
- case 27:
1216
- return _context20.abrupt("return", abort);
1217
- case 28:
1218
- case "end":
1219
- return _context20.stop();
1220
- }
1221
- }, _callee19, this, [[9, 21, 24, 27]]);
1222
- }));
1223
- function attemptRegistrationWithServers(_x11) {
1224
- return _attemptRegistrationWithServers.apply(this, arguments);
1225
- }
1226
- return attemptRegistrationWithServers;
1227
- }()
1228
- /**
1229
- * This method sets up a timer to periodically send keep-alive requests to maintain a connection.
1230
- * It handles retries, error handling, and re-registration attempts based on the response, ensuring continuous connectivity with the server.
1231
- */
1232
- )
1233
- }, {
1234
- key: "startKeepaliveTimer",
1235
- value: (function () {
1236
- var _startKeepaliveTimer = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee22(url, interval, serverType) {
1237
- var _this8 = this;
1238
- var RETRY_COUNT_THRESHOLD;
1239
- return _regenerator.default.wrap(function _callee22$(_context23) {
1240
- while (1) switch (_context23.prev = _context23.next) {
1241
- case 0:
1242
- this.clearKeepaliveTimer();
1243
- RETRY_COUNT_THRESHOLD = this.isCCFlow ? 4 : 5;
1244
- _context23.next = 4;
1245
- return this.mutex.runExclusive(/*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee21() {
1246
- var accessToken, blob, blobUrl;
1247
- return _regenerator.default.wrap(function _callee21$(_context22) {
1248
- while (1) switch (_context22.prev = _context22.next) {
1249
- case 0:
1250
- if (!_this8.isDeviceRegistered()) {
1251
- _context22.next = 5;
1252
- break;
1253
- }
1254
- _context22.next = 3;
1255
- return _this8.webex.credentials.getUserToken();
1256
- case 3:
1257
- accessToken = _context22.sent;
1258
- if (!_this8.webWorker) {
1259
- blob = new Blob([_webWorkerStr.default], {
1260
- type: 'application/javascript'
1261
- });
1262
- blobUrl = URL.createObjectURL(blob);
1263
- _this8.webWorker = new Worker(blobUrl);
1264
- URL.revokeObjectURL(blobUrl);
1265
- _this8.webWorker.postMessage({
1266
- type: _types2.WorkerMessageType.START_KEEPALIVE,
1267
- accessToken: String(accessToken),
1268
- deviceUrl: String(_this8.webex.internal.device.url),
1269
- interval: interval,
1270
- retryCountThreshold: RETRY_COUNT_THRESHOLD,
1271
- url: url
1272
- });
1273
- _this8.webWorker.onmessage = /*#__PURE__*/function () {
1274
- var _ref10 = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee20(event) {
1275
- var logContext, error, abort;
1276
- return _regenerator.default.wrap(function _callee20$(_context21) {
1277
- while (1) switch (_context21.prev = _context21.next) {
1278
- case 0:
1279
- logContext = {
1280
- file: _constants2.REGISTRATION_FILE,
1281
- method: _constants2.KEEPALIVE_UTIL
1282
- };
1283
- if (event.data.type === _types2.WorkerMessageType.KEEPALIVE_SUCCESS) {
1284
- _Logger.default.info("Sent Keepalive, status: ".concat(event.data.statusCode), logContext);
1285
- _this8.lineEmitter(_types3.LINE_EVENTS.RECONNECTED);
1286
- }
1287
- if (!(event.data.type === _types2.WorkerMessageType.KEEPALIVE_FAILURE)) {
1288
- _context21.next = 25;
1289
- break;
1290
- }
1291
- error = event.data.err;
1292
- _Logger.default.warn("Keep-alive missed ".concat(event.data.keepAliveRetryCount, " times. Status -> ").concat(error.statusCode, " "), logContext);
1293
- _context21.next = 7;
1294
- return (0, _common.handleRegistrationErrors)(error, function (clientError, finalError) {
1295
- var _error$headers$tracki, _error$headers;
1296
- if (finalError) {
1297
- _this8.lineEmitter(_types3.LINE_EVENTS.ERROR, undefined, clientError);
1298
- }
1299
- _this8.metricManager.submitRegistrationMetric(_types.METRIC_EVENT.KEEPALIVE_ERROR, _types.REG_ACTION.KEEPALIVE_FAILURE, _types.METRIC_TYPE.BEHAVIORAL, _constants2.KEEPALIVE_UTIL, serverType, (_error$headers$tracki = (_error$headers = error.headers) === null || _error$headers === void 0 ? void 0 : _error$headers.trackingid) !== null && _error$headers$tracki !== void 0 ? _error$headers$tracki : '', event.data.keepAliveRetryCount, clientError);
1300
- }, {
1301
- method: _constants2.KEEPALIVE_UTIL,
1302
- file: _constants2.REGISTRATION_FILE
1303
- }, function (retryAfter, retryCaller) {
1304
- return _this8.handle429Retry(retryAfter, retryCaller);
1305
- });
1306
- case 7:
1307
- abort = _context21.sent;
1308
- if (!(abort || event.data.keepAliveRetryCount >= RETRY_COUNT_THRESHOLD)) {
1309
- _context21.next = 24;
1310
- break;
1311
- }
1312
- _this8.failoverImmediately = _this8.isCCFlow;
1313
- _this8.setStatus(_types2.RegistrationStatus.INACTIVE);
1314
- _this8.clearKeepaliveTimer();
1315
- _this8.clearFailbackTimer();
1316
- _this8.lineEmitter(_types3.LINE_EVENTS.UNREGISTERED);
1317
- _context21.next = 16;
1318
- return (0, _common.uploadLogs)();
1319
- case 16:
1320
- if (abort) {
1321
- _context21.next = 21;
1322
- break;
1323
- }
1324
- _context21.next = 19;
1325
- return _this8.reconnectOnFailure(_constants2.KEEPALIVE_UTIL);
1326
- case 19:
1327
- _context21.next = 22;
1328
- break;
1329
- case 21:
1330
- if (error.statusCode === 404) {
1331
- _this8.handle404KeepaliveFailure(_constants2.KEEPALIVE_UTIL);
1332
- }
1333
- case 22:
1334
- _context21.next = 25;
1335
- break;
1336
- case 24:
1337
- _this8.lineEmitter(_types3.LINE_EVENTS.RECONNECTING);
1338
- case 25:
1339
- case "end":
1340
- return _context21.stop();
1341
- }
1342
- }, _callee20);
1343
- }));
1344
- return function (_x15) {
1345
- return _ref10.apply(this, arguments);
1346
- };
1347
- }();
1348
- }
1349
- case 5:
1350
- case "end":
1351
- return _context22.stop();
1352
- }
1353
- }, _callee21);
1354
- })));
1355
- case 4:
1356
- case "end":
1357
- return _context23.stop();
1358
- }
1359
- }, _callee22, this);
1360
- }));
1361
- function startKeepaliveTimer(_x12, _x13, _x14) {
1362
- return _startKeepaliveTimer.apply(this, arguments);
1363
- }
1364
- return startKeepaliveTimer;
1365
- }()
1366
- /**
1367
- * Clears the keepalive timer if running.
1368
- */
1369
- )
1370
- }, {
1371
- key: "clearKeepaliveTimer",
1372
- value: function clearKeepaliveTimer() {
1373
- if (this.webWorker) {
1374
- this.webWorker.postMessage({
1375
- type: _types2.WorkerMessageType.CLEAR_KEEPALIVE
1376
- });
1377
- this.webWorker.terminate();
1378
- this.webWorker = undefined;
1379
- }
1380
- }
1381
- }, {
1382
- key: "isReconnectPending",
1383
- value: function isReconnectPending() {
1384
- return this.reconnectPending;
1385
- }
1386
- }, {
1387
- key: "deregister",
1388
- value: function () {
1389
- var _deregister = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee23() {
1390
- var _this$deviceInfo$devi2, _this$deviceInfo$devi3;
1391
- return _regenerator.default.wrap(function _callee23$(_context24) {
1392
- while (1) switch (_context24.prev = _context24.next) {
1393
- case 0:
1394
- _context24.prev = 0;
1395
- _context24.next = 3;
1396
- return this.deleteRegistration(this.activeMobiusUrl, (_this$deviceInfo$devi2 = this.deviceInfo.device) === null || _this$deviceInfo$devi2 === void 0 ? void 0 : _this$deviceInfo$devi2.deviceId, (_this$deviceInfo$devi3 = this.deviceInfo.device) === null || _this$deviceInfo$devi3 === void 0 ? void 0 : _this$deviceInfo$devi3.clientDeviceUri);
1397
- case 3:
1398
- _Logger.default.log('Registration successfully deregistered', {
1399
- file: _constants2.REGISTRATION_FILE,
1400
- method: _constants2.METHODS.DEREGISTER
1401
- });
1402
- _context24.next = 9;
1403
- break;
1404
- case 6:
1405
- _context24.prev = 6;
1406
- _context24.t0 = _context24["catch"](0);
1407
- _Logger.default.warn("Delete failed with Mobius: ".concat(_context24.t0), {
1408
- file: _constants2.REGISTRATION_FILE,
1409
- method: _constants2.METHODS.DEREGISTER
1410
- });
1411
- case 9:
1412
- this.clearKeepaliveTimer();
1413
- this.setStatus(_types2.RegistrationStatus.INACTIVE);
1414
- case 11:
1415
- case "end":
1416
- return _context24.stop();
1417
- }
1418
- }, _callee23, this, [[0, 6]]);
1419
- }));
1420
- function deregister() {
1421
- return _deregister.apply(this, arguments);
1422
- }
1423
- return deregister;
1424
- }()
1425
- /**
1426
- * Indicates whether the calling client is in a mode
1427
- * to retry registration.
1428
- */
1429
- }, {
1430
- key: "isRegRetry",
1431
- value: function isRegRetry() {
1432
- return this.registerRetry;
1433
- }
1434
-
1435
- /**
1436
- * Sets the received value in instance variable
1437
- * registerRetry for registration retry cases.
1438
- *
1439
- */
1440
- }, {
1441
- key: "setRegRetry",
1442
- value: function setRegRetry(value) {
1443
- this.registerRetry = value;
1444
- }
1445
-
1446
- /**
1447
- * Restores the deviceInfo object in callingClient when receiving a 403 with error code 101.
1448
- *
1449
- */
1450
- }, {
1451
- key: "getExistingDevice",
1452
- value: function getExistingDevice(restoreData) {
1453
- if (restoreData.devices && restoreData.devices.length > 0) {
1454
- this.deviceInfo = {
1455
- userId: restoreData.userId,
1456
- device: restoreData.devices[0],
1457
- keepaliveInterval: _constants2.DEFAULT_KEEPALIVE_INTERVAL,
1458
- rehomingIntervalMax: _constants2.DEFAULT_REHOMING_INTERVAL_MAX,
1459
- rehomingIntervalMin: _constants2.DEFAULT_REHOMING_INTERVAL_MIN
1460
- };
1461
- var stringToReplace = "".concat(_constants2.DEVICES_ENDPOINT_RESOURCE, "/").concat(restoreData.devices[0].deviceId);
1462
- var uri = restoreData.devices[0].uri.replace(stringToReplace, '');
1463
- this.setActiveMobiusUrl(uri);
1464
- this.registrationStatus = _types2.RegistrationStatus.ACTIVE;
1465
- return true;
1466
- }
1467
- return false;
1468
- }
1469
-
1470
- /**
1471
- * Invoked to re-register in cases when the registration
1472
- * is lost due to some failure.
1473
- * If there are active calls, it will only mark reconnectPending
1474
- * as true and then retry will happen when this method gets
1475
- * invoked again on receiving all calls cleared event from
1476
- * callManager.
1477
- *
1478
- */
1479
- }, {
1480
- key: "reconnectOnFailure",
1481
- value: (function () {
1482
- var _reconnectOnFailure = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee24(caller) {
1483
- var abort;
1484
- return _regenerator.default.wrap(function _callee24$(_context25) {
1485
- while (1) switch (_context25.prev = _context25.next) {
1486
- case 0:
1487
- _Logger.default.info(_constants.METHOD_START_MESSAGE, {
1488
- method: _constants2.METHODS.RECONNECT_ON_FAILURE,
1489
- file: _constants2.REGISTRATION_FILE
1490
- });
1491
- this.reconnectPending = false;
1492
- if (this.isDeviceRegistered()) {
1493
- _context25.next = 14;
1494
- break;
1495
- }
1496
- if (!((0, _keys.default)(this.callManager.getActiveCalls()).length === 0)) {
1497
- _context25.next = 12;
1498
- break;
1499
- }
1500
- _context25.next = 6;
1501
- return this.restorePreviousRegistration(caller);
1502
- case 6:
1503
- abort = _context25.sent;
1504
- if (!(!abort && !this.isDeviceRegistered())) {
1505
- _context25.next = 10;
1506
- break;
1507
- }
1508
- _context25.next = 10;
1509
- return this.restartRegistration(caller);
1510
- case 10:
1511
- _context25.next = 14;
1512
- break;
1513
- case 12:
1514
- this.reconnectPending = true;
1515
- _Logger.default.info('Active call(s) present, deferred reconnect till call cleanup.', {
1516
- file: _constants2.REGISTRATION_FILE,
1517
- method: _constants2.METHODS.RECONNECT_ON_FAILURE
1518
- });
1519
- case 14:
1520
- case "end":
1521
- return _context25.stop();
1522
- }
1523
- }, _callee24, this);
1524
- }));
1525
- function reconnectOnFailure(_x16) {
1526
- return _reconnectOnFailure.apply(this, arguments);
1527
- }
1528
- return reconnectOnFailure;
1529
- }())
1530
- }]);
1531
- return Registration;
1532
- }();
1533
- /*
1534
- */
1535
- var createRegistration = exports.createRegistration = function createRegistration(webex, serviceData, mutex, lineEmitter, logLevel, jwe) {
1536
- return new Registration(webex, serviceData, mutex, lineEmitter, logLevel, jwe);
1537
- };
1538
- //# sourceMappingURL=register.js.map