@webex/calling 3.12.0-next.5 → 3.12.0-next.51

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 (212) hide show
  1. package/dist/CallingClient/CallingClient.js +506 -223
  2. package/dist/CallingClient/CallingClient.js.map +1 -1
  3. package/dist/CallingClient/CallingClient.test.js +236 -77
  4. package/dist/CallingClient/CallingClient.test.js.map +1 -1
  5. package/dist/CallingClient/calling/call.js +589 -445
  6. package/dist/CallingClient/calling/call.js.map +1 -1
  7. package/dist/CallingClient/calling/call.test.js +695 -445
  8. package/dist/CallingClient/calling/call.test.js.map +1 -1
  9. package/dist/CallingClient/calling/callManager.js +53 -30
  10. package/dist/CallingClient/calling/callManager.js.map +1 -1
  11. package/dist/CallingClient/calling/callManager.test.js +35 -0
  12. package/dist/CallingClient/calling/callManager.test.js.map +1 -1
  13. package/dist/CallingClient/calling/types.js +2 -0
  14. package/dist/CallingClient/calling/types.js.map +1 -1
  15. package/dist/CallingClient/constants.js +27 -3
  16. package/dist/CallingClient/constants.js.map +1 -1
  17. package/dist/CallingClient/line/index.js +4 -1
  18. package/dist/CallingClient/line/index.js.map +1 -1
  19. package/dist/CallingClient/line/line.test.js +16 -1
  20. package/dist/CallingClient/line/line.test.js.map +1 -1
  21. package/dist/CallingClient/registration/register.js +714 -407
  22. package/dist/CallingClient/registration/register.js.map +1 -1
  23. package/dist/CallingClient/registration/register.test.js +311 -58
  24. package/dist/CallingClient/registration/register.test.js.map +1 -1
  25. package/dist/CallingClient/registration/types.js.map +1 -1
  26. package/dist/CallingClient/registration/webWorker.js +41 -104
  27. package/dist/CallingClient/registration/webWorker.js.map +1 -1
  28. package/dist/CallingClient/registration/webWorker.test.js +39 -153
  29. package/dist/CallingClient/registration/webWorker.test.js.map +1 -1
  30. package/dist/CallingClient/registration/webWorkerStr.js +1 -1
  31. package/dist/CallingClient/registration/webWorkerStr.js.map +1 -1
  32. package/dist/CallingClient/types.js.map +1 -1
  33. package/dist/CallingClient/utils/constants.js +58 -0
  34. package/dist/CallingClient/utils/constants.js.map +1 -0
  35. package/dist/CallingClient/utils/index.js +63 -0
  36. package/dist/CallingClient/utils/index.js.map +1 -0
  37. package/dist/CallingClient/utils/mobiusSocketMapper.js +122 -0
  38. package/dist/CallingClient/utils/mobiusSocketMapper.js.map +1 -0
  39. package/dist/CallingClient/utils/mobiusSocketMapper.test.js +221 -0
  40. package/dist/CallingClient/utils/mobiusSocketMapper.test.js.map +1 -0
  41. package/dist/CallingClient/utils/request.js +415 -0
  42. package/dist/CallingClient/utils/request.js.map +1 -0
  43. package/dist/CallingClient/utils/request.test.js +968 -0
  44. package/dist/CallingClient/utils/request.test.js.map +1 -0
  45. package/dist/CallingClient/utils/types.js +7 -0
  46. package/dist/CallingClient/utils/types.js.map +1 -0
  47. package/dist/CallingClient/utils/wsFeatureFlag.js +70 -0
  48. package/dist/CallingClient/utils/wsFeatureFlag.js.map +1 -0
  49. package/dist/CallingClient/utils/wsFeatureFlag.test.js +139 -0
  50. package/dist/CallingClient/utils/wsFeatureFlag.test.js.map +1 -0
  51. package/dist/Contacts/ContactsClient.js +13 -11
  52. package/dist/Contacts/ContactsClient.js.map +1 -1
  53. package/dist/Contacts/ContactsClient.test.js +3 -8
  54. package/dist/Contacts/ContactsClient.test.js.map +1 -1
  55. package/dist/Events/types.js +11 -11
  56. package/dist/Events/types.js.map +1 -1
  57. package/dist/Metrics/index.js +63 -2
  58. package/dist/Metrics/index.js.map +1 -1
  59. package/dist/Metrics/index.test.js +357 -1
  60. package/dist/Metrics/index.test.js.map +1 -1
  61. package/dist/Metrics/types.js +19 -1
  62. package/dist/Metrics/types.js.map +1 -1
  63. package/dist/SDKConnector/types.js.map +1 -1
  64. package/dist/common/Utils.js +138 -44
  65. package/dist/common/Utils.js.map +1 -1
  66. package/dist/common/testUtil.js +8 -4
  67. package/dist/common/testUtil.js.map +1 -1
  68. package/dist/common/types.js +2 -0
  69. package/dist/common/types.js.map +1 -1
  70. package/dist/index.js +12 -0
  71. package/dist/index.js.map +1 -1
  72. package/dist/mobius-socket/config.js +24 -0
  73. package/dist/mobius-socket/config.js.map +1 -0
  74. package/dist/mobius-socket/errors.js +143 -0
  75. package/dist/mobius-socket/errors.js.map +1 -0
  76. package/dist/mobius-socket/errors.test.js +20 -0
  77. package/dist/mobius-socket/errors.test.js.map +1 -0
  78. package/dist/mobius-socket/index.js +57 -0
  79. package/dist/mobius-socket/index.js.map +1 -0
  80. package/dist/mobius-socket/mobius-socket-events.test.js +492 -0
  81. package/dist/mobius-socket/mobius-socket-events.test.js.map +1 -0
  82. package/dist/mobius-socket/mobius-socket.js +849 -0
  83. package/dist/mobius-socket/mobius-socket.js.map +1 -0
  84. package/dist/mobius-socket/mobius-socket.test.js +1898 -0
  85. package/dist/mobius-socket/mobius-socket.test.js.map +1 -0
  86. package/dist/mobius-socket/socket/constants.js +55 -0
  87. package/dist/mobius-socket/socket/constants.js.map +1 -0
  88. package/dist/mobius-socket/socket/index.js +15 -0
  89. package/dist/mobius-socket/socket/index.js.map +1 -0
  90. package/dist/mobius-socket/socket/socket-base.js +604 -0
  91. package/dist/mobius-socket/socket/socket-base.js.map +1 -0
  92. package/dist/mobius-socket/socket/socket.js +19 -0
  93. package/dist/mobius-socket/socket/socket.js.map +1 -0
  94. package/dist/mobius-socket/socket/socket.shim.js +26 -0
  95. package/dist/mobius-socket/socket/socket.shim.js.map +1 -0
  96. package/dist/mobius-socket/socket/types.js +7 -0
  97. package/dist/mobius-socket/socket/types.js.map +1 -0
  98. package/dist/mobius-socket/socket.test.js +727 -0
  99. package/dist/mobius-socket/socket.test.js.map +1 -0
  100. package/dist/mobius-socket/test/mocha-helpers.js +23 -0
  101. package/dist/mobius-socket/test/mocha-helpers.js.map +1 -0
  102. package/dist/mobius-socket/test/promise-tick.js +28 -0
  103. package/dist/mobius-socket/test/promise-tick.js.map +1 -0
  104. package/dist/mobius-socket/types.js +7 -0
  105. package/dist/mobius-socket/types.js.map +1 -0
  106. package/dist/module/CallingClient/CallingClient.js +148 -10
  107. package/dist/module/CallingClient/calling/call.js +177 -61
  108. package/dist/module/CallingClient/calling/callManager.js +27 -7
  109. package/dist/module/CallingClient/calling/types.js +2 -0
  110. package/dist/module/CallingClient/constants.js +23 -0
  111. package/dist/module/CallingClient/line/index.js +2 -2
  112. package/dist/module/CallingClient/registration/register.js +236 -63
  113. package/dist/module/CallingClient/registration/webWorker.js +42 -61
  114. package/dist/module/CallingClient/registration/webWorkerStr.js +47 -82
  115. package/dist/module/CallingClient/utils/constants.js +36 -0
  116. package/dist/module/CallingClient/utils/index.js +5 -0
  117. package/dist/module/CallingClient/utils/mobiusSocketMapper.js +72 -0
  118. package/dist/module/CallingClient/utils/request.js +204 -0
  119. package/dist/module/CallingClient/utils/types.js +1 -0
  120. package/dist/module/CallingClient/utils/wsFeatureFlag.js +41 -0
  121. package/dist/module/Contacts/ContactsClient.js +1 -1
  122. package/dist/module/Events/types.js +4 -10
  123. package/dist/module/Metrics/index.js +48 -1
  124. package/dist/module/Metrics/types.js +18 -0
  125. package/dist/module/common/Utils.js +52 -12
  126. package/dist/module/common/testUtil.js +5 -1
  127. package/dist/module/common/types.js +2 -0
  128. package/dist/module/index.js +1 -1
  129. package/dist/module/mobius-socket/config.js +15 -0
  130. package/dist/module/mobius-socket/errors.js +58 -0
  131. package/dist/module/mobius-socket/index.js +24 -0
  132. package/dist/module/mobius-socket/mobius-socket.js +593 -0
  133. package/dist/module/mobius-socket/socket/constants.js +26 -0
  134. package/dist/module/mobius-socket/socket/index.js +4 -0
  135. package/dist/module/mobius-socket/socket/socket-base.js +368 -0
  136. package/dist/module/mobius-socket/socket/socket.js +9 -0
  137. package/dist/module/mobius-socket/socket/socket.shim.js +12 -0
  138. package/dist/module/mobius-socket/socket/types.js +1 -0
  139. package/dist/module/mobius-socket/types.js +1 -0
  140. package/dist/types/CallingClient/CallingClient.d.ts +8 -0
  141. package/dist/types/CallingClient/CallingClient.d.ts.map +1 -1
  142. package/dist/types/CallingClient/calling/call.d.ts +12 -0
  143. package/dist/types/CallingClient/calling/call.d.ts.map +1 -1
  144. package/dist/types/CallingClient/calling/callManager.d.ts +3 -2
  145. package/dist/types/CallingClient/calling/callManager.d.ts.map +1 -1
  146. package/dist/types/CallingClient/calling/types.d.ts +34 -9
  147. package/dist/types/CallingClient/calling/types.d.ts.map +1 -1
  148. package/dist/types/CallingClient/constants.d.ts +23 -0
  149. package/dist/types/CallingClient/constants.d.ts.map +1 -1
  150. package/dist/types/CallingClient/line/index.d.ts +1 -1
  151. package/dist/types/CallingClient/line/index.d.ts.map +1 -1
  152. package/dist/types/CallingClient/registration/register.d.ts +7 -1
  153. package/dist/types/CallingClient/registration/register.d.ts.map +1 -1
  154. package/dist/types/CallingClient/registration/types.d.ts +4 -2
  155. package/dist/types/CallingClient/registration/types.d.ts.map +1 -1
  156. package/dist/types/CallingClient/registration/webWorker.d.ts.map +1 -1
  157. package/dist/types/CallingClient/registration/webWorkerStr.d.ts +1 -1
  158. package/dist/types/CallingClient/registration/webWorkerStr.d.ts.map +1 -1
  159. package/dist/types/CallingClient/types.d.ts +1 -0
  160. package/dist/types/CallingClient/types.d.ts.map +1 -1
  161. package/dist/types/CallingClient/utils/constants.d.ts +35 -0
  162. package/dist/types/CallingClient/utils/constants.d.ts.map +1 -0
  163. package/dist/types/CallingClient/utils/index.d.ts +6 -0
  164. package/dist/types/CallingClient/utils/index.d.ts.map +1 -0
  165. package/dist/types/CallingClient/utils/mobiusSocketMapper.d.ts +5 -0
  166. package/dist/types/CallingClient/utils/mobiusSocketMapper.d.ts.map +1 -0
  167. package/dist/types/CallingClient/utils/request.d.ts +27 -0
  168. package/dist/types/CallingClient/utils/request.d.ts.map +1 -0
  169. package/dist/types/CallingClient/utils/types.d.ts +34 -0
  170. package/dist/types/CallingClient/utils/types.d.ts.map +1 -0
  171. package/dist/types/CallingClient/utils/wsFeatureFlag.d.ts +4 -0
  172. package/dist/types/CallingClient/utils/wsFeatureFlag.d.ts.map +1 -0
  173. package/dist/types/Events/types.d.ts +14 -13
  174. package/dist/types/Events/types.d.ts.map +1 -1
  175. package/dist/types/Metrics/index.d.ts.map +1 -1
  176. package/dist/types/Metrics/types.d.ts +19 -2
  177. package/dist/types/Metrics/types.d.ts.map +1 -1
  178. package/dist/types/SDKConnector/types.d.ts +24 -0
  179. package/dist/types/SDKConnector/types.d.ts.map +1 -1
  180. package/dist/types/common/Utils.d.ts +9 -2
  181. package/dist/types/common/Utils.d.ts.map +1 -1
  182. package/dist/types/common/testUtil.d.ts +4 -1
  183. package/dist/types/common/testUtil.d.ts.map +1 -1
  184. package/dist/types/common/types.d.ts +3 -0
  185. package/dist/types/common/types.d.ts.map +1 -1
  186. package/dist/types/index.d.ts +1 -1
  187. package/dist/types/index.d.ts.map +1 -1
  188. package/dist/types/mobius-socket/config.d.ts +17 -0
  189. package/dist/types/mobius-socket/config.d.ts.map +1 -0
  190. package/dist/types/mobius-socket/errors.d.ts +32 -0
  191. package/dist/types/mobius-socket/errors.d.ts.map +1 -0
  192. package/dist/types/mobius-socket/index.d.ts +14 -0
  193. package/dist/types/mobius-socket/index.d.ts.map +1 -0
  194. package/dist/types/mobius-socket/mobius-socket.d.ts +48 -0
  195. package/dist/types/mobius-socket/mobius-socket.d.ts.map +1 -0
  196. package/dist/types/mobius-socket/socket/constants.d.ts +27 -0
  197. package/dist/types/mobius-socket/socket/constants.d.ts.map +1 -0
  198. package/dist/types/mobius-socket/socket/index.d.ts +5 -0
  199. package/dist/types/mobius-socket/socket/index.d.ts.map +1 -0
  200. package/dist/types/mobius-socket/socket/socket-base.d.ts +43 -0
  201. package/dist/types/mobius-socket/socket/socket-base.d.ts.map +1 -0
  202. package/dist/types/mobius-socket/socket/socket.d.ts +6 -0
  203. package/dist/types/mobius-socket/socket/socket.d.ts.map +1 -0
  204. package/dist/types/mobius-socket/socket/socket.shim.d.ts +6 -0
  205. package/dist/types/mobius-socket/socket/socket.shim.d.ts.map +1 -0
  206. package/dist/types/mobius-socket/socket/types.d.ts +61 -0
  207. package/dist/types/mobius-socket/socket/types.d.ts.map +1 -0
  208. package/dist/types/mobius-socket/types.d.ts +21 -0
  209. package/dist/types/mobius-socket/types.d.ts.map +1 -0
  210. package/package.json +20 -5
  211. package/src/mobius-socket/socket/socket.shim.ts +22 -0
  212. package/src/mobius-socket/socket/socket.ts +14 -0
@@ -32,9 +32,17 @@ var _constants = require("../constants");
32
32
  var _types4 = require("../line/types");
33
33
  var _LineError = require("../../Errors/catalog/LineError");
34
34
  var _types5 = require("../../Metrics/types");
35
+ var _request = require("../utils/request");
35
36
  function _interopRequireWildcard(e, t) { if ("function" == typeof _WeakMap) var r = new _WeakMap(), n = new _WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = _Object$defineProperty) && _Object$getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
36
37
  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; }
37
38
  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; } /* eslint-disable @typescript-eslint/no-shadow */
39
+ jest.mock('../../mobius-socket', function () {
40
+ return {
41
+ getMobiusSocketInstance: jest.fn().mockReturnValue({
42
+ sendWssRequest: jest.fn()
43
+ })
44
+ };
45
+ });
38
46
  var webex = (0, _testUtil.getTestUtilsWebex)();
39
47
  var MockServiceData = {
40
48
  indicator: _types.ServiceIndicator.CALLING,
@@ -137,6 +145,11 @@ describe('Registration Tests', function () {
137
145
  metricSpy = jest.spyOn(reg.metricManager, 'submitRegistrationMetric');
138
146
  };
139
147
  beforeEach(function () {
148
+ _request.APIRequest.resetInstance();
149
+ _request.APIRequest.getInstance({
150
+ webex: webex,
151
+ isMobiusSocketEnabled: false
152
+ });
140
153
  setupRegistration(MockServiceData);
141
154
  });
142
155
  afterEach(function () {
@@ -170,7 +183,7 @@ describe('Registration Tests', function () {
170
183
  // Check that log.log was called for successful registration
171
184
  expect(logSpy).toBeCalledWith("Registration successful for deviceId: ".concat(_registerFixtures.mockPostResponse.device.deviceId, " userId: ").concat(_registerFixtures.mockPostResponse.userId, " responseTrackingId: webex-js-sdk_06bafdd0-2f9b-4cd7-b438-9c0d95ecec9b_15"), expect.objectContaining({
172
185
  file: _constants.REGISTRATION_FILE,
173
- method: 'register'
186
+ method: _constants.REGISTER_UTIL
174
187
  }));
175
188
  expect(metricSpy).toBeCalledWith(_types5.METRIC_EVENT.REGISTRATION, _types5.REG_ACTION.REGISTER, _types5.METRIC_TYPE.BEHAVIORAL, _constants.REGISTRATION_UTIL, 'PRIMARY', 'webex-js-sdk_06bafdd0-2f9b-4cd7-b438-9c0d95ecec9b_15', undefined, undefined);
176
189
  case 2:
@@ -218,6 +231,9 @@ describe('Registration Tests', function () {
218
231
  devices: [_registerFixtures.mockPostResponse.device]
219
232
  },
220
233
  statusCode: 403
234
+ }).mockResolvedValueOnce({
235
+ statusCode: 200,
236
+ body: _registerFixtures.mockDeleteResponse
221
237
  }).mockResolvedValueOnce({
222
238
  statusCode: 200,
223
239
  body: _registerFixtures.mockPostResponse,
@@ -225,25 +241,18 @@ describe('Registration Tests', function () {
225
241
  trackingid: 'webex-js-sdk_06bafdd0-2f9b-4cd7-b438-9c0d95ecec9b_15'
226
242
  }
227
243
  });
228
- global.fetch = jest.fn(function () {
229
- return _promise.default.resolve({
230
- json: function json() {
231
- return _registerFixtures.mockDeleteResponse;
232
- }
233
- });
234
- });
235
244
  expect(reg.getStatus()).toEqual(_types.RegistrationStatus.IDLE);
236
245
  _context3.next = 1;
237
246
  return reg.triggerRegistration();
238
247
  case 1:
239
- expect(webex.request).toBeCalledTimes(2);
248
+ expect(webex.request).toBeCalledTimes(3);
240
249
  expect(webex.request).toBeCalledWith(_objectSpread(_objectSpread({}, mockResponse), {}, {
241
250
  method: 'POST'
242
251
  }));
243
- expect(global.fetch).toBeCalledOnceWith(_registerFixtures.mockPostResponse.device.uri, {
244
- method: 'DELETE',
245
- headers: expect.anything()
246
- });
252
+ expect(webex.request).toBeCalledWith(expect.objectContaining({
253
+ uri: _registerFixtures.mockPostResponse.device.uri,
254
+ method: 'DELETE'
255
+ }));
247
256
  expect(warnSpy).toBeCalledWith('User device limit exceeded', expect.anything());
248
257
  expect(infoSpy).toBeCalledWith('Registration restoration in progress.', expect.anything());
249
258
  expect(infoSpy).toBeCalledWith('Registration restored successfully.', expect.anything());
@@ -1277,11 +1286,8 @@ describe('Registration Tests', function () {
1277
1286
  expect(reg.webWorker).toBeDefined();
1278
1287
  expect(postMessageSpy).toHaveBeenCalledWith(expect.objectContaining({
1279
1288
  type: 'START_KEEPALIVE',
1280
- accessToken: expect.any(String),
1281
- deviceUrl: expect.any(String),
1282
1289
  interval: expect.any(Number),
1283
- retryCountThreshold: expect.any(Number),
1284
- url: expect.any(String)
1290
+ retryCountThreshold: expect.any(Number)
1285
1291
  }));
1286
1292
  reg.webWorker.onmessage({
1287
1293
  data: {
@@ -1690,7 +1696,7 @@ describe('Registration Tests', function () {
1690
1696
  })));
1691
1697
  it('checks for keep-alive failure with 429', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee35() {
1692
1698
  var _reg$deviceInfo$devic;
1693
- var keepaliveSpy, postMessageSpy, clearTimerSpy, retry429Spy;
1699
+ var keepaliveSpy, postMessageSpy, clearTimerSpy, retry429Spy, keepaliveInterval, retryAfter, adjustedResumeDelayMs;
1694
1700
  return _regenerator.default.wrap(function (_context35) {
1695
1701
  while (1) switch (_context35.prev = _context35.next) {
1696
1702
  case 0:
@@ -1701,13 +1707,17 @@ describe('Registration Tests', function () {
1701
1707
  postMessageSpy = jest.spyOn(Worker.prototype, 'postMessage');
1702
1708
  clearTimerSpy = jest.spyOn(reg, 'clearKeepaliveTimer');
1703
1709
  retry429Spy = jest.spyOn(reg, 'handle429Retry');
1710
+ keepaliveInterval = reg.deviceInfo.keepaliveInterval; // Choose a retryAfter strictly greater than keepaliveInterval so the
1711
+ // adjusted resume delay (retryAfter - keepaliveInterval) is positive and verifiable.
1712
+ retryAfter = keepaliveInterval + 30;
1713
+ adjustedResumeDelayMs = (retryAfter - keepaliveInterval) * _constants.SEC_TO_MSEC_MFACTOR;
1704
1714
  reg.webWorker.onmessage({
1705
1715
  data: {
1706
1716
  type: _types.WorkerMessageType.KEEPALIVE_FAILURE,
1707
1717
  err: {
1708
1718
  statusCode: 429,
1709
1719
  headers: {
1710
- 'retry-after': 20
1720
+ 'retry-after': retryAfter
1711
1721
  }
1712
1722
  },
1713
1723
  keepAliveRetryCount: 1
@@ -1723,47 +1733,112 @@ describe('Registration Tests', function () {
1723
1733
  expect(handleErrorSpy).toBeCalledOnceWith({
1724
1734
  statusCode: 429,
1725
1735
  headers: {
1726
- 'retry-after': 20
1736
+ 'retry-after': retryAfter
1727
1737
  }
1728
1738
  }, expect.anything(), {
1729
1739
  file: _constants.REGISTRATION_FILE,
1730
1740
  method: _constants.KEEPALIVE_UTIL
1731
1741
  }, expect.anything());
1732
- expect(retry429Spy).toBeCalledOnceWith(20, 'startKeepaliveTimer');
1742
+ expect(retry429Spy).toBeCalledOnceWith(retryAfter, 'startKeepaliveTimer');
1733
1743
  expect(clearTimerSpy).toBeCalledTimes(1);
1734
1744
  expect(reg.reconnectPending).toStrictEqual(false);
1735
1745
  expect(reg.keepaliveTimer).toBe(undefined);
1736
1746
  expect(reg.webWorker).toBeUndefined();
1737
- jest.advanceTimersByTime(20 * _constants.SEC_TO_MSEC_MFACTOR);
1747
+
1748
+ // Resume timer must NOT fire before the adjusted (retryAfter - keepaliveInterval) interval.
1749
+ jest.advanceTimersByTime(adjustedResumeDelayMs - 1);
1738
1750
  _context35.next = 3;
1739
1751
  return flushPromises();
1740
1752
  case 3:
1741
- expect(keepaliveSpy).toBeCalledOnceWith((_reg$deviceInfo$devic = reg.deviceInfo.device) === null || _reg$deviceInfo$devic === void 0 ? void 0 : _reg$deviceInfo$devic.uri, reg.deviceInfo.keepaliveInterval, 'UNKNOWN');
1742
- expect(logSpy).toBeCalledWith('Resuming keepalive after 20 seconds', {
1753
+ expect(keepaliveSpy).not.toBeCalled();
1754
+ expect(reg.webWorker).toBeUndefined();
1755
+
1756
+ // Advance the remaining 1ms to hit the exact adjusted timeout; keepalive must resume now.
1757
+ jest.advanceTimersByTime(1);
1758
+ _context35.next = 4;
1759
+ return flushPromises();
1760
+ case 4:
1761
+ expect(keepaliveSpy).toBeCalledOnceWith((_reg$deviceInfo$devic = reg.deviceInfo.device) === null || _reg$deviceInfo$devic === void 0 ? void 0 : _reg$deviceInfo$devic.uri, keepaliveInterval, 'UNKNOWN');
1762
+ expect(logSpy).toBeCalledWith("Resuming keepalive after ".concat(retryAfter, " seconds"), {
1743
1763
  file: _constants.REGISTRATION_FILE,
1744
1764
  method: 'handle429Retry'
1745
1765
  });
1746
1766
  expect(reg.webWorker).toBeDefined();
1747
1767
  expect(postMessageSpy).toHaveBeenCalledWith(expect.objectContaining({
1748
1768
  type: 'START_KEEPALIVE',
1749
- accessToken: expect.any(String),
1750
- deviceUrl: expect.any(String),
1751
1769
  interval: expect.any(Number),
1752
- retryCountThreshold: expect.any(Number),
1753
- url: expect.any(String)
1770
+ retryCountThreshold: expect.any(Number)
1754
1771
  }));
1755
- case 4:
1772
+ case 5:
1756
1773
  case "end":
1757
1774
  return _context35.stop();
1758
1775
  }
1759
1776
  }, _callee35);
1760
1777
  })));
1761
- it('ensure retryAfter is set when 429 occurs during failover retry', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee36() {
1778
+ it.each([{
1779
+ description: 'retryAfter less than keepaliveInterval -> negative delay fires immediately',
1780
+ retryAfterDelta: -10
1781
+ }, {
1782
+ description: 'retryAfter equal to keepaliveInterval -> zero delay fires immediately',
1783
+ retryAfterDelta: 0
1784
+ }])('adjusts retry-after with keepaliveInterval on 429 keepalive failure ($description)', /*#__PURE__*/function () {
1785
+ var _ref37 = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee36(_ref36) {
1786
+ var _reg$deviceInfo$devic2;
1787
+ var retryAfterDelta, keepaliveSpy, keepaliveInterval, retryAfter;
1788
+ return _regenerator.default.wrap(function (_context36) {
1789
+ while (1) switch (_context36.prev = _context36.next) {
1790
+ case 0:
1791
+ retryAfterDelta = _ref36.retryAfterDelta;
1792
+ _context36.next = 1;
1793
+ return beforeEachSetupForKeepalive();
1794
+ case 1:
1795
+ keepaliveSpy = jest.spyOn(reg, 'startKeepaliveTimer');
1796
+ keepaliveInterval = reg.deviceInfo.keepaliveInterval;
1797
+ retryAfter = keepaliveInterval + retryAfterDelta;
1798
+ reg.webWorker.onmessage({
1799
+ data: {
1800
+ type: _types.WorkerMessageType.KEEPALIVE_FAILURE,
1801
+ err: {
1802
+ statusCode: 429,
1803
+ headers: {
1804
+ 'retry-after': retryAfter
1805
+ }
1806
+ },
1807
+ keepAliveRetryCount: 1
1808
+ }
1809
+ });
1810
+ _context36.next = 2;
1811
+ return flushPromises();
1812
+ case 2:
1813
+ expect(reg.webWorker).toBeUndefined();
1814
+ expect(keepaliveSpy).not.toBeCalled();
1815
+
1816
+ // With a non-positive adjusted delay, the timer should fire on the next tick.
1817
+ jest.advanceTimersByTime(0);
1818
+ _context36.next = 3;
1819
+ return flushPromises();
1820
+ case 3:
1821
+ expect(keepaliveSpy).toBeCalledOnceWith((_reg$deviceInfo$devic2 = reg.deviceInfo.device) === null || _reg$deviceInfo$devic2 === void 0 ? void 0 : _reg$deviceInfo$devic2.uri, keepaliveInterval, 'UNKNOWN');
1822
+ expect(logSpy).toBeCalledWith("Resuming keepalive after ".concat(retryAfter, " seconds"), {
1823
+ file: _constants.REGISTRATION_FILE,
1824
+ method: 'handle429Retry'
1825
+ });
1826
+ case 4:
1827
+ case "end":
1828
+ return _context36.stop();
1829
+ }
1830
+ }, _callee36);
1831
+ }));
1832
+ return function (_x) {
1833
+ return _ref37.apply(this, arguments);
1834
+ };
1835
+ }());
1836
+ it('ensure retryAfter is set when 429 occurs during failover retry', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee37() {
1762
1837
  var retry429Spy;
1763
- return _regenerator.default.wrap(function (_context36) {
1764
- while (1) switch (_context36.prev = _context36.next) {
1838
+ return _regenerator.default.wrap(function (_context37) {
1839
+ while (1) switch (_context37.prev = _context37.next) {
1765
1840
  case 0:
1766
- _context36.next = 1;
1841
+ _context37.next = 1;
1767
1842
  return beforeEachSetupForKeepalive();
1768
1843
  case 1:
1769
1844
  // Simulate loss of registration so failover path attempts a new registration
@@ -1774,11 +1849,11 @@ describe('Registration Tests', function () {
1774
1849
  webex.request.mockRejectedValueOnce(failurePayload429One);
1775
1850
 
1776
1851
  // Directly schedule the failover attempt
1777
- _context36.next = 2;
1852
+ _context37.next = 2;
1778
1853
  return reg.startFailoverTimer();
1779
1854
  case 2:
1780
1855
  jest.advanceTimersByTime(33 * _constants.SEC_TO_MSEC_MFACTOR);
1781
- _context36.next = 3;
1856
+ _context37.next = 3;
1782
1857
  return flushPromises();
1783
1858
  case 3:
1784
1859
  expect(retry429Spy).toBeCalledWith(failurePayload429One.headers['retry-after'], 'startFailoverTimer');
@@ -1786,16 +1861,16 @@ describe('Registration Tests', function () {
1786
1861
  jest.useRealTimers();
1787
1862
  case 4:
1788
1863
  case "end":
1789
- return _context36.stop();
1864
+ return _context37.stop();
1790
1865
  }
1791
- }, _callee36);
1866
+ }, _callee37);
1792
1867
  })));
1793
- it('sets retryAfter when reconnectOnFailure caller receives 429 after keepalive threshold miss', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee37() {
1868
+ it('sets retryAfter when reconnectOnFailure caller receives 429 after keepalive threshold miss', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee38() {
1794
1869
  var retry429Spy, threshold;
1795
- return _regenerator.default.wrap(function (_context37) {
1796
- while (1) switch (_context37.prev = _context37.next) {
1870
+ return _regenerator.default.wrap(function (_context38) {
1871
+ while (1) switch (_context38.prev = _context38.next) {
1797
1872
  case 0:
1798
- _context37.next = 1;
1873
+ _context38.next = 1;
1799
1874
  return beforeEachSetupForKeepalive();
1800
1875
  case 1:
1801
1876
  retry429Spy = jest.spyOn(reg, 'handle429Retry'); // On reconnectOnFailure(RECONNECT_ON_FAILURE_UTIL) first restore attempt, make registration respond with 429 (retry-after: 20)
@@ -1818,7 +1893,7 @@ describe('Registration Tests', function () {
1818
1893
  keepAliveRetryCount: threshold
1819
1894
  }
1820
1895
  });
1821
- _context37.next = 2;
1896
+ _context38.next = 2;
1822
1897
  return flushPromises();
1823
1898
  case 2:
1824
1899
  // handle429Retry is called with caller 'reconnectOnFailure' → else branch executes and sets retryAfter
@@ -1826,25 +1901,25 @@ describe('Registration Tests', function () {
1826
1901
  expect(reg.retryAfter).toEqual(undefined); // Clear retryAfter after 429 retry
1827
1902
  case 3:
1828
1903
  case "end":
1829
- return _context37.stop();
1904
+ return _context38.stop();
1830
1905
  }
1831
- }, _callee37);
1906
+ }, _callee38);
1832
1907
  })));
1833
1908
  });
1834
1909
  describe('Primary server status checks', function () {
1835
- it('success: primary server status to be up', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee38() {
1910
+ it('success: primary server status to be up', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee39() {
1836
1911
  var pingSuccessPayload, status;
1837
- return _regenerator.default.wrap(function (_context38) {
1838
- while (1) switch (_context38.prev = _context38.next) {
1912
+ return _regenerator.default.wrap(function (_context39) {
1913
+ while (1) switch (_context39.prev = _context39.next) {
1839
1914
  case 0:
1840
1915
  pingSuccessPayload = {
1841
1916
  statusCode: 200
1842
1917
  };
1843
1918
  webex.request.mockResolvedValue(pingSuccessPayload);
1844
- _context38.next = 1;
1919
+ _context39.next = 1;
1845
1920
  return reg.isPrimaryActive();
1846
1921
  case 1:
1847
- status = _context38.sent;
1922
+ status = _context39.sent;
1848
1923
  expect(webex.request).toBeCalledWith(_objectSpread({
1849
1924
  method: 'GET',
1850
1925
  uri: "https://mobius-dfw.webex.com/api/v1/ping"
@@ -1852,23 +1927,23 @@ describe('Registration Tests', function () {
1852
1927
  expect(status).toEqual(true);
1853
1928
  case 2:
1854
1929
  case "end":
1855
- return _context38.stop();
1930
+ return _context39.stop();
1856
1931
  }
1857
- }, _callee38);
1932
+ }, _callee39);
1858
1933
  })));
1859
- it('failed: primary server status to be down', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee39() {
1934
+ it('failed: primary server status to be down', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee40() {
1860
1935
  var pingFailurePayload, status;
1861
- return _regenerator.default.wrap(function (_context39) {
1862
- while (1) switch (_context39.prev = _context39.next) {
1936
+ return _regenerator.default.wrap(function (_context40) {
1937
+ while (1) switch (_context40.prev = _context40.next) {
1863
1938
  case 0:
1864
1939
  pingFailurePayload = {
1865
1940
  statusCode: 500
1866
1941
  };
1867
1942
  webex.request.mockResolvedValue(pingFailurePayload);
1868
- _context39.next = 1;
1943
+ _context40.next = 1;
1869
1944
  return reg.isPrimaryActive();
1870
1945
  case 1:
1871
- status = _context39.sent;
1946
+ status = _context40.sent;
1872
1947
  expect(webex.request).toBeCalledWith(_objectSpread({
1873
1948
  method: 'GET',
1874
1949
  uri: "https://mobius-dfw.webex.com/api/v1/ping"
@@ -1876,9 +1951,187 @@ describe('Registration Tests', function () {
1876
1951
  expect(status).toEqual(false);
1877
1952
  case 2:
1878
1953
  case "end":
1879
- return _context39.stop();
1954
+ return _context40.stop();
1880
1955
  }
1881
- }, _callee39);
1956
+ }, _callee40);
1957
+ })));
1958
+ });
1959
+ describe('handleRegistrationDownEvent tests', function () {
1960
+ var registrationDownEvent = {
1961
+ type: 'async_event',
1962
+ eventId: 'evt-1',
1963
+ trackingId: 'tid-1',
1964
+ data: {
1965
+ eventType: 'registration.down',
1966
+ deviceInfo: {
1967
+ userId: 'u1',
1968
+ device: {
1969
+ deviceId: 'd1',
1970
+ uri: 'https://mobius/device/d1',
1971
+ status: 'ACTIVE'
1972
+ }
1973
+ }
1974
+ }
1975
+ };
1976
+ beforeEach(/*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee41() {
1977
+ return _regenerator.default.wrap(function (_context41) {
1978
+ while (1) switch (_context41.prev = _context41.next) {
1979
+ case 0:
1980
+ postRegistrationSpy.mockResolvedValueOnce(successPayload);
1981
+ _context41.next = 1;
1982
+ return reg.triggerRegistration();
1983
+ case 1:
1984
+ expect(reg.getStatus()).toBe(_types.RegistrationStatus.ACTIVE);
1985
+ case 2:
1986
+ case "end":
1987
+ return _context41.stop();
1988
+ }
1989
+ }, _callee41);
1990
+ })));
1991
+ afterEach(function () {
1992
+ var calls = (0, _values.default)(reg.callManager.getActiveCalls());
1993
+ calls.forEach(function (call) {
1994
+ call.end();
1995
+ });
1996
+ reg.callManager.callCollection = {};
1997
+ });
1998
+ it('runs cleanup immediately when no active calls are present (socket disabled)', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee42() {
1999
+ var clearKeepaliveSpy, setStatusSpy, disconnectSocketSpy;
2000
+ return _regenerator.default.wrap(function (_context42) {
2001
+ while (1) switch (_context42.prev = _context42.next) {
2002
+ case 0:
2003
+ clearKeepaliveSpy = jest.spyOn(reg, 'clearKeepaliveTimer');
2004
+ setStatusSpy = jest.spyOn(reg, 'setStatus');
2005
+ disconnectSocketSpy = jest.spyOn(_request.APIRequest.getInstance({
2006
+ webex: webex
2007
+ }), 'disconnectFromMobiusSocket');
2008
+ lineEmitter.mockClear();
2009
+ expect((0, _keys.default)(reg.callManager.getActiveCalls()).length).toBe(0);
2010
+ _context42.next = 1;
2011
+ return reg.handleRegistrationDownEvent(registrationDownEvent);
2012
+ case 1:
2013
+ expect(clearKeepaliveSpy).toHaveBeenCalled();
2014
+ expect(setStatusSpy).toHaveBeenCalledWith(_types.RegistrationStatus.INACTIVE);
2015
+ expect(reg.getStatus()).toBe(_types.RegistrationStatus.INACTIVE);
2016
+ expect(reg.reconnectPending).toBe(false);
2017
+ expect(reg.scheduled429Retry).toBe(false);
2018
+ expect(reg.failoverImmediately).toBe(false);
2019
+ expect(reg.retryAfter).toBeUndefined();
2020
+ expect(reg.registerRetry).toBe(false);
2021
+ expect(disconnectSocketSpy).not.toHaveBeenCalled();
2022
+ expect(lineEmitter).toHaveBeenCalledWith(_types4.LINE_EVENTS.UNREGISTERED);
2023
+ case 2:
2024
+ case "end":
2025
+ return _context42.stop();
2026
+ }
2027
+ }, _callee42);
2028
+ })));
2029
+ it('ends the active call and still runs cleanup when an active call is present', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee43() {
2030
+ var clearKeepaliveSpy, setStatusSpy, activeCall, endSpy;
2031
+ return _regenerator.default.wrap(function (_context43) {
2032
+ while (1) switch (_context43.prev = _context43.next) {
2033
+ case 0:
2034
+ clearKeepaliveSpy = jest.spyOn(reg, 'clearKeepaliveTimer');
2035
+ setStatusSpy = jest.spyOn(reg, 'setStatus');
2036
+ activeCall = reg.callManager.createCall();
2037
+ endSpy = jest.spyOn(activeCall, 'end');
2038
+ expect((0, _keys.default)(reg.callManager.getActiveCalls()).length).toBe(1);
2039
+ lineEmitter.mockClear();
2040
+ _context43.next = 1;
2041
+ return reg.handleRegistrationDownEvent(registrationDownEvent);
2042
+ case 1:
2043
+ expect(endSpy).toHaveBeenCalledTimes(1);
2044
+ expect(clearKeepaliveSpy).toHaveBeenCalled();
2045
+ expect(setStatusSpy).toHaveBeenCalledWith(_types.RegistrationStatus.INACTIVE);
2046
+ expect(reg.getStatus()).toBe(_types.RegistrationStatus.INACTIVE);
2047
+ expect(lineEmitter).toHaveBeenCalledWith(_types4.LINE_EVENTS.UNREGISTERED);
2048
+ case 2:
2049
+ case "end":
2050
+ return _context43.stop();
2051
+ }
2052
+ }, _callee43);
2053
+ })));
2054
+ it('runs cleanup without calling end when no active call is present on re-invocation', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee44() {
2055
+ var clearKeepaliveSpy, setStatusSpy;
2056
+ return _regenerator.default.wrap(function (_context44) {
2057
+ while (1) switch (_context44.prev = _context44.next) {
2058
+ case 0:
2059
+ clearKeepaliveSpy = jest.spyOn(reg, 'clearKeepaliveTimer');
2060
+ setStatusSpy = jest.spyOn(reg, 'setStatus');
2061
+ _context44.next = 1;
2062
+ return reg.handleRegistrationDownEvent(registrationDownEvent);
2063
+ case 1:
2064
+ expect(reg.getStatus()).toBe(_types.RegistrationStatus.INACTIVE);
2065
+ clearKeepaliveSpy.mockClear();
2066
+ setStatusSpy.mockClear();
2067
+ lineEmitter.mockClear();
2068
+ expect((0, _keys.default)(reg.callManager.getActiveCalls()).length).toBe(0);
2069
+ _context44.next = 2;
2070
+ return reg.handleRegistrationDownEvent(registrationDownEvent);
2071
+ case 2:
2072
+ expect(clearKeepaliveSpy).toHaveBeenCalled();
2073
+ expect(setStatusSpy).toHaveBeenCalledWith(_types.RegistrationStatus.INACTIVE);
2074
+ expect(reg.getStatus()).toBe(_types.RegistrationStatus.INACTIVE);
2075
+ expect(lineEmitter).toHaveBeenCalledWith(_types4.LINE_EVENTS.UNREGISTERED);
2076
+ case 3:
2077
+ case "end":
2078
+ return _context44.stop();
2079
+ }
2080
+ }, _callee44);
2081
+ })));
2082
+ it('disconnects the Mobius WebSocket when socket is enabled', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee45() {
2083
+ var apiRequest, disconnectSocketSpy;
2084
+ return _regenerator.default.wrap(function (_context45) {
2085
+ while (1) switch (_context45.prev = _context45.next) {
2086
+ case 0:
2087
+ apiRequest = _request.APIRequest.getInstance({
2088
+ webex: webex
2089
+ });
2090
+ jest.spyOn(apiRequest, 'isSocketEnabled').mockReturnValue(true);
2091
+ disconnectSocketSpy = jest.spyOn(apiRequest, 'disconnectFromMobiusSocket').mockResolvedValue();
2092
+ lineEmitter.mockClear();
2093
+ expect((0, _keys.default)(reg.callManager.getActiveCalls()).length).toBe(0);
2094
+ _context45.next = 1;
2095
+ return reg.handleRegistrationDownEvent(registrationDownEvent);
2096
+ case 1:
2097
+ expect(disconnectSocketSpy).toHaveBeenCalledWith({
2098
+ code: 3050,
2099
+ reason: 'done (permanent)'
2100
+ });
2101
+ expect(reg.getStatus()).toBe(_types.RegistrationStatus.INACTIVE);
2102
+ expect(lineEmitter).toHaveBeenCalledWith(_types4.LINE_EVENTS.UNREGISTERED);
2103
+ case 2:
2104
+ case "end":
2105
+ return _context45.stop();
2106
+ }
2107
+ }, _callee45);
2108
+ })));
2109
+ it('still emits UNREGISTERED when socket disconnect fails', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee46() {
2110
+ var apiRequest, disconnectSocketSpy;
2111
+ return _regenerator.default.wrap(function (_context46) {
2112
+ while (1) switch (_context46.prev = _context46.next) {
2113
+ case 0:
2114
+ apiRequest = _request.APIRequest.getInstance({
2115
+ webex: webex
2116
+ });
2117
+ jest.spyOn(apiRequest, 'isSocketEnabled').mockReturnValue(true);
2118
+ disconnectSocketSpy = jest.spyOn(apiRequest, 'disconnectFromMobiusSocket').mockRejectedValue(new Error('socket teardown failed'));
2119
+ lineEmitter.mockClear();
2120
+ _context46.next = 1;
2121
+ return reg.handleRegistrationDownEvent(registrationDownEvent);
2122
+ case 1:
2123
+ expect(disconnectSocketSpy).toHaveBeenCalled();
2124
+ expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('Mobius socket disconnect failed after registration-down'), {
2125
+ file: _constants.REGISTRATION_FILE,
2126
+ method: _constants.METHODS.HANDLE_REGISTRATION_DOWN_EVENT
2127
+ });
2128
+ expect(reg.getStatus()).toBe(_types.RegistrationStatus.INACTIVE);
2129
+ expect(lineEmitter).toHaveBeenCalledWith(_types4.LINE_EVENTS.UNREGISTERED);
2130
+ case 2:
2131
+ case "end":
2132
+ return _context46.stop();
2133
+ }
2134
+ }, _callee46);
1882
2135
  })));
1883
2136
  });
1884
2137
  });