@webex/calling 3.12.0-webex-services-ready.4 → 3.13.0

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