@webex/calling 3.12.0-next.1 → 3.12.0-next.100

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 (263) hide show
  1. package/dist/CallRecording/CallRecording.js +160 -0
  2. package/dist/CallRecording/CallRecording.js.map +1 -0
  3. package/dist/CallRecording/CallRecording.test.js +257 -0
  4. package/dist/CallRecording/CallRecording.test.js.map +1 -0
  5. package/dist/CallRecording/WxcCallRecordingConnector.js +577 -0
  6. package/dist/CallRecording/WxcCallRecordingConnector.js.map +1 -0
  7. package/dist/CallRecording/WxcCallRecordingConnector.test.js +652 -0
  8. package/dist/CallRecording/WxcCallRecordingConnector.test.js.map +1 -0
  9. package/dist/CallRecording/callRecordingFixtures.js +235 -0
  10. package/dist/CallRecording/callRecordingFixtures.js.map +1 -0
  11. package/dist/CallRecording/constants.js +50 -0
  12. package/dist/CallRecording/constants.js.map +1 -0
  13. package/dist/CallRecording/types.js +137 -0
  14. package/dist/CallRecording/types.js.map +1 -0
  15. package/dist/CallRecording/utils.js +42 -0
  16. package/dist/CallRecording/utils.js.map +1 -0
  17. package/dist/CallRecording/utils.test.js +97 -0
  18. package/dist/CallRecording/utils.test.js.map +1 -0
  19. package/dist/CallingClient/CallingClient.js +456 -226
  20. package/dist/CallingClient/CallingClient.js.map +1 -1
  21. package/dist/CallingClient/CallingClient.test.js +513 -154
  22. package/dist/CallingClient/CallingClient.test.js.map +1 -1
  23. package/dist/CallingClient/calling/call.js +635 -455
  24. package/dist/CallingClient/calling/call.js.map +1 -1
  25. package/dist/CallingClient/calling/call.test.js +874 -484
  26. package/dist/CallingClient/calling/call.test.js.map +1 -1
  27. package/dist/CallingClient/calling/callManager.js +106 -35
  28. package/dist/CallingClient/calling/callManager.js.map +1 -1
  29. package/dist/CallingClient/calling/callManager.test.js +140 -0
  30. package/dist/CallingClient/calling/callManager.test.js.map +1 -1
  31. package/dist/CallingClient/calling/types.js +5 -0
  32. package/dist/CallingClient/calling/types.js.map +1 -1
  33. package/dist/CallingClient/constants.js +32 -3
  34. package/dist/CallingClient/constants.js.map +1 -1
  35. package/dist/CallingClient/line/index.js +8 -1
  36. package/dist/CallingClient/line/index.js.map +1 -1
  37. package/dist/CallingClient/line/line.test.js +62 -10
  38. package/dist/CallingClient/line/line.test.js.map +1 -1
  39. package/dist/CallingClient/registration/register.js +967 -504
  40. package/dist/CallingClient/registration/register.js.map +1 -1
  41. package/dist/CallingClient/registration/register.test.js +936 -59
  42. package/dist/CallingClient/registration/register.test.js.map +1 -1
  43. package/dist/CallingClient/registration/types.js +26 -0
  44. package/dist/CallingClient/registration/types.js.map +1 -1
  45. package/dist/CallingClient/registration/webWorker.js +41 -104
  46. package/dist/CallingClient/registration/webWorker.js.map +1 -1
  47. package/dist/CallingClient/registration/webWorker.test.js +39 -153
  48. package/dist/CallingClient/registration/webWorker.test.js.map +1 -1
  49. package/dist/CallingClient/registration/webWorkerStr.js +1 -1
  50. package/dist/CallingClient/registration/webWorkerStr.js.map +1 -1
  51. package/dist/CallingClient/types.js +7 -0
  52. package/dist/CallingClient/types.js.map +1 -1
  53. package/dist/CallingClient/utils/constants.js +58 -0
  54. package/dist/CallingClient/utils/constants.js.map +1 -0
  55. package/dist/CallingClient/utils/index.js +63 -0
  56. package/dist/CallingClient/utils/index.js.map +1 -0
  57. package/dist/CallingClient/utils/mobiusSocketMapper.js +122 -0
  58. package/dist/CallingClient/utils/mobiusSocketMapper.js.map +1 -0
  59. package/dist/CallingClient/utils/mobiusSocketMapper.test.js +221 -0
  60. package/dist/CallingClient/utils/mobiusSocketMapper.test.js.map +1 -0
  61. package/dist/CallingClient/utils/request.js +435 -0
  62. package/dist/CallingClient/utils/request.js.map +1 -0
  63. package/dist/CallingClient/utils/request.test.js +999 -0
  64. package/dist/CallingClient/utils/request.test.js.map +1 -0
  65. package/dist/CallingClient/utils/types.js +7 -0
  66. package/dist/CallingClient/utils/types.js.map +1 -0
  67. package/dist/CallingClient/utils/wsFeatureFlag.js +70 -0
  68. package/dist/CallingClient/utils/wsFeatureFlag.js.map +1 -0
  69. package/dist/CallingClient/utils/wsFeatureFlag.test.js +139 -0
  70. package/dist/CallingClient/utils/wsFeatureFlag.test.js.map +1 -0
  71. package/dist/Contacts/ContactsClient.js +13 -11
  72. package/dist/Contacts/ContactsClient.js.map +1 -1
  73. package/dist/Contacts/ContactsClient.test.js +3 -8
  74. package/dist/Contacts/ContactsClient.test.js.map +1 -1
  75. package/dist/Errors/types.js +2 -0
  76. package/dist/Errors/types.js.map +1 -1
  77. package/dist/Events/types.js +38 -11
  78. package/dist/Events/types.js.map +1 -1
  79. package/dist/Metrics/index.js +63 -2
  80. package/dist/Metrics/index.js.map +1 -1
  81. package/dist/Metrics/index.test.js +357 -1
  82. package/dist/Metrics/index.test.js.map +1 -1
  83. package/dist/Metrics/types.js +19 -1
  84. package/dist/Metrics/types.js.map +1 -1
  85. package/dist/SDKConnector/types.js.map +1 -1
  86. package/dist/api.js +56 -0
  87. package/dist/api.js.map +1 -1
  88. package/dist/common/Utils.js +198 -68
  89. package/dist/common/Utils.js.map +1 -1
  90. package/dist/common/Utils.test.js +414 -181
  91. package/dist/common/Utils.test.js.map +1 -1
  92. package/dist/common/testUtil.js +10 -5
  93. package/dist/common/testUtil.js.map +1 -1
  94. package/dist/common/types.js +3 -0
  95. package/dist/common/types.js.map +1 -1
  96. package/dist/index.js +171 -40
  97. package/dist/index.js.map +1 -1
  98. package/dist/mobius-socket/config.js +24 -0
  99. package/dist/mobius-socket/config.js.map +1 -0
  100. package/dist/mobius-socket/errors.js +143 -0
  101. package/dist/mobius-socket/errors.js.map +1 -0
  102. package/dist/mobius-socket/errors.test.js +20 -0
  103. package/dist/mobius-socket/errors.test.js.map +1 -0
  104. package/dist/mobius-socket/index.js +57 -0
  105. package/dist/mobius-socket/index.js.map +1 -0
  106. package/dist/mobius-socket/mobius-socket-events.test.js +492 -0
  107. package/dist/mobius-socket/mobius-socket-events.test.js.map +1 -0
  108. package/dist/mobius-socket/mobius-socket.js +849 -0
  109. package/dist/mobius-socket/mobius-socket.js.map +1 -0
  110. package/dist/mobius-socket/mobius-socket.test.js +1898 -0
  111. package/dist/mobius-socket/mobius-socket.test.js.map +1 -0
  112. package/dist/mobius-socket/socket/constants.js +55 -0
  113. package/dist/mobius-socket/socket/constants.js.map +1 -0
  114. package/dist/mobius-socket/socket/index.js +15 -0
  115. package/dist/mobius-socket/socket/index.js.map +1 -0
  116. package/dist/mobius-socket/socket/socket-base.js +604 -0
  117. package/dist/mobius-socket/socket/socket-base.js.map +1 -0
  118. package/dist/mobius-socket/socket/socket.js +19 -0
  119. package/dist/mobius-socket/socket/socket.js.map +1 -0
  120. package/dist/mobius-socket/socket/socket.shim.js +26 -0
  121. package/dist/mobius-socket/socket/socket.shim.js.map +1 -0
  122. package/dist/mobius-socket/socket/types.js +7 -0
  123. package/dist/mobius-socket/socket/types.js.map +1 -0
  124. package/dist/mobius-socket/socket.test.js +727 -0
  125. package/dist/mobius-socket/socket.test.js.map +1 -0
  126. package/dist/mobius-socket/test/mocha-helpers.js +23 -0
  127. package/dist/mobius-socket/test/mocha-helpers.js.map +1 -0
  128. package/dist/mobius-socket/test/promise-tick.js +28 -0
  129. package/dist/mobius-socket/test/promise-tick.js.map +1 -0
  130. package/dist/mobius-socket/types.js +7 -0
  131. package/dist/mobius-socket/types.js.map +1 -0
  132. package/dist/module/CallRecording/CallRecording.js +56 -0
  133. package/dist/module/CallRecording/WxcCallRecordingConnector.js +257 -0
  134. package/dist/module/CallRecording/callRecordingFixtures.js +201 -0
  135. package/dist/module/CallRecording/constants.js +28 -0
  136. package/dist/module/CallRecording/types.js +19 -0
  137. package/dist/module/CallRecording/utils.js +14 -0
  138. package/dist/module/CallingClient/CallingClient.js +126 -10
  139. package/dist/module/CallingClient/calling/call.js +201 -67
  140. package/dist/module/CallingClient/calling/callManager.js +51 -11
  141. package/dist/module/CallingClient/calling/types.js +2 -0
  142. package/dist/module/CallingClient/constants.js +27 -0
  143. package/dist/module/CallingClient/line/index.js +4 -2
  144. package/dist/module/CallingClient/registration/register.js +294 -67
  145. package/dist/module/CallingClient/registration/types.js +5 -1
  146. package/dist/module/CallingClient/registration/webWorker.js +42 -61
  147. package/dist/module/CallingClient/registration/webWorkerStr.js +47 -82
  148. package/dist/module/CallingClient/utils/constants.js +36 -0
  149. package/dist/module/CallingClient/utils/index.js +5 -0
  150. package/dist/module/CallingClient/utils/mobiusSocketMapper.js +72 -0
  151. package/dist/module/CallingClient/utils/request.js +211 -0
  152. package/dist/module/CallingClient/utils/types.js +1 -0
  153. package/dist/module/CallingClient/utils/wsFeatureFlag.js +41 -0
  154. package/dist/module/Contacts/ContactsClient.js +1 -1
  155. package/dist/module/Errors/types.js +2 -0
  156. package/dist/module/Events/types.js +23 -10
  157. package/dist/module/Metrics/index.js +48 -1
  158. package/dist/module/Metrics/types.js +18 -0
  159. package/dist/module/api.js +3 -2
  160. package/dist/module/common/Utils.js +77 -19
  161. package/dist/module/common/testUtil.js +6 -1
  162. package/dist/module/common/types.js +3 -0
  163. package/dist/module/index.js +7 -3
  164. package/dist/module/mobius-socket/config.js +15 -0
  165. package/dist/module/mobius-socket/errors.js +58 -0
  166. package/dist/module/mobius-socket/index.js +24 -0
  167. package/dist/module/mobius-socket/mobius-socket.js +593 -0
  168. package/dist/module/mobius-socket/socket/constants.js +26 -0
  169. package/dist/module/mobius-socket/socket/index.js +4 -0
  170. package/dist/module/mobius-socket/socket/socket-base.js +368 -0
  171. package/dist/module/mobius-socket/socket/socket.js +9 -0
  172. package/dist/module/mobius-socket/socket/socket.shim.js +12 -0
  173. package/dist/module/mobius-socket/socket/types.js +1 -0
  174. package/dist/module/mobius-socket/types.js +1 -0
  175. package/dist/types/CallRecording/CallRecording.d.ts +18 -0
  176. package/dist/types/CallRecording/CallRecording.d.ts.map +1 -0
  177. package/dist/types/CallRecording/WxcCallRecordingConnector.d.ts +23 -0
  178. package/dist/types/CallRecording/WxcCallRecordingConnector.d.ts.map +1 -0
  179. package/dist/types/CallRecording/callRecordingFixtures.d.ts +61 -0
  180. package/dist/types/CallRecording/callRecordingFixtures.d.ts.map +1 -0
  181. package/dist/types/CallRecording/constants.d.ts +29 -0
  182. package/dist/types/CallRecording/constants.d.ts.map +1 -0
  183. package/dist/types/CallRecording/types.d.ts +176 -0
  184. package/dist/types/CallRecording/types.d.ts.map +1 -0
  185. package/dist/types/CallRecording/utils.d.ts +3 -0
  186. package/dist/types/CallRecording/utils.d.ts.map +1 -0
  187. package/dist/types/CallingClient/CallingClient.d.ts +8 -0
  188. package/dist/types/CallingClient/CallingClient.d.ts.map +1 -1
  189. package/dist/types/CallingClient/calling/call.d.ts +17 -3
  190. package/dist/types/CallingClient/calling/call.d.ts.map +1 -1
  191. package/dist/types/CallingClient/calling/callManager.d.ts +8 -4
  192. package/dist/types/CallingClient/calling/callManager.d.ts.map +1 -1
  193. package/dist/types/CallingClient/calling/types.d.ts +38 -9
  194. package/dist/types/CallingClient/calling/types.d.ts.map +1 -1
  195. package/dist/types/CallingClient/constants.d.ts +27 -0
  196. package/dist/types/CallingClient/constants.d.ts.map +1 -1
  197. package/dist/types/CallingClient/line/index.d.ts +1 -1
  198. package/dist/types/CallingClient/line/index.d.ts.map +1 -1
  199. package/dist/types/CallingClient/registration/register.d.ts +9 -1
  200. package/dist/types/CallingClient/registration/register.d.ts.map +1 -1
  201. package/dist/types/CallingClient/registration/types.d.ts +26 -2
  202. package/dist/types/CallingClient/registration/types.d.ts.map +1 -1
  203. package/dist/types/CallingClient/registration/webWorker.d.ts.map +1 -1
  204. package/dist/types/CallingClient/registration/webWorkerStr.d.ts +1 -1
  205. package/dist/types/CallingClient/registration/webWorkerStr.d.ts.map +1 -1
  206. package/dist/types/CallingClient/types.d.ts +4 -2
  207. package/dist/types/CallingClient/types.d.ts.map +1 -1
  208. package/dist/types/CallingClient/utils/constants.d.ts +35 -0
  209. package/dist/types/CallingClient/utils/constants.d.ts.map +1 -0
  210. package/dist/types/CallingClient/utils/index.d.ts +6 -0
  211. package/dist/types/CallingClient/utils/index.d.ts.map +1 -0
  212. package/dist/types/CallingClient/utils/mobiusSocketMapper.d.ts +5 -0
  213. package/dist/types/CallingClient/utils/mobiusSocketMapper.d.ts.map +1 -0
  214. package/dist/types/CallingClient/utils/request.d.ts +28 -0
  215. package/dist/types/CallingClient/utils/request.d.ts.map +1 -0
  216. package/dist/types/CallingClient/utils/types.d.ts +34 -0
  217. package/dist/types/CallingClient/utils/types.d.ts.map +1 -0
  218. package/dist/types/CallingClient/utils/wsFeatureFlag.d.ts +4 -0
  219. package/dist/types/CallingClient/utils/wsFeatureFlag.d.ts.map +1 -0
  220. package/dist/types/Errors/types.d.ts +2 -0
  221. package/dist/types/Errors/types.d.ts.map +1 -1
  222. package/dist/types/Events/types.d.ts +80 -16
  223. package/dist/types/Events/types.d.ts.map +1 -1
  224. package/dist/types/Metrics/index.d.ts.map +1 -1
  225. package/dist/types/Metrics/types.d.ts +19 -2
  226. package/dist/types/Metrics/types.d.ts.map +1 -1
  227. package/dist/types/SDKConnector/types.d.ts +39 -12
  228. package/dist/types/SDKConnector/types.d.ts.map +1 -1
  229. package/dist/types/api.d.ts +6 -4
  230. package/dist/types/api.d.ts.map +1 -1
  231. package/dist/types/common/Utils.d.ts +9 -4
  232. package/dist/types/common/Utils.d.ts.map +1 -1
  233. package/dist/types/common/testUtil.d.ts +5 -1
  234. package/dist/types/common/testUtil.d.ts.map +1 -1
  235. package/dist/types/common/types.d.ts +5 -1
  236. package/dist/types/common/types.d.ts.map +1 -1
  237. package/dist/types/index.d.ts +9 -4
  238. package/dist/types/index.d.ts.map +1 -1
  239. package/dist/types/mobius-socket/config.d.ts +17 -0
  240. package/dist/types/mobius-socket/config.d.ts.map +1 -0
  241. package/dist/types/mobius-socket/errors.d.ts +32 -0
  242. package/dist/types/mobius-socket/errors.d.ts.map +1 -0
  243. package/dist/types/mobius-socket/index.d.ts +14 -0
  244. package/dist/types/mobius-socket/index.d.ts.map +1 -0
  245. package/dist/types/mobius-socket/mobius-socket.d.ts +48 -0
  246. package/dist/types/mobius-socket/mobius-socket.d.ts.map +1 -0
  247. package/dist/types/mobius-socket/socket/constants.d.ts +27 -0
  248. package/dist/types/mobius-socket/socket/constants.d.ts.map +1 -0
  249. package/dist/types/mobius-socket/socket/index.d.ts +5 -0
  250. package/dist/types/mobius-socket/socket/index.d.ts.map +1 -0
  251. package/dist/types/mobius-socket/socket/socket-base.d.ts +43 -0
  252. package/dist/types/mobius-socket/socket/socket-base.d.ts.map +1 -0
  253. package/dist/types/mobius-socket/socket/socket.d.ts +6 -0
  254. package/dist/types/mobius-socket/socket/socket.d.ts.map +1 -0
  255. package/dist/types/mobius-socket/socket/socket.shim.d.ts +6 -0
  256. package/dist/types/mobius-socket/socket/socket.shim.d.ts.map +1 -0
  257. package/dist/types/mobius-socket/socket/types.d.ts +61 -0
  258. package/dist/types/mobius-socket/socket/types.d.ts.map +1 -0
  259. package/dist/types/mobius-socket/types.d.ts +21 -0
  260. package/dist/types/mobius-socket/types.d.ts.map +1 -0
  261. package/package.json +21 -5
  262. package/src/mobius-socket/socket/socket.shim.ts +22 -0
  263. 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
- 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); }
35
+ var _request = require("../utils/request");
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 _t2 in e) "default" !== _t2 && {}.hasOwnProperty.call(e, _t2) && ((i = (o = _Object$defineProperty) && _Object$getOwnPropertyDescriptor(e, _t2)) && (i.get || i.set) ? o(f, _t2, i) : f[_t2] = e[_t2]); 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,579 @@ 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);
1907
+ })));
1908
+ describe('409 Conflict on keepalive (session superseded)', function () {
1909
+ var conflictError = {
1910
+ statusCode: 409,
1911
+ headers: {
1912
+ trackingid: 'tid-409'
1913
+ }
1914
+ };
1915
+ var sendKeepaliveFailure = /*#__PURE__*/function () {
1916
+ var _ref40 = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee39(err, keepAliveRetryCount) {
1917
+ return _regenerator.default.wrap(function (_context39) {
1918
+ while (1) switch (_context39.prev = _context39.next) {
1919
+ case 0:
1920
+ reg.webWorker.onmessage({
1921
+ data: {
1922
+ type: _types.WorkerMessageType.KEEPALIVE_FAILURE,
1923
+ err: err,
1924
+ keepAliveRetryCount: keepAliveRetryCount
1925
+ }
1926
+ });
1927
+ _context39.next = 1;
1928
+ return flushPromises();
1929
+ case 1:
1930
+ case "end":
1931
+ return _context39.stop();
1932
+ }
1933
+ }, _callee39);
1934
+ }));
1935
+ return function sendKeepaliveFailure(_x2, _x3) {
1936
+ return _ref40.apply(this, arguments);
1937
+ };
1938
+ }();
1939
+ var getSupersededError = function getSupersededError() {
1940
+ var unregisteredCall = lineEmitter.mock.calls.find(function (_ref41) {
1941
+ var _ref42 = (0, _slicedToArray2.default)(_ref41, 1),
1942
+ event = _ref42[0];
1943
+ return event === _types4.LINE_EVENTS.UNREGISTERED;
1944
+ });
1945
+ return unregisteredCall === null || unregisteredCall === void 0 ? void 0 : unregisteredCall[2];
1946
+ };
1947
+ it.each([{
1948
+ description: 'on the very first keepalive failure',
1949
+ keepAliveRetryCount: 1
1950
+ }, {
1951
+ description: 'when the retry count already reached the threshold',
1952
+ keepAliveRetryCount: 5
1953
+ }])('stops keepalive without re-registration $description', /*#__PURE__*/function () {
1954
+ var _ref44 = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee40(_ref43) {
1955
+ var keepAliveRetryCount, clearTimerSpy, reconnectSpy, registerSpy, handle404Spy;
1956
+ return _regenerator.default.wrap(function (_context40) {
1957
+ while (1) switch (_context40.prev = _context40.next) {
1958
+ case 0:
1959
+ keepAliveRetryCount = _ref43.keepAliveRetryCount;
1960
+ _context40.next = 1;
1961
+ return beforeEachSetupForKeepalive();
1962
+ case 1:
1963
+ clearTimerSpy = jest.spyOn(reg, 'clearKeepaliveTimer');
1964
+ reconnectSpy = jest.spyOn(reg, 'reconnectOnFailure');
1965
+ registerSpy = jest.spyOn(reg, 'attemptRegistrationWithServers');
1966
+ handle404Spy = jest.spyOn(reg, 'handle404KeepaliveFailure');
1967
+ lineEmitter.mockClear();
1968
+ _context40.next = 2;
1969
+ return sendKeepaliveFailure(conflictError, keepAliveRetryCount);
1970
+ case 2:
1971
+ // The 409 is classified by the common registration error handler.
1972
+ expect(handleErrorSpy).toHaveBeenCalledWith(conflictError, expect.anything(), {
1973
+ file: _constants.REGISTRATION_FILE,
1974
+ method: _constants.KEEPALIVE_UTIL
1975
+ }, expect.objectContaining({
1976
+ sessionSupersededCb: expect.any(Function)
1977
+ }));
1978
+ expect(warnSpy).toBeCalledWith('409 Conflict: session superseded by another device for this user', {
1979
+ file: _constants.REGISTRATION_FILE,
1980
+ method: _constants.KEEPALIVE_UTIL
1981
+ });
1982
+ expect(warnSpy).toBeCalledWith("Stopping keepalive without re-registration, session superseded by another device for this user - keepaliveRetryCount: ".concat(keepAliveRetryCount), {
1983
+ file: _constants.REGISTRATION_FILE,
1984
+ method: _constants.METHODS.HANDLE_409_KEEPALIVE_FAILURE
1985
+ });
1986
+
1987
+ // Keepalive is stopped and no further keepalive can be sent.
1988
+ expect(clearTimerSpy).toHaveBeenCalled();
1989
+ expect(reg.webWorker).toBeUndefined();
1990
+ expect(reg.getStatus()).toEqual(_types.RegistrationStatus.INACTIVE);
1991
+ expect(reg.failbackTimer).toStrictEqual(undefined);
1992
+
1993
+ // No re-registration of any kind is attempted.
1994
+ expect(reconnectSpy).not.toHaveBeenCalled();
1995
+ expect(restoreSpy).not.toHaveBeenCalled();
1996
+ expect(restartSpy).not.toHaveBeenCalled();
1997
+ expect(failoverSpy).not.toHaveBeenCalled();
1998
+ expect(registerSpy).not.toHaveBeenCalled();
1999
+ expect(handle404Spy).not.toHaveBeenCalled();
2000
+ expect(reg.reconnectPending).toStrictEqual(false);
2001
+ case 3:
2002
+ case "end":
2003
+ return _context40.stop();
2004
+ }
2005
+ }, _callee40);
2006
+ }));
2007
+ return function (_x4) {
2008
+ return _ref44.apply(this, arguments);
2009
+ };
2010
+ }());
2011
+ it('notifies the consumer with a single UNREGISTERED carrying the superseded reason', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee41() {
2012
+ var supersededError;
2013
+ return _regenerator.default.wrap(function (_context41) {
2014
+ while (1) switch (_context41.prev = _context41.next) {
2015
+ case 0:
2016
+ _context41.next = 1;
2017
+ return beforeEachSetupForKeepalive();
2018
+ case 1:
2019
+ lineEmitter.mockClear();
2020
+ _context41.next = 2;
2021
+ return sendKeepaliveFailure(conflictError, 1);
2022
+ case 2:
2023
+ expect(lineEmitter.mock.calls.filter(function (_ref46) {
2024
+ var _ref47 = (0, _slicedToArray2.default)(_ref46, 1),
2025
+ event = _ref47[0];
2026
+ return event === _types4.LINE_EVENTS.UNREGISTERED;
2027
+ })).toHaveLength(1);
2028
+ expect(lineEmitter).not.toHaveBeenCalledWith(_types4.LINE_EVENTS.RECONNECTING);
2029
+ expect(lineEmitter).toHaveBeenLastCalledWith(_types4.LINE_EVENTS.UNREGISTERED, undefined, expect.any(_LineError.LineError));
2030
+ supersededError = getSupersededError();
2031
+ expect(supersededError.getError()).toStrictEqual({
2032
+ message: _constants.SESSION_SUPERSEDED_MESSAGE,
2033
+ type: _types3.ERROR_TYPE.SESSION_SUPERSEDED,
2034
+ status: _types.RegistrationStatus.INACTIVE,
2035
+ context: {
2036
+ file: _constants.REGISTRATION_FILE,
2037
+ method: _constants.KEEPALIVE_UTIL
2038
+ }
2039
+ });
2040
+ case 3:
2041
+ case "end":
2042
+ return _context41.stop();
2043
+ }
2044
+ }, _callee41);
2045
+ })));
2046
+ it('submits the keepalive failure metric and uploads logs', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee42() {
2047
+ var uploadLogsSpy;
2048
+ return _regenerator.default.wrap(function (_context42) {
2049
+ while (1) switch (_context42.prev = _context42.next) {
2050
+ case 0:
2051
+ _context42.next = 1;
2052
+ return beforeEachSetupForKeepalive();
2053
+ case 1:
2054
+ uploadLogsSpy = jest.spyOn(utils, 'uploadLogs');
2055
+ lineEmitter.mockClear();
2056
+ metricSpy.mockClear();
2057
+ _context42.next = 2;
2058
+ return sendKeepaliveFailure(conflictError, 2);
2059
+ case 2:
2060
+ expect(metricSpy).toBeCalledOnceWith(_types5.METRIC_EVENT.KEEPALIVE_ERROR, _types5.REG_ACTION.KEEPALIVE_FAILURE, _types5.METRIC_TYPE.BEHAVIORAL, _constants.METHODS.HANDLE_409_KEEPALIVE_FAILURE, 'PRIMARY', conflictError.headers.trackingid, 2, getSupersededError());
2061
+ expect(uploadLogsSpy).toHaveBeenCalled();
2062
+ case 3:
2063
+ case "end":
2064
+ return _context42.stop();
2065
+ }
2066
+ }, _callee42);
2067
+ })));
2068
+ it('closes the Mobius WebSocket when the socket transport is enabled', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee43() {
2069
+ var apiRequest, disconnectSocketSpy;
2070
+ return _regenerator.default.wrap(function (_context43) {
2071
+ while (1) switch (_context43.prev = _context43.next) {
2072
+ case 0:
2073
+ _context43.next = 1;
2074
+ return beforeEachSetupForKeepalive();
2075
+ case 1:
2076
+ apiRequest = _request.APIRequest.getInstance({
2077
+ webex: webex
2078
+ });
2079
+ jest.spyOn(apiRequest, 'isSocketEnabled').mockReturnValue(true);
2080
+ disconnectSocketSpy = jest.spyOn(apiRequest, 'disconnectFromMobiusSocket').mockResolvedValue();
2081
+ lineEmitter.mockClear();
2082
+ _context43.next = 2;
2083
+ return sendKeepaliveFailure(conflictError, 1);
2084
+ case 2:
2085
+ expect(disconnectSocketSpy).toBeCalledOnceWith({
2086
+ code: 3050,
2087
+ reason: 'done (permanent)'
2088
+ });
2089
+ expect(lineEmitter).toHaveBeenLastCalledWith(_types4.LINE_EVENTS.UNREGISTERED, undefined, expect.any(_LineError.LineError));
2090
+ case 3:
2091
+ case "end":
2092
+ return _context43.stop();
2093
+ }
2094
+ }, _callee43);
2095
+ })));
2096
+ it('still notifies the consumer when the Mobius WebSocket teardown fails', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee44() {
2097
+ var apiRequest;
2098
+ return _regenerator.default.wrap(function (_context44) {
2099
+ while (1) switch (_context44.prev = _context44.next) {
2100
+ case 0:
2101
+ _context44.next = 1;
2102
+ return beforeEachSetupForKeepalive();
2103
+ case 1:
2104
+ apiRequest = _request.APIRequest.getInstance({
2105
+ webex: webex
2106
+ });
2107
+ jest.spyOn(apiRequest, 'isSocketEnabled').mockReturnValue(true);
2108
+ jest.spyOn(apiRequest, 'disconnectFromMobiusSocket').mockRejectedValue(new Error('socket teardown failed'));
2109
+ lineEmitter.mockClear();
2110
+ _context44.next = 2;
2111
+ return sendKeepaliveFailure(conflictError, 1);
2112
+ case 2:
2113
+ expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('Mobius socket disconnect failed after session-superseded'), {
2114
+ file: _constants.REGISTRATION_FILE,
2115
+ method: _constants.METHODS.HANDLE_409_KEEPALIVE_FAILURE
2116
+ });
2117
+ expect(reg.getStatus()).toEqual(_types.RegistrationStatus.INACTIVE);
2118
+ expect(lineEmitter).toHaveBeenLastCalledWith(_types4.LINE_EVENTS.UNREGISTERED, undefined, expect.any(_LineError.LineError));
2119
+ case 3:
2120
+ case "end":
2121
+ return _context44.stop();
2122
+ }
2123
+ }, _callee44);
2124
+ })));
2125
+ it.each([{
2126
+ description: '404 device not found',
2127
+ err: {
2128
+ statusCode: 404
2129
+ }
2130
+ }, {
2131
+ description: '429 too many requests',
2132
+ err: {
2133
+ statusCode: 429,
2134
+ headers: {
2135
+ 'retry-after': 5
2136
+ }
2137
+ }
2138
+ }, {
2139
+ description: '503 service unavailable',
2140
+ err: {
2141
+ statusCode: 503
2142
+ }
2143
+ }])('leaves the existing handling of $description untouched', /*#__PURE__*/function () {
2144
+ var _ref52 = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee45(_ref51) {
2145
+ var err, handle409Spy;
2146
+ return _regenerator.default.wrap(function (_context45) {
2147
+ while (1) switch (_context45.prev = _context45.next) {
2148
+ case 0:
2149
+ err = _ref51.err;
2150
+ _context45.next = 1;
2151
+ return beforeEachSetupForKeepalive();
2152
+ case 1:
2153
+ handle409Spy = jest.spyOn(reg, 'handle409KeepaliveFailure');
2154
+ lineEmitter.mockClear();
2155
+ handleErrorSpy.mockClear();
2156
+ _context45.next = 2;
2157
+ return sendKeepaliveFailure(err, 1);
2158
+ case 2:
2159
+ expect(handle409Spy).not.toHaveBeenCalled();
2160
+ expect(handleErrorSpy).toHaveBeenCalledWith(err, expect.anything(), {
2161
+ file: _constants.REGISTRATION_FILE,
2162
+ method: _constants.KEEPALIVE_UTIL
2163
+ }, expect.anything());
2164
+ expect(lineEmitter).not.toHaveBeenCalledWith(_types4.LINE_EVENTS.UNREGISTERED, undefined, expect.anything());
2165
+ case 3:
2166
+ case "end":
2167
+ return _context45.stop();
2168
+ }
2169
+ }, _callee45);
2170
+ }));
2171
+ return function (_x5) {
2172
+ return _ref52.apply(this, arguments);
2173
+ };
2174
+ }());
2175
+ it('stays terminal when the network recovers after a superseded session', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee46() {
2176
+ var retry;
2177
+ return _regenerator.default.wrap(function (_context46) {
2178
+ while (1) switch (_context46.prev = _context46.next) {
2179
+ case 0:
2180
+ _context46.next = 1;
2181
+ return beforeEachSetupForKeepalive();
2182
+ case 1:
2183
+ lineEmitter.mockClear();
2184
+ _context46.next = 2;
2185
+ return sendKeepaliveFailure(conflictError, 1);
2186
+ case 2:
2187
+ expect(reg.sessionSuperseded).toStrictEqual(true);
2188
+ restoreSpy.mockClear();
2189
+ restartSpy.mockClear();
2190
+ postRegistrationSpy.mockClear();
2191
+ failoverSpy.mockClear();
2192
+ _context46.next = 3;
2193
+ return reg.handleConnectionRestoration(true);
2194
+ case 3:
2195
+ retry = _context46.sent;
2196
+ /* The restoration runs, but every registration attempt it makes is refused at the
2197
+ * choke point, so nothing reaches Mobius and no failover is rescheduled. */
2198
+ expect(retry).toStrictEqual(false);
2199
+ expect(warnSpy).toHaveBeenCalledWith("Session superseded, skipping registration attempt - caller: ".concat(_constants.METHODS.HANDLE_CONNECTION_RESTORATION), {
2200
+ file: _constants.REGISTRATION_FILE,
2201
+ method: _constants.METHODS.HANDLE_CONNECTION_RESTORATION
2202
+ });
2203
+ expect(postRegistrationSpy).not.toHaveBeenCalled();
2204
+ expect(restartSpy).not.toHaveBeenCalled();
2205
+ expect(failoverSpy).not.toHaveBeenCalled();
2206
+ expect(reg.getStatus()).toEqual(_types.RegistrationStatus.INACTIVE);
2207
+ case 4:
2208
+ case "end":
2209
+ return _context46.stop();
2210
+ }
2211
+ }, _callee46);
2212
+ })));
2213
+ it('abandons a restoration that was already queued when the session was superseded', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee47() {
2214
+ var release, restoration, _t;
2215
+ return _regenerator.default.wrap(function (_context47) {
2216
+ while (1) switch (_context47.prev = _context47.next) {
2217
+ case 0:
2218
+ _context47.next = 1;
2219
+ return beforeEachSetupForKeepalive();
2220
+ case 1:
2221
+ lineEmitter.mockClear();
2222
+ postRegistrationSpy.mockClear();
2223
+ restartSpy.mockClear();
2224
+ failoverSpy.mockClear();
2225
+
2226
+ /* Something else holds the mutex, so the restoration queues behind it having
2227
+ * begun while the session was still valid. */
2228
+ _context47.next = 2;
2229
+ return reg.mutex.acquire();
2230
+ case 2:
2231
+ release = _context47.sent;
2232
+ restoration = reg.handleConnectionRestoration(true);
2233
+ _context47.next = 3;
2234
+ return flushPromises();
2235
+ case 3:
2236
+ /* The 409 cleanup latches without the mutex, so the flip lands mid-wait. */
2237
+ reg.sessionSuperseded = true;
2238
+ release();
2239
+ _t = expect;
2240
+ _context47.next = 4;
2241
+ return restoration;
2242
+ case 4:
2243
+ _t(_context47.sent).toStrictEqual(false);
2244
+ /* The latch flipped after this restoration had already started, so the choke
2245
+ * point is what stops it: no device is registered for the dead session. */
2246
+ expect(warnSpy).toHaveBeenCalledWith("Session superseded, skipping registration attempt - caller: ".concat(_constants.METHODS.HANDLE_CONNECTION_RESTORATION), {
2247
+ file: _constants.REGISTRATION_FILE,
2248
+ method: _constants.METHODS.HANDLE_CONNECTION_RESTORATION
2249
+ });
2250
+ expect(postRegistrationSpy).not.toHaveBeenCalled();
2251
+ expect(restartSpy).not.toHaveBeenCalled();
2252
+ expect(failoverSpy).not.toHaveBeenCalled();
2253
+ case 5:
2254
+ case "end":
2255
+ return _context47.stop();
2256
+ }
2257
+ }, _callee47);
2258
+ })));
2259
+ it('stays terminal when all calls are cleared after a superseded session', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee48() {
2260
+ return _regenerator.default.wrap(function (_context48) {
2261
+ while (1) switch (_context48.prev = _context48.next) {
2262
+ case 0:
2263
+ _context48.next = 1;
2264
+ return beforeEachSetupForKeepalive();
2265
+ case 1:
2266
+ lineEmitter.mockClear();
2267
+ _context48.next = 2;
2268
+ return sendKeepaliveFailure(conflictError, 1);
2269
+ case 2:
2270
+ postRegistrationSpy.mockClear();
2271
+ restartSpy.mockClear();
2272
+ failoverSpy.mockClear();
2273
+ _context48.next = 3;
2274
+ return reg.reconnectOnFailure(_constants.CALLS_CLEARED_HANDLER_UTIL);
2275
+ case 3:
2276
+ expect(warnSpy).toHaveBeenCalledWith("Session superseded, skipping registration attempt - caller: ".concat(_constants.CALLS_CLEARED_HANDLER_UTIL), {
2277
+ file: _constants.REGISTRATION_FILE,
2278
+ method: _constants.CALLS_CLEARED_HANDLER_UTIL
2279
+ });
2280
+ expect(postRegistrationSpy).not.toHaveBeenCalled();
2281
+ expect(restartSpy).not.toHaveBeenCalled();
2282
+ expect(failoverSpy).not.toHaveBeenCalled();
2283
+ expect(reg.getStatus()).toEqual(_types.RegistrationStatus.INACTIVE);
2284
+ case 4:
2285
+ case "end":
2286
+ return _context48.stop();
2287
+ }
2288
+ }, _callee48);
2289
+ })));
2290
+ it('lets an explicit registration by the consumer clear the superseded state', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee49() {
2291
+ return _regenerator.default.wrap(function (_context49) {
2292
+ while (1) switch (_context49.prev = _context49.next) {
2293
+ case 0:
2294
+ _context49.next = 1;
2295
+ return beforeEachSetupForKeepalive();
2296
+ case 1:
2297
+ lineEmitter.mockClear();
2298
+ _context49.next = 2;
2299
+ return sendKeepaliveFailure(conflictError, 1);
2300
+ case 2:
2301
+ expect(reg.sessionSuperseded).toStrictEqual(true);
2302
+ postRegistrationSpy.mockResolvedValueOnce(successPayload);
2303
+ _context49.next = 3;
2304
+ return reg.triggerRegistration();
2305
+ case 3:
2306
+ expect(reg.sessionSuperseded).toStrictEqual(false);
2307
+ expect(reg.getStatus()).toBe(_types.RegistrationStatus.ACTIVE);
2308
+ case 4:
2309
+ case "end":
2310
+ return _context49.stop();
2311
+ }
2312
+ }, _callee49);
2313
+ })));
2314
+ it('latches the superseded state before waiting on the shared mutex', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee50() {
2315
+ var worker, release, inFlight, abort;
2316
+ return _regenerator.default.wrap(function (_context50) {
2317
+ while (1) switch (_context50.prev = _context50.next) {
2318
+ case 0:
2319
+ _context50.next = 1;
2320
+ return beforeEachSetupForKeepalive();
2321
+ case 1:
2322
+ worker = reg.webWorker;
2323
+ lineEmitter.mockClear();
2324
+ postRegistrationSpy.mockClear();
2325
+
2326
+ /* A recovery already holds the mutex, so the 409 cleanup queues behind it. */
2327
+ _context50.next = 2;
2328
+ return reg.mutex.acquire();
2329
+ case 2:
2330
+ release = _context50.sent;
2331
+ inFlight = worker.onmessage({
2332
+ data: {
2333
+ type: _types.WorkerMessageType.KEEPALIVE_FAILURE,
2334
+ err: conflictError,
2335
+ keepAliveRetryCount: 1
2336
+ }
2337
+ });
2338
+ _context50.next = 3;
2339
+ return flushPromises();
2340
+ case 3:
2341
+ /* The latch and the worker teardown are visible before cleanup has run. */
2342
+ expect(reg.sessionSuperseded).toStrictEqual(true);
2343
+ expect(reg.webWorker).toBeUndefined();
2344
+ expect(lineEmitter).not.toHaveBeenCalledWith(_types4.LINE_EVENTS.UNREGISTERED, undefined, expect.anything());
2345
+
2346
+ /* A registration path starting now aborts instead of racing the queued cleanup. */
2347
+ _context50.next = 4;
2348
+ return reg.attemptRegistrationWithServers(_constants.FAILOVER_UTIL);
2349
+ case 4:
2350
+ abort = _context50.sent;
2351
+ expect(abort).toStrictEqual(true);
2352
+ expect(postRegistrationSpy).not.toHaveBeenCalled();
2353
+ expect(warnSpy).toHaveBeenCalledWith("Session superseded, skipping registration attempt - caller: ".concat(_constants.FAILOVER_UTIL), {
2354
+ file: _constants.REGISTRATION_FILE,
2355
+ method: _constants.FAILOVER_UTIL
2356
+ });
2357
+ release();
2358
+ _context50.next = 5;
2359
+ return inFlight;
2360
+ case 5:
2361
+ _context50.next = 6;
2362
+ return flushPromises();
2363
+ case 6:
2364
+ expect(reg.getStatus()).toEqual(_types.RegistrationStatus.INACTIVE);
2365
+ case 7:
2366
+ case "end":
2367
+ return _context50.stop();
2368
+ }
2369
+ }, _callee50);
2370
+ })));
2371
+ it('discards a 409 delivered by a keepalive worker that has been replaced', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee51() {
2372
+ var staleWorker, staleWorkerPostSpy, handle409Spy, failKeepalive, inFlight, currentWorker;
2373
+ return _regenerator.default.wrap(function (_context51) {
2374
+ while (1) switch (_context51.prev = _context51.next) {
2375
+ case 0:
2376
+ _context51.next = 1;
2377
+ return beforeEachSetupForKeepalive();
2378
+ case 1:
2379
+ staleWorker = reg.webWorker;
2380
+ staleWorkerPostSpy = jest.spyOn(staleWorker, 'postMessage');
2381
+ handle409Spy = jest.spyOn(reg, 'handle409KeepaliveFailure');
2382
+ jest.spyOn(reg, 'postKeepAlive').mockReturnValue(new _promise.default(function (_, reject) {
2383
+ failKeepalive = reject;
2384
+ }));
2385
+ lineEmitter.mockClear();
2386
+ inFlight = staleWorker.onmessage({
2387
+ data: {
2388
+ type: _types.WorkerMessageType.SEND_KEEPALIVE
2389
+ }
2390
+ });
2391
+ /* A re-registration (failback, connection restoration) swaps the worker while the
2392
+ * keepalive of the previous registration is still in flight. */
2393
+ currentWorker = {
2394
+ postMessage: jest.fn(),
2395
+ terminate: jest.fn(),
2396
+ onmessage: null
2397
+ };
2398
+ reg.webWorker = currentWorker;
2399
+ failKeepalive(conflictError);
2400
+ _context51.next = 2;
2401
+ return inFlight;
2402
+ case 2:
2403
+ _context51.next = 3;
2404
+ return flushPromises();
2405
+ case 3:
2406
+ expect(staleWorkerPostSpy).not.toHaveBeenCalledWith(expect.objectContaining({
2407
+ type: _types.WorkerMessageType.KEEPALIVE_RESULT
2408
+ }));
2409
+ expect(currentWorker.postMessage).not.toHaveBeenCalled();
2410
+ expect(handle409Spy).not.toHaveBeenCalled();
2411
+ expect(lineEmitter).not.toHaveBeenCalledWith(_types4.LINE_EVENTS.UNREGISTERED, undefined, expect.anything());
2412
+ case 4:
2413
+ case "end":
2414
+ return _context51.stop();
2415
+ }
2416
+ }, _callee51);
2417
+ })));
2418
+ });
2419
+ });
2420
+ describe('409 Conflict outside the keepalive flow', function () {
2421
+ /* The registration flow passes no sessionSupersededCb, so a 409 there is logged and
2422
+ * ignored: no consumer event, no registration-error metric, and non-final so the
2423
+ * server loop and failover proceed as they would for any non-fatal status. */
2424
+ it('ignores a 409 during registration without notifying the consumer', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee52() {
2425
+ var conflictPayload;
2426
+ return _regenerator.default.wrap(function (_context52) {
2427
+ while (1) switch (_context52.prev = _context52.next) {
2428
+ case 0:
2429
+ jest.useFakeTimers();
2430
+ conflictPayload = {
2431
+ statusCode: 409,
2432
+ headers: {
2433
+ trackingid: 'tid-reg-409'
2434
+ }
2435
+ };
2436
+ webex.request.mockRejectedValue(conflictPayload);
2437
+ lineEmitter.mockClear();
2438
+ metricSpy.mockClear();
2439
+ _context52.next = 1;
2440
+ return reg.triggerRegistration();
2441
+ case 1:
2442
+ expect(warnSpy).toHaveBeenCalledWith('409 Conflict: ignored, caller does not handle a superseded session', {
2443
+ file: _constants.REGISTRATION_FILE,
2444
+ method: _constants.REGISTRATION_UTIL
2445
+ });
2446
+
2447
+ /* No consumer notification and no registration-error metric on this path. */
2448
+ expect(lineEmitter).not.toHaveBeenCalledWith(_types4.LINE_EVENTS.UNREGISTERED);
2449
+ expect(lineEmitter).not.toHaveBeenCalledWith(_types4.LINE_EVENTS.ERROR, undefined, expect.anything());
2450
+ expect(metricSpy).not.toHaveBeenCalledWith(_types5.METRIC_EVENT.REGISTRATION_ERROR, _types5.REG_ACTION.REGISTER, _types5.METRIC_TYPE.BEHAVIORAL, expect.anything(), expect.anything(), expect.anything(), expect.anything(), expect.anything());
2451
+
2452
+ /* Non-final: every server was tried and failover was scheduled. */
2453
+ expect(reg.getStatus()).toEqual(_types.RegistrationStatus.INACTIVE);
2454
+ expect(reg.sessionSuperseded).toStrictEqual(false);
2455
+ expect(failoverSpy).toHaveBeenCalled();
2456
+ case 2:
2457
+ case "end":
2458
+ return _context52.stop();
2459
+ }
2460
+ }, _callee52);
1832
2461
  })));
1833
2462
  });
1834
2463
  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() {
2464
+ it('success: primary server status to be up', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee53() {
1836
2465
  var pingSuccessPayload, status;
1837
- return _regenerator.default.wrap(function (_context38) {
1838
- while (1) switch (_context38.prev = _context38.next) {
2466
+ return _regenerator.default.wrap(function (_context53) {
2467
+ while (1) switch (_context53.prev = _context53.next) {
1839
2468
  case 0:
1840
2469
  pingSuccessPayload = {
1841
2470
  statusCode: 200
1842
2471
  };
1843
2472
  webex.request.mockResolvedValue(pingSuccessPayload);
1844
- _context38.next = 1;
2473
+ _context53.next = 1;
1845
2474
  return reg.isPrimaryActive();
1846
2475
  case 1:
1847
- status = _context38.sent;
2476
+ status = _context53.sent;
1848
2477
  expect(webex.request).toBeCalledWith(_objectSpread({
1849
2478
  method: 'GET',
1850
2479
  uri: "https://mobius-dfw.webex.com/api/v1/ping"
@@ -1852,23 +2481,23 @@ describe('Registration Tests', function () {
1852
2481
  expect(status).toEqual(true);
1853
2482
  case 2:
1854
2483
  case "end":
1855
- return _context38.stop();
2484
+ return _context53.stop();
1856
2485
  }
1857
- }, _callee38);
2486
+ }, _callee53);
1858
2487
  })));
1859
- it('failed: primary server status to be down', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee39() {
2488
+ it('failed: primary server status to be down', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee54() {
1860
2489
  var pingFailurePayload, status;
1861
- return _regenerator.default.wrap(function (_context39) {
1862
- while (1) switch (_context39.prev = _context39.next) {
2490
+ return _regenerator.default.wrap(function (_context54) {
2491
+ while (1) switch (_context54.prev = _context54.next) {
1863
2492
  case 0:
1864
2493
  pingFailurePayload = {
1865
2494
  statusCode: 500
1866
2495
  };
1867
2496
  webex.request.mockResolvedValue(pingFailurePayload);
1868
- _context39.next = 1;
2497
+ _context54.next = 1;
1869
2498
  return reg.isPrimaryActive();
1870
2499
  case 1:
1871
- status = _context39.sent;
2500
+ status = _context54.sent;
1872
2501
  expect(webex.request).toBeCalledWith(_objectSpread({
1873
2502
  method: 'GET',
1874
2503
  uri: "https://mobius-dfw.webex.com/api/v1/ping"
@@ -1876,9 +2505,257 @@ describe('Registration Tests', function () {
1876
2505
  expect(status).toEqual(false);
1877
2506
  case 2:
1878
2507
  case "end":
1879
- return _context39.stop();
2508
+ return _context54.stop();
2509
+ }
2510
+ }, _callee54);
2511
+ })));
2512
+ });
2513
+ describe('handleRegistrationDownEvent tests', function () {
2514
+ var registrationDownEvent = {
2515
+ type: 'async_event',
2516
+ eventId: 'evt-1',
2517
+ trackingId: 'tid-1',
2518
+ data: {
2519
+ eventType: 'registration.down',
2520
+ deviceInfo: {
2521
+ userId: 'u1',
2522
+ device: {
2523
+ deviceId: 'd1',
2524
+ uri: 'https://mobius/device/d1',
2525
+ status: 'ACTIVE'
2526
+ }
2527
+ }
2528
+ }
2529
+ };
2530
+ beforeEach(/*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee55() {
2531
+ return _regenerator.default.wrap(function (_context55) {
2532
+ while (1) switch (_context55.prev = _context55.next) {
2533
+ case 0:
2534
+ postRegistrationSpy.mockResolvedValueOnce(successPayload);
2535
+ _context55.next = 1;
2536
+ return reg.triggerRegistration();
2537
+ case 1:
2538
+ expect(reg.getStatus()).toBe(_types.RegistrationStatus.ACTIVE);
2539
+ case 2:
2540
+ case "end":
2541
+ return _context55.stop();
2542
+ }
2543
+ }, _callee55);
2544
+ })));
2545
+ afterEach(function () {
2546
+ var calls = (0, _values.default)(reg.callManager.getActiveCalls());
2547
+ calls.forEach(function (call) {
2548
+ call.end();
2549
+ });
2550
+ reg.callManager.callCollection = {};
2551
+ });
2552
+ it('runs cleanup immediately when no active calls are present (socket disabled)', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee56() {
2553
+ var clearKeepaliveSpy, setStatusSpy, disconnectSocketSpy;
2554
+ return _regenerator.default.wrap(function (_context56) {
2555
+ while (1) switch (_context56.prev = _context56.next) {
2556
+ case 0:
2557
+ clearKeepaliveSpy = jest.spyOn(reg, 'clearKeepaliveTimer');
2558
+ setStatusSpy = jest.spyOn(reg, 'setStatus');
2559
+ disconnectSocketSpy = jest.spyOn(_request.APIRequest.getInstance({
2560
+ webex: webex
2561
+ }), 'disconnectFromMobiusSocket');
2562
+ lineEmitter.mockClear();
2563
+ expect((0, _keys.default)(reg.callManager.getActiveCalls()).length).toBe(0);
2564
+ _context56.next = 1;
2565
+ return reg.handleRegistrationDownEvent(registrationDownEvent);
2566
+ case 1:
2567
+ expect(clearKeepaliveSpy).toHaveBeenCalled();
2568
+ expect(setStatusSpy).toHaveBeenCalledWith(_types.RegistrationStatus.INACTIVE);
2569
+ expect(reg.getStatus()).toBe(_types.RegistrationStatus.INACTIVE);
2570
+ expect(reg.reconnectPending).toBe(false);
2571
+ expect(reg.scheduled429Retry).toBe(false);
2572
+ expect(reg.failoverImmediately).toBe(false);
2573
+ expect(reg.retryAfter).toBeUndefined();
2574
+ expect(reg.registerRetry).toBe(false);
2575
+ expect(disconnectSocketSpy).not.toHaveBeenCalled();
2576
+ /* A registration-down stop has no reason to report to the consumer. */
2577
+ expect(lineEmitter).toHaveBeenCalledWith(_types4.LINE_EVENTS.UNREGISTERED, undefined, undefined);
2578
+ case 2:
2579
+ case "end":
2580
+ return _context56.stop();
2581
+ }
2582
+ }, _callee56);
2583
+ })));
2584
+ it('ends the active call and still runs cleanup when an active call is present', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee57() {
2585
+ var clearKeepaliveSpy, setStatusSpy, activeCall, endSpy;
2586
+ return _regenerator.default.wrap(function (_context57) {
2587
+ while (1) switch (_context57.prev = _context57.next) {
2588
+ case 0:
2589
+ clearKeepaliveSpy = jest.spyOn(reg, 'clearKeepaliveTimer');
2590
+ setStatusSpy = jest.spyOn(reg, 'setStatus');
2591
+ activeCall = reg.callManager.createCall();
2592
+ endSpy = jest.spyOn(activeCall, 'end');
2593
+ expect((0, _keys.default)(reg.callManager.getActiveCalls()).length).toBe(1);
2594
+ lineEmitter.mockClear();
2595
+ _context57.next = 1;
2596
+ return reg.handleRegistrationDownEvent(registrationDownEvent);
2597
+ case 1:
2598
+ expect(endSpy).toHaveBeenCalledTimes(1);
2599
+ expect(clearKeepaliveSpy).toHaveBeenCalled();
2600
+ expect(setStatusSpy).toHaveBeenCalledWith(_types.RegistrationStatus.INACTIVE);
2601
+ expect(reg.getStatus()).toBe(_types.RegistrationStatus.INACTIVE);
2602
+ expect(lineEmitter).toHaveBeenCalledWith(_types4.LINE_EVENTS.UNREGISTERED, undefined, undefined);
2603
+ case 2:
2604
+ case "end":
2605
+ return _context57.stop();
2606
+ }
2607
+ }, _callee57);
2608
+ })));
2609
+ it('runs cleanup without calling end when no active call is present on re-invocation', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee58() {
2610
+ var clearKeepaliveSpy, setStatusSpy;
2611
+ return _regenerator.default.wrap(function (_context58) {
2612
+ while (1) switch (_context58.prev = _context58.next) {
2613
+ case 0:
2614
+ clearKeepaliveSpy = jest.spyOn(reg, 'clearKeepaliveTimer');
2615
+ setStatusSpy = jest.spyOn(reg, 'setStatus');
2616
+ _context58.next = 1;
2617
+ return reg.handleRegistrationDownEvent(registrationDownEvent);
2618
+ case 1:
2619
+ expect(reg.getStatus()).toBe(_types.RegistrationStatus.INACTIVE);
2620
+ clearKeepaliveSpy.mockClear();
2621
+ setStatusSpy.mockClear();
2622
+ lineEmitter.mockClear();
2623
+ expect((0, _keys.default)(reg.callManager.getActiveCalls()).length).toBe(0);
2624
+ _context58.next = 2;
2625
+ return reg.handleRegistrationDownEvent(registrationDownEvent);
2626
+ case 2:
2627
+ expect(clearKeepaliveSpy).toHaveBeenCalled();
2628
+ expect(setStatusSpy).toHaveBeenCalledWith(_types.RegistrationStatus.INACTIVE);
2629
+ expect(reg.getStatus()).toBe(_types.RegistrationStatus.INACTIVE);
2630
+ expect(lineEmitter).toHaveBeenCalledWith(_types4.LINE_EVENTS.UNREGISTERED, undefined, undefined);
2631
+ case 3:
2632
+ case "end":
2633
+ return _context58.stop();
2634
+ }
2635
+ }, _callee58);
2636
+ })));
2637
+ it('disconnects the Mobius WebSocket when socket is enabled', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee59() {
2638
+ var apiRequest, disconnectSocketSpy;
2639
+ return _regenerator.default.wrap(function (_context59) {
2640
+ while (1) switch (_context59.prev = _context59.next) {
2641
+ case 0:
2642
+ apiRequest = _request.APIRequest.getInstance({
2643
+ webex: webex
2644
+ });
2645
+ jest.spyOn(apiRequest, 'isSocketEnabled').mockReturnValue(true);
2646
+ disconnectSocketSpy = jest.spyOn(apiRequest, 'disconnectFromMobiusSocket').mockResolvedValue();
2647
+ lineEmitter.mockClear();
2648
+ expect((0, _keys.default)(reg.callManager.getActiveCalls()).length).toBe(0);
2649
+ _context59.next = 1;
2650
+ return reg.handleRegistrationDownEvent(registrationDownEvent);
2651
+ case 1:
2652
+ expect(disconnectSocketSpy).toHaveBeenCalledWith({
2653
+ code: 3050,
2654
+ reason: 'done (permanent)'
2655
+ });
2656
+ expect(reg.getStatus()).toBe(_types.RegistrationStatus.INACTIVE);
2657
+ expect(lineEmitter).toHaveBeenCalledWith(_types4.LINE_EVENTS.UNREGISTERED, undefined, undefined);
2658
+ case 2:
2659
+ case "end":
2660
+ return _context59.stop();
2661
+ }
2662
+ }, _callee59);
2663
+ })));
2664
+ it('still emits UNREGISTERED when socket disconnect fails', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee60() {
2665
+ var apiRequest, disconnectSocketSpy;
2666
+ return _regenerator.default.wrap(function (_context60) {
2667
+ while (1) switch (_context60.prev = _context60.next) {
2668
+ case 0:
2669
+ apiRequest = _request.APIRequest.getInstance({
2670
+ webex: webex
2671
+ });
2672
+ jest.spyOn(apiRequest, 'isSocketEnabled').mockReturnValue(true);
2673
+ disconnectSocketSpy = jest.spyOn(apiRequest, 'disconnectFromMobiusSocket').mockRejectedValue(new Error('socket teardown failed'));
2674
+ lineEmitter.mockClear();
2675
+ _context60.next = 1;
2676
+ return reg.handleRegistrationDownEvent(registrationDownEvent);
2677
+ case 1:
2678
+ expect(disconnectSocketSpy).toHaveBeenCalled();
2679
+ expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('Mobius socket disconnect failed after registration-down'), {
2680
+ file: _constants.REGISTRATION_FILE,
2681
+ method: _constants.METHODS.HANDLE_REGISTRATION_DOWN_EVENT
2682
+ });
2683
+ expect(reg.getStatus()).toBe(_types.RegistrationStatus.INACTIVE);
2684
+ expect(lineEmitter).toHaveBeenCalledWith(_types4.LINE_EVENTS.UNREGISTERED, undefined, undefined);
2685
+ case 2:
2686
+ case "end":
2687
+ return _context60.stop();
2688
+ }
2689
+ }, _callee60);
2690
+ })));
2691
+ });
2692
+ describe('attemptRegistrationWithServers transport alignment', function () {
2693
+ var apiRequest;
2694
+ var setSocketEnabledSpy;
2695
+ beforeEach(function () {
2696
+ apiRequest = _request.APIRequest.getInstance({
2697
+ webex: webex
2698
+ });
2699
+ // Keep the actual transport on HTTP (no-op) so the registration flow stays simple;
2700
+ // we only assert which boolean the method derives from the server group's URL scheme.
2701
+ setSocketEnabledSpy = jest.spyOn(apiRequest, 'setSocketEnabled').mockImplementation(function () {});
2702
+ webex.request.mockResolvedValue(successPayload);
2703
+ });
2704
+ it('enables the WebSocket transport when the server group uses the wss:// scheme', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee61() {
2705
+ return _regenerator.default.wrap(function (_context61) {
2706
+ while (1) switch (_context61.prev = _context61.next) {
2707
+ case 0:
2708
+ _context61.next = 1;
2709
+ return reg.attemptRegistrationWithServers(_constants.REGISTRATION_UTIL, ['wss://mobius.example.com/api/v1/calling/web/']);
2710
+ case 1:
2711
+ expect(setSocketEnabledSpy).toHaveBeenCalledWith(true);
2712
+ case 2:
2713
+ case "end":
2714
+ return _context61.stop();
2715
+ }
2716
+ }, _callee61);
2717
+ })));
2718
+ it('falls back to the HTTP transport when the server group uses the https:// scheme', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee62() {
2719
+ return _regenerator.default.wrap(function (_context62) {
2720
+ while (1) switch (_context62.prev = _context62.next) {
2721
+ case 0:
2722
+ _context62.next = 1;
2723
+ return reg.attemptRegistrationWithServers(_constants.REGISTRATION_UTIL, ['https://mobius.example.com/api/v1/calling/web/']);
2724
+ case 1:
2725
+ expect(setSocketEnabledSpy).toHaveBeenCalledWith(false);
2726
+ case 2:
2727
+ case "end":
2728
+ return _context62.stop();
2729
+ }
2730
+ }, _callee62);
2731
+ })));
2732
+ it('does not change the transport when the server group is empty', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee63() {
2733
+ return _regenerator.default.wrap(function (_context63) {
2734
+ while (1) switch (_context63.prev = _context63.next) {
2735
+ case 0:
2736
+ _context63.next = 1;
2737
+ return reg.attemptRegistrationWithServers(_constants.REGISTRATION_UTIL, []);
2738
+ case 1:
2739
+ expect(setSocketEnabledSpy).not.toHaveBeenCalled();
2740
+ case 2:
2741
+ case "end":
2742
+ return _context63.stop();
2743
+ }
2744
+ }, _callee63);
2745
+ })));
2746
+ it('derives the transport from the first server in the group', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee64() {
2747
+ return _regenerator.default.wrap(function (_context64) {
2748
+ while (1) switch (_context64.prev = _context64.next) {
2749
+ case 0:
2750
+ _context64.next = 1;
2751
+ return reg.attemptRegistrationWithServers(_constants.REGISTRATION_UTIL, ['wss://primary.example.com/api/v1/calling/web/', 'https://backup.example.com/api/v1/calling/web/']);
2752
+ case 1:
2753
+ expect(setSocketEnabledSpy).toHaveBeenCalledWith(true);
2754
+ case 2:
2755
+ case "end":
2756
+ return _context64.stop();
1880
2757
  }
1881
- }, _callee39);
2758
+ }, _callee64);
1882
2759
  })));
1883
2760
  });
1884
2761
  });