@webex/calling 3.8.0 → 3.8.1-next.10

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 (180) hide show
  1. package/dist/CallHistory/CallHistory.js +100 -63
  2. package/dist/CallHistory/CallHistory.js.map +1 -1
  3. package/dist/CallHistory/CallHistory.test.js +115 -19
  4. package/dist/CallHistory/CallHistory.test.js.map +1 -1
  5. package/dist/CallHistory/constants.js +9 -1
  6. package/dist/CallHistory/constants.js.map +1 -1
  7. package/dist/CallSettings/CallSettings.js +46 -13
  8. package/dist/CallSettings/CallSettings.js.map +1 -1
  9. package/dist/CallSettings/UcmBackendConnector.js +62 -18
  10. package/dist/CallSettings/UcmBackendConnector.js.map +1 -1
  11. package/dist/CallSettings/UcmBackendConnector.test.js +70 -7
  12. package/dist/CallSettings/UcmBackendConnector.test.js.map +1 -1
  13. package/dist/CallSettings/WxCallBackendConnector.js +153 -103
  14. package/dist/CallSettings/WxCallBackendConnector.js.map +1 -1
  15. package/dist/CallSettings/WxCallBackendConnector.test.js +52 -15
  16. package/dist/CallSettings/WxCallBackendConnector.test.js.map +1 -1
  17. package/dist/CallSettings/constants.js +15 -1
  18. package/dist/CallSettings/constants.js.map +1 -1
  19. package/dist/CallingClient/CallingClient.js +220 -159
  20. package/dist/CallingClient/CallingClient.js.map +1 -1
  21. package/dist/CallingClient/CallingClient.test.js +58 -27
  22. package/dist/CallingClient/CallingClient.test.js.map +1 -1
  23. package/dist/CallingClient/calling/call.js +251 -189
  24. package/dist/CallingClient/calling/call.js.map +1 -1
  25. package/dist/CallingClient/calling/call.test.js +96 -41
  26. package/dist/CallingClient/calling/call.test.js.map +1 -1
  27. package/dist/CallingClient/calling/callManager.js +73 -48
  28. package/dist/CallingClient/calling/callManager.js.map +1 -1
  29. package/dist/CallingClient/calling/callManager.test.js +96 -37
  30. package/dist/CallingClient/calling/callManager.test.js.map +1 -1
  31. package/dist/CallingClient/constants.js +105 -3
  32. package/dist/CallingClient/constants.js.map +1 -1
  33. package/dist/CallingClient/line/index.js +47 -18
  34. package/dist/CallingClient/line/index.js.map +1 -1
  35. package/dist/CallingClient/line/line.test.js +6 -12
  36. package/dist/CallingClient/line/line.test.js.map +1 -1
  37. package/dist/CallingClient/registration/register.js +590 -522
  38. package/dist/CallingClient/registration/register.js.map +1 -1
  39. package/dist/CallingClient/registration/register.test.js +821 -394
  40. package/dist/CallingClient/registration/register.test.js.map +1 -1
  41. package/dist/CallingClient/registration/types.js.map +1 -1
  42. package/dist/CallingClient/registration/webWorker.js +115 -0
  43. package/dist/CallingClient/registration/webWorker.js.map +1 -0
  44. package/dist/CallingClient/registration/webWorker.test.js +256 -0
  45. package/dist/CallingClient/registration/webWorker.test.js.map +1 -0
  46. package/dist/CallingClient/registration/webWorkerStr.js +15 -0
  47. package/dist/CallingClient/registration/webWorkerStr.js.map +1 -0
  48. package/dist/Contacts/ContactsClient.js +156 -102
  49. package/dist/Contacts/ContactsClient.js.map +1 -1
  50. package/dist/Contacts/ContactsClient.test.js +197 -49
  51. package/dist/Contacts/ContactsClient.test.js.map +1 -1
  52. package/dist/Contacts/constants.js +11 -1
  53. package/dist/Contacts/constants.js.map +1 -1
  54. package/dist/Errors/types.js +2 -0
  55. package/dist/Errors/types.js.map +1 -1
  56. package/dist/Events/impl/index.js +1 -1
  57. package/dist/Events/impl/index.js.map +1 -1
  58. package/dist/Metrics/index.js +102 -41
  59. package/dist/Metrics/index.js.map +1 -1
  60. package/dist/Metrics/index.test.js +10 -4
  61. package/dist/Metrics/index.test.js.map +1 -1
  62. package/dist/Metrics/types.js +4 -1
  63. package/dist/Metrics/types.js.map +1 -1
  64. package/dist/SDKConnector/types.js.map +1 -1
  65. package/dist/Voicemail/BroadworksBackendConnector.js +154 -91
  66. package/dist/Voicemail/BroadworksBackendConnector.js.map +1 -1
  67. package/dist/Voicemail/BroadworksBackendConnector.test.js +99 -19
  68. package/dist/Voicemail/BroadworksBackendConnector.test.js.map +1 -1
  69. package/dist/Voicemail/UcmBackendConnector.js +105 -54
  70. package/dist/Voicemail/UcmBackendConnector.js.map +1 -1
  71. package/dist/Voicemail/UcmBackendConnector.test.js +127 -17
  72. package/dist/Voicemail/UcmBackendConnector.test.js.map +1 -1
  73. package/dist/Voicemail/Voicemail.js +198 -79
  74. package/dist/Voicemail/Voicemail.js.map +1 -1
  75. package/dist/Voicemail/Voicemail.test.js +188 -23
  76. package/dist/Voicemail/Voicemail.test.js.map +1 -1
  77. package/dist/Voicemail/WxCallBackendConnector.js +277 -161
  78. package/dist/Voicemail/WxCallBackendConnector.js.map +1 -1
  79. package/dist/Voicemail/WxCallBackendConnector.test.js +268 -10
  80. package/dist/Voicemail/WxCallBackendConnector.test.js.map +1 -1
  81. package/dist/Voicemail/constants.js +25 -1
  82. package/dist/Voicemail/constants.js.map +1 -1
  83. package/dist/Voicemail/types.js.map +1 -1
  84. package/dist/common/Utils.js +168 -104
  85. package/dist/common/Utils.js.map +1 -1
  86. package/dist/common/Utils.test.js +199 -35
  87. package/dist/common/Utils.test.js.map +1 -1
  88. package/dist/common/constants.js +2 -1
  89. package/dist/common/constants.js.map +1 -1
  90. package/dist/common/testUtil.js +3 -0
  91. package/dist/common/testUtil.js.map +1 -1
  92. package/dist/common/types.js +8 -1
  93. package/dist/common/types.js.map +1 -1
  94. package/dist/index.js +12 -0
  95. package/dist/index.js.map +1 -1
  96. package/dist/module/CallHistory/CallHistory.js +32 -13
  97. package/dist/module/CallHistory/constants.js +6 -0
  98. package/dist/module/CallSettings/CallSettings.js +36 -3
  99. package/dist/module/CallSettings/UcmBackendConnector.js +50 -5
  100. package/dist/module/CallSettings/WxCallBackendConnector.js +54 -18
  101. package/dist/module/CallSettings/constants.js +12 -0
  102. package/dist/module/CallingClient/CallingClient.js +54 -16
  103. package/dist/module/CallingClient/calling/call.js +172 -121
  104. package/dist/module/CallingClient/calling/callManager.js +51 -26
  105. package/dist/module/CallingClient/constants.js +102 -2
  106. package/dist/module/CallingClient/line/index.js +37 -8
  107. package/dist/module/CallingClient/registration/register.js +151 -112
  108. package/dist/module/CallingClient/registration/webWorker.js +59 -0
  109. package/dist/module/CallingClient/registration/webWorkerStr.js +93 -0
  110. package/dist/module/Contacts/ContactsClient.js +65 -21
  111. package/dist/module/Contacts/constants.js +10 -0
  112. package/dist/module/Errors/types.js +2 -0
  113. package/dist/module/Events/impl/index.js +1 -1
  114. package/dist/module/Metrics/index.js +57 -2
  115. package/dist/module/Metrics/types.js +3 -0
  116. package/dist/module/Voicemail/BroadworksBackendConnector.js +66 -17
  117. package/dist/module/Voicemail/UcmBackendConnector.js +51 -11
  118. package/dist/module/Voicemail/Voicemail.js +109 -9
  119. package/dist/module/Voicemail/WxCallBackendConnector.js +67 -18
  120. package/dist/module/Voicemail/constants.js +21 -0
  121. package/dist/module/common/Utils.js +51 -12
  122. package/dist/module/common/constants.js +1 -0
  123. package/dist/module/common/testUtil.js +3 -0
  124. package/dist/module/common/types.js +7 -0
  125. package/dist/module/index.js +1 -0
  126. package/dist/types/CallHistory/CallHistory.d.ts.map +1 -1
  127. package/dist/types/CallHistory/constants.d.ts +6 -0
  128. package/dist/types/CallHistory/constants.d.ts.map +1 -1
  129. package/dist/types/CallSettings/CallSettings.d.ts.map +1 -1
  130. package/dist/types/CallSettings/UcmBackendConnector.d.ts.map +1 -1
  131. package/dist/types/CallSettings/WxCallBackendConnector.d.ts.map +1 -1
  132. package/dist/types/CallSettings/constants.d.ts +12 -0
  133. package/dist/types/CallSettings/constants.d.ts.map +1 -1
  134. package/dist/types/CallingClient/CallingClient.d.ts +2 -3
  135. package/dist/types/CallingClient/CallingClient.d.ts.map +1 -1
  136. package/dist/types/CallingClient/calling/call.d.ts.map +1 -1
  137. package/dist/types/CallingClient/calling/callManager.d.ts.map +1 -1
  138. package/dist/types/CallingClient/constants.d.ts +102 -2
  139. package/dist/types/CallingClient/constants.d.ts.map +1 -1
  140. package/dist/types/CallingClient/line/index.d.ts.map +1 -1
  141. package/dist/types/CallingClient/registration/register.d.ts +4 -3
  142. package/dist/types/CallingClient/registration/register.d.ts.map +1 -1
  143. package/dist/types/CallingClient/registration/types.d.ts +1 -0
  144. package/dist/types/CallingClient/registration/types.d.ts.map +1 -1
  145. package/dist/types/CallingClient/registration/webWorker.d.ts +2 -0
  146. package/dist/types/CallingClient/registration/webWorker.d.ts.map +1 -0
  147. package/dist/types/CallingClient/registration/webWorkerStr.d.ts +3 -0
  148. package/dist/types/CallingClient/registration/webWorkerStr.d.ts.map +1 -0
  149. package/dist/types/Contacts/ContactsClient.d.ts.map +1 -1
  150. package/dist/types/Contacts/constants.d.ts +10 -0
  151. package/dist/types/Contacts/constants.d.ts.map +1 -1
  152. package/dist/types/Errors/types.d.ts +2 -0
  153. package/dist/types/Errors/types.d.ts.map +1 -1
  154. package/dist/types/Metrics/index.d.ts +1 -1
  155. package/dist/types/Metrics/index.d.ts.map +1 -1
  156. package/dist/types/Metrics/types.d.ts +7 -2
  157. package/dist/types/Metrics/types.d.ts.map +1 -1
  158. package/dist/types/SDKConnector/types.d.ts +11 -2
  159. package/dist/types/SDKConnector/types.d.ts.map +1 -1
  160. package/dist/types/Voicemail/BroadworksBackendConnector.d.ts.map +1 -1
  161. package/dist/types/Voicemail/UcmBackendConnector.d.ts.map +1 -1
  162. package/dist/types/Voicemail/Voicemail.d.ts +1 -1
  163. package/dist/types/Voicemail/Voicemail.d.ts.map +1 -1
  164. package/dist/types/Voicemail/WxCallBackendConnector.d.ts +3 -1
  165. package/dist/types/Voicemail/WxCallBackendConnector.d.ts.map +1 -1
  166. package/dist/types/Voicemail/constants.d.ts +21 -0
  167. package/dist/types/Voicemail/constants.d.ts.map +1 -1
  168. package/dist/types/Voicemail/types.d.ts +1 -1
  169. package/dist/types/Voicemail/types.d.ts.map +1 -1
  170. package/dist/types/common/Utils.d.ts +4 -4
  171. package/dist/types/common/Utils.d.ts.map +1 -1
  172. package/dist/types/common/constants.d.ts +1 -0
  173. package/dist/types/common/constants.d.ts.map +1 -1
  174. package/dist/types/common/testUtil.d.ts +3 -0
  175. package/dist/types/common/testUtil.d.ts.map +1 -1
  176. package/dist/types/common/types.d.ts +24 -0
  177. package/dist/types/common/types.d.ts.map +1 -1
  178. package/dist/types/index.d.ts +2 -0
  179. package/dist/types/index.d.ts.map +1 -1
  180. package/package.json +4 -3
@@ -0,0 +1,256 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
4
+ var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs2/regenerator"));
5
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/asyncToGenerator"));
6
+ var _uuid = require("uuid");
7
+ var _webWorker = require("./webWorker");
8
+ var _types = require("../../common/types");
9
+ global.self = global;
10
+ jest.mock('uuid');
11
+ describe('webWorker', function () {
12
+ var postMessageSpy;
13
+ var capturedIntervalCallback;
14
+ var capturedIntervalTimer;
15
+ var clearIntervalSpy;
16
+ beforeEach(function () {
17
+ jest.useFakeTimers();
18
+ global.fetch = jest.fn();
19
+ _uuid.v4.mockReturnValue('mock-uuid');
20
+ postMessageSpy = jest.spyOn(global, 'postMessage').mockImplementation(function () {});
21
+ clearIntervalSpy = jest.spyOn(global, 'clearInterval');
22
+
23
+ // Overriding setInterval so that we capture the callback rather than schedule a timer
24
+ jest.spyOn(global, 'setInterval').mockImplementation(
25
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
26
+ function (callback, interval) {
27
+ capturedIntervalCallback = callback;
28
+ // Create a dummy timer object (could be any non-null value)
29
+ capturedIntervalTimer = {
30
+ dummy: true
31
+ };
32
+ return capturedIntervalTimer;
33
+ });
34
+ });
35
+ afterEach(function () {
36
+ jest.clearAllMocks();
37
+ jest.clearAllTimers();
38
+ jest.useRealTimers();
39
+ });
40
+ it('should start keepalive lifecycle correctly', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
41
+ var fakeSuccessResponse, fakeFailureRespponse;
42
+ return _regenerator.default.wrap(function _callee$(_context) {
43
+ while (1) switch (_context.prev = _context.next) {
44
+ case 0:
45
+ fakeSuccessResponse = {
46
+ ok: true,
47
+ status: 200
48
+ };
49
+ global.fetch.mockResolvedValue(fakeSuccessResponse);
50
+ (0, _webWorker.messageHandler)({
51
+ data: {
52
+ type: _types.WorkerMessageType.START_KEEPALIVE,
53
+ accessToken: 'dummy',
54
+ deviceUrl: 'dummyDevice',
55
+ interval: 1,
56
+ retryCountThreshold: 3,
57
+ url: 'http://example.com'
58
+ }
59
+ });
60
+
61
+ // Manually invoke the captured interval callback to simulate one tick
62
+ _context.next = 5;
63
+ return capturedIntervalCallback();
64
+ case 5:
65
+ expect(global.fetch.mock.calls.length).toBe(1);
66
+ expect(global.fetch).toHaveBeenCalledWith('http://example.com/status', {
67
+ method: 'POST',
68
+ headers: {
69
+ 'cisco-device-url': 'dummyDevice',
70
+ 'spark-user-agent': 'webex-calling/beta',
71
+ Authorization: 'dummy',
72
+ trackingId: 'web_worker_mock-uuid'
73
+ }
74
+ });
75
+ expect(postMessageSpy).not.toHaveBeenCalled();
76
+ fakeFailureRespponse = {
77
+ ok: false,
78
+ status: 401
79
+ };
80
+ global.fetch.mockResolvedValue(fakeFailureRespponse);
81
+ (0, _webWorker.messageHandler)({
82
+ data: {
83
+ type: _types.WorkerMessageType.START_KEEPALIVE,
84
+ accessToken: 'dummy',
85
+ deviceUrl: 'dummyDevice',
86
+ interval: 1,
87
+ retryCountThreshold: 3,
88
+ url: 'http://example.com'
89
+ }
90
+ });
91
+
92
+ // Manually invoke the captured interval callback to simulate one tick
93
+ _context.next = 13;
94
+ return capturedIntervalCallback();
95
+ case 13:
96
+ expect(global.fetch.mock.calls.length).toBe(2);
97
+ expect(postMessageSpy).toHaveBeenCalledWith({
98
+ err: new Error("Keepalive failed with status: 401"),
99
+ keepAliveRetryCount: 1,
100
+ type: 'KEEPALIVE_FAILURE'
101
+ });
102
+ case 15:
103
+ case "end":
104
+ return _context.stop();
105
+ }
106
+ }, _callee);
107
+ })));
108
+ it('should post KEEPALIVE_FAILURE when fetch fails', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
109
+ var mockError;
110
+ return _regenerator.default.wrap(function _callee2$(_context2) {
111
+ while (1) switch (_context2.prev = _context2.next) {
112
+ case 0:
113
+ mockError = new Error('Network error');
114
+ global.fetch.mockRejectedValue({
115
+ ok: false,
116
+ err: mockError,
117
+ status: 401
118
+ });
119
+ (0, _webWorker.messageHandler)({
120
+ data: {
121
+ type: _types.WorkerMessageType.START_KEEPALIVE,
122
+ accessToken: 'dummy',
123
+ deviceUrl: 'dummyDevice',
124
+ interval: 1,
125
+ retryCountThreshold: 1,
126
+ url: 'http://example.com'
127
+ }
128
+ });
129
+ _context2.next = 5;
130
+ return capturedIntervalCallback();
131
+ case 5:
132
+ expect(postMessageSpy).toHaveBeenCalledWith({
133
+ type: _types.WorkerMessageType.KEEPALIVE_FAILURE,
134
+ err: {
135
+ ok: false,
136
+ err: mockError,
137
+ status: 401
138
+ },
139
+ keepAliveRetryCount: 1
140
+ });
141
+ case 6:
142
+ case "end":
143
+ return _context2.stop();
144
+ }
145
+ }, _callee2);
146
+ })));
147
+ it('should post KEEPALIVE_SUCCESS after a failure when fetch succeeds', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
148
+ return _regenerator.default.wrap(function _callee3$(_context3) {
149
+ while (1) switch (_context3.prev = _context3.next) {
150
+ case 0:
151
+ // Set fetch so that first tick rejects (failure) and second tick resolves (success)
152
+ global.fetch.mockRejectedValueOnce(new Error('first failure')).mockResolvedValueOnce({
153
+ ok: true,
154
+ status: 200
155
+ });
156
+ (0, _webWorker.messageHandler)({
157
+ data: {
158
+ type: _types.WorkerMessageType.START_KEEPALIVE,
159
+ accessToken: 'dummy',
160
+ deviceUrl: 'dummyDevice',
161
+ interval: 1,
162
+ retryCountThreshold: 3,
163
+ url: 'http://example.com'
164
+ }
165
+ });
166
+
167
+ // First tick: trigger failure
168
+ _context3.next = 4;
169
+ return capturedIntervalCallback();
170
+ case 4:
171
+ expect(postMessageSpy.mock.calls[0][0].type).toBe(_types.WorkerMessageType.KEEPALIVE_FAILURE);
172
+
173
+ // Second tick: trigger success.
174
+ _context3.next = 7;
175
+ return capturedIntervalCallback();
176
+ case 7:
177
+ expect(postMessageSpy.mock.calls[1][0].type).toBe(_types.WorkerMessageType.KEEPALIVE_SUCCESS);
178
+ expect(postMessageSpy.mock.calls[1][0].statusCode).toBe(200);
179
+ case 9:
180
+ case "end":
181
+ return _context3.stop();
182
+ }
183
+ }, _callee3);
184
+ })));
185
+ it('should clear keepalive timer on receiving CLEAR_KEEPALIVE message', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4() {
186
+ var fakeSuccessResponse, startEvent;
187
+ return _regenerator.default.wrap(function _callee4$(_context4) {
188
+ while (1) switch (_context4.prev = _context4.next) {
189
+ case 0:
190
+ fakeSuccessResponse = {
191
+ ok: true,
192
+ status: 200
193
+ };
194
+ global.fetch.mockResolvedValue(fakeSuccessResponse);
195
+ startEvent = {
196
+ data: {
197
+ type: _types.WorkerMessageType.START_KEEPALIVE,
198
+ accessToken: 'dummy',
199
+ deviceUrl: 'dummyDevice',
200
+ interval: 1,
201
+ retryCountThreshold: 1,
202
+ url: 'http://example.com'
203
+ }
204
+ };
205
+ (0, _webWorker.messageHandler)(startEvent);
206
+ (0, _webWorker.messageHandler)({
207
+ data: {
208
+ type: _types.WorkerMessageType.CLEAR_KEEPALIVE
209
+ }
210
+ });
211
+ jest.advanceTimersByTime(3000);
212
+ expect(global.fetch.mock.calls.length).toBeLessThanOrEqual(3);
213
+ expect(clearIntervalSpy).toHaveBeenCalled();
214
+ case 8:
215
+ case "end":
216
+ return _context4.stop();
217
+ }
218
+ }, _callee4);
219
+ })));
220
+ it('improve coverage: should not clear keepalive timer on receiving CLEAR_KEEPALIVE message without keepTimer', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5() {
221
+ var fakeSuccessResponse, startEvent;
222
+ return _regenerator.default.wrap(function _callee5$(_context5) {
223
+ while (1) switch (_context5.prev = _context5.next) {
224
+ case 0:
225
+ jest.spyOn(global, 'setInterval').mockReturnValue(undefined);
226
+ fakeSuccessResponse = {
227
+ ok: true,
228
+ status: 200
229
+ };
230
+ global.fetch.mockResolvedValue(fakeSuccessResponse);
231
+ startEvent = {
232
+ data: {
233
+ type: _types.WorkerMessageType.START_KEEPALIVE,
234
+ accessToken: 'dummy',
235
+ deviceUrl: 'dummyDevice',
236
+ interval: 1,
237
+ retryCountThreshold: 1,
238
+ url: 'http://example.com'
239
+ }
240
+ };
241
+ (0, _webWorker.messageHandler)(startEvent);
242
+ (0, _webWorker.messageHandler)({
243
+ data: {
244
+ type: _types.WorkerMessageType.CLEAR_KEEPALIVE
245
+ }
246
+ });
247
+ jest.advanceTimersByTime(3000);
248
+ expect(clearIntervalSpy).not.toHaveBeenCalled();
249
+ case 8:
250
+ case "end":
251
+ return _context5.stop();
252
+ }
253
+ }, _callee5);
254
+ })));
255
+ });
256
+ //# sourceMappingURL=webWorker.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_uuid","require","_webWorker","_types","global","self","jest","mock","describe","postMessageSpy","capturedIntervalCallback","capturedIntervalTimer","clearIntervalSpy","beforeEach","useFakeTimers","fetch","fn","uuid","mockReturnValue","spyOn","mockImplementation","callback","interval","dummy","afterEach","clearAllMocks","clearAllTimers","useRealTimers","it","_asyncToGenerator2","default","_regenerator","mark","_callee","fakeSuccessResponse","fakeFailureRespponse","wrap","_callee$","_context","prev","next","ok","status","mockResolvedValue","messageHandler","data","type","WorkerMessageType","START_KEEPALIVE","accessToken","deviceUrl","retryCountThreshold","url","expect","calls","length","toBe","toHaveBeenCalledWith","method","headers","Authorization","trackingId","not","toHaveBeenCalled","err","Error","keepAliveRetryCount","stop","_callee2","mockError","_callee2$","_context2","mockRejectedValue","KEEPALIVE_FAILURE","_callee3","_callee3$","_context3","mockRejectedValueOnce","mockResolvedValueOnce","KEEPALIVE_SUCCESS","statusCode","_callee4","startEvent","_callee4$","_context4","CLEAR_KEEPALIVE","advanceTimersByTime","toBeLessThanOrEqual","_callee5","_callee5$","_context5","undefined"],"sources":["webWorker.test.ts"],"sourcesContent":["import {v4 as uuid} from 'uuid';\nimport {messageHandler} from './webWorker';\nimport {WorkerMessageType} from '../../common/types';\n\n(global as any).self = global;\n\njest.mock('uuid');\n\ndescribe('webWorker', () => {\n let postMessageSpy: jest.SpyInstance;\n let capturedIntervalCallback: any;\n let capturedIntervalTimer: any;\n let clearIntervalSpy: jest.SpyInstance;\n\n beforeEach(() => {\n jest.useFakeTimers();\n global.fetch = jest.fn();\n (uuid as jest.Mock).mockReturnValue('mock-uuid');\n\n postMessageSpy = jest.spyOn(global, 'postMessage').mockImplementation(() => {});\n clearIntervalSpy = jest.spyOn(global, 'clearInterval');\n\n // Overriding setInterval so that we capture the callback rather than schedule a timer\n jest.spyOn(global, 'setInterval').mockImplementation(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n (callback: any, interval: number): NodeJS.Timeout => {\n capturedIntervalCallback = callback;\n // Create a dummy timer object (could be any non-null value)\n capturedIntervalTimer = {dummy: true};\n\n return capturedIntervalTimer as NodeJS.Timeout;\n }\n );\n });\n\n afterEach(() => {\n jest.clearAllMocks();\n jest.clearAllTimers();\n jest.useRealTimers();\n });\n\n it('should start keepalive lifecycle correctly', async () => {\n const fakeSuccessResponse = {ok: true, status: 200};\n (global.fetch as jest.Mock).mockResolvedValue(fakeSuccessResponse);\n\n messageHandler({\n data: {\n type: WorkerMessageType.START_KEEPALIVE,\n accessToken: 'dummy',\n deviceUrl: 'dummyDevice',\n interval: 1,\n retryCountThreshold: 3,\n url: 'http://example.com',\n },\n } as MessageEvent);\n\n // Manually invoke the captured interval callback to simulate one tick\n await capturedIntervalCallback();\n\n expect((global.fetch as jest.Mock).mock.calls.length).toBe(1);\n expect(global.fetch).toHaveBeenCalledWith('http://example.com/status', {\n method: 'POST',\n headers: {\n 'cisco-device-url': 'dummyDevice',\n 'spark-user-agent': 'webex-calling/beta',\n Authorization: 'dummy',\n trackingId: 'web_worker_mock-uuid',\n },\n });\n expect(postMessageSpy).not.toHaveBeenCalled();\n\n const fakeFailureRespponse = {ok: false, status: 401};\n (global.fetch as jest.Mock).mockResolvedValue(fakeFailureRespponse);\n\n messageHandler({\n data: {\n type: WorkerMessageType.START_KEEPALIVE,\n accessToken: 'dummy',\n deviceUrl: 'dummyDevice',\n interval: 1,\n retryCountThreshold: 3,\n url: 'http://example.com',\n },\n } as MessageEvent);\n\n // Manually invoke the captured interval callback to simulate one tick\n await capturedIntervalCallback();\n\n expect((global.fetch as jest.Mock).mock.calls.length).toBe(2);\n expect(postMessageSpy).toHaveBeenCalledWith({\n err: new Error(`Keepalive failed with status: 401`),\n keepAliveRetryCount: 1,\n type: 'KEEPALIVE_FAILURE',\n });\n });\n\n it('should post KEEPALIVE_FAILURE when fetch fails', async () => {\n const mockError = new Error('Network error');\n (global.fetch as jest.Mock).mockRejectedValue({\n ok: false,\n err: mockError,\n status: 401,\n });\n\n messageHandler({\n data: {\n type: WorkerMessageType.START_KEEPALIVE,\n accessToken: 'dummy',\n deviceUrl: 'dummyDevice',\n interval: 1,\n retryCountThreshold: 1,\n url: 'http://example.com',\n },\n } as MessageEvent);\n\n await capturedIntervalCallback();\n\n expect(postMessageSpy).toHaveBeenCalledWith({\n type: WorkerMessageType.KEEPALIVE_FAILURE,\n err: {\n ok: false,\n err: mockError,\n status: 401,\n },\n keepAliveRetryCount: 1,\n });\n });\n\n it('should post KEEPALIVE_SUCCESS after a failure when fetch succeeds', async () => {\n // Set fetch so that first tick rejects (failure) and second tick resolves (success)\n (global.fetch as jest.Mock)\n .mockRejectedValueOnce(new Error('first failure'))\n .mockResolvedValueOnce({ok: true, status: 200});\n\n messageHandler({\n data: {\n type: WorkerMessageType.START_KEEPALIVE,\n accessToken: 'dummy',\n deviceUrl: 'dummyDevice',\n interval: 1,\n retryCountThreshold: 3,\n url: 'http://example.com',\n },\n } as MessageEvent);\n\n // First tick: trigger failure\n await capturedIntervalCallback();\n expect(postMessageSpy.mock.calls[0][0].type).toBe(WorkerMessageType.KEEPALIVE_FAILURE);\n\n // Second tick: trigger success.\n await capturedIntervalCallback();\n expect(postMessageSpy.mock.calls[1][0].type).toBe(WorkerMessageType.KEEPALIVE_SUCCESS);\n expect(postMessageSpy.mock.calls[1][0].statusCode).toBe(200);\n });\n\n it('should clear keepalive timer on receiving CLEAR_KEEPALIVE message', async () => {\n const fakeSuccessResponse = {ok: true, status: 200};\n (global.fetch as jest.Mock).mockResolvedValue(fakeSuccessResponse);\n\n const startEvent = {\n data: {\n type: WorkerMessageType.START_KEEPALIVE,\n accessToken: 'dummy',\n deviceUrl: 'dummyDevice',\n interval: 1,\n retryCountThreshold: 1,\n url: 'http://example.com',\n },\n };\n\n messageHandler(startEvent as MessageEvent);\n messageHandler({data: {type: WorkerMessageType.CLEAR_KEEPALIVE}} as MessageEvent);\n\n jest.advanceTimersByTime(3000);\n expect((global.fetch as jest.Mock).mock.calls.length).toBeLessThanOrEqual(3);\n expect(clearIntervalSpy).toHaveBeenCalled();\n });\n\n it('improve coverage: should not clear keepalive timer on receiving CLEAR_KEEPALIVE message without keepTimer', async () => {\n jest.spyOn(global, 'setInterval').mockReturnValue(undefined);\n const fakeSuccessResponse = {ok: true, status: 200};\n (global.fetch as jest.Mock).mockResolvedValue(fakeSuccessResponse);\n\n const startEvent = {\n data: {\n type: WorkerMessageType.START_KEEPALIVE,\n accessToken: 'dummy',\n deviceUrl: 'dummyDevice',\n interval: 1,\n retryCountThreshold: 1,\n url: 'http://example.com',\n },\n };\n\n messageHandler(startEvent as MessageEvent);\n messageHandler({data: {type: WorkerMessageType.CLEAR_KEEPALIVE}} as MessageEvent);\n\n jest.advanceTimersByTime(3000);\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AE,aAAa;cACxB5B,QAAQ,EAAE,CAAC;cACX6B,mBAAmB,EAAE,CAAC;cACtBC,GAAG,EAAE;YACP;UACF,CAAC;UAED,IAAAR,yBAAc,EAACsC,UAA0B,CAAC;UAC1C,IAAAtC,yBAAc,EAAC;YAACC,IAAI,EAAE;cAACC,IAAI,EAAEC,wBAAiB,CAACsC;YAAe;UAAC,CAAiB,CAAC;UAEjF/E,IAAI,CAACgF,mBAAmB,CAAC,IAAI,CAAC;UAC9BjC,MAAM,CAACzC,gBAAgB,CAAC,CAACkD,GAAG,CAACC,gBAAgB,CAAC,CAAC;QAAC;QAAA;UAAA,OAAA2B,SAAA,CAAAvB,IAAA;MAAA;IAAA,GAAAqB,QAAA;EAAA,CACjD,GAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
4
+ _Object$defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ /**
9
+ * This file contains the stringified version of the web worker code from webWorker.ts
10
+ * It can be used to create a Blob URL for the worker instead of loading it from a separate file
11
+ */
12
+
13
+ var webWorkerStr = "/* eslint-env worker */\n\nconst uuid = () => {\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {\n const r = (Math.random() * 16) | 0;\n const v = c === 'x' ? r : (r & 0x3) | 0x8;\n return v.toString(16);\n });\n};\n\n// Enum values from the original imports\nconst HTTP_METHODS = {\n GET: 'GET',\n POST: 'POST',\n PUT: 'PUT',\n DELETE: 'DELETE',\n PATCH: 'PATCH',\n};\n\nconst WorkerMessageType = {\n START_KEEPALIVE: 'START_KEEPALIVE',\n CLEAR_KEEPALIVE: 'CLEAR_KEEPALIVE',\n KEEPALIVE_SUCCESS: 'KEEPALIVE_SUCCESS',\n KEEPALIVE_FAILURE: 'KEEPALIVE_FAILURE',\n};\n\nlet keepaliveTimer;\n\nconst messageHandler = (event) => {\n const {type} = event.data;\n\n const postKeepAlive = async (accessToken, deviceUrl, url) => {\n const response = await fetch(`${url}/status`, {\n method: HTTP_METHODS.POST,\n headers: {\n 'cisco-device-url': deviceUrl,\n 'spark-user-agent': 'webex-calling/beta',\n Authorization: `${accessToken}`,\n trackingId: `web_worker_${uuid()}`,\n },\n });\n\n if (!response.ok) {\n throw new Error(`Keepalive failed with status: ${response.status}`);\n }\n\n return response;\n };\n\n if (type === WorkerMessageType.START_KEEPALIVE) {\n let keepAliveRetryCount = 0;\n const {accessToken, deviceUrl, interval, retryCountThreshold, url} = event.data;\n\n if (keepaliveTimer) {\n clearInterval(keepaliveTimer);\n keepaliveTimer = undefined;\n }\n\n keepaliveTimer = setInterval(async () => {\n if (keepAliveRetryCount < retryCountThreshold) {\n try {\n const res = await postKeepAlive(accessToken, deviceUrl, url);\n const statusCode = res.status;\n if (keepAliveRetryCount > 0) {\n self.postMessage({\n type: WorkerMessageType.KEEPALIVE_SUCCESS,\n statusCode,\n });\n }\n keepAliveRetryCount = 0;\n } catch (err) {\n keepAliveRetryCount += 1;\n self.postMessage({\n type: WorkerMessageType.KEEPALIVE_FAILURE,\n err,\n keepAliveRetryCount,\n });\n }\n }\n }, interval * 1000);\n }\n\n if (type === WorkerMessageType.CLEAR_KEEPALIVE) {\n if (keepaliveTimer) {\n clearInterval(keepaliveTimer);\n keepaliveTimer = undefined;\n }\n }\n};\n\nself.addEventListener('message', messageHandler);\n";
14
+ var _default = exports.default = webWorkerStr;
15
+ //# sourceMappingURL=webWorkerStr.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["webWorkerStr","_default","exports","default"],"sources":["webWorkerStr.ts"],"sourcesContent":["/**\n * This file contains the stringified version of the web worker code from webWorker.ts\n * It can be used to create a Blob URL for the worker instead of loading it from a separate file\n */\n\nconst webWorkerStr = `/* eslint-env worker */\n\nconst uuid = () => {\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {\n const r = (Math.random() * 16) | 0;\n const v = c === 'x' ? r : (r & 0x3) | 0x8;\n return v.toString(16);\n });\n};\n\n// Enum values from the original imports\nconst HTTP_METHODS = {\n GET: 'GET',\n POST: 'POST',\n PUT: 'PUT',\n DELETE: 'DELETE',\n PATCH: 'PATCH',\n};\n\nconst WorkerMessageType = {\n START_KEEPALIVE: 'START_KEEPALIVE',\n CLEAR_KEEPALIVE: 'CLEAR_KEEPALIVE',\n KEEPALIVE_SUCCESS: 'KEEPALIVE_SUCCESS',\n KEEPALIVE_FAILURE: 'KEEPALIVE_FAILURE',\n};\n\nlet keepaliveTimer;\n\nconst messageHandler = (event) => {\n const {type} = event.data;\n\n const postKeepAlive = async (accessToken, deviceUrl, url) => {\n const response = await fetch(\\`\\${url}/status\\`, {\n method: HTTP_METHODS.POST,\n headers: {\n 'cisco-device-url': deviceUrl,\n 'spark-user-agent': 'webex-calling/beta',\n Authorization: \\`\\${accessToken}\\`,\n trackingId: \\`web_worker_\\${uuid()}\\`,\n },\n });\n\n if (!response.ok) {\n throw new Error(\\`Keepalive failed with status: \\${response.status}\\`);\n }\n\n return response;\n };\n\n if (type === WorkerMessageType.START_KEEPALIVE) {\n let keepAliveRetryCount = 0;\n const {accessToken, deviceUrl, interval, retryCountThreshold, url} = event.data;\n\n if (keepaliveTimer) {\n clearInterval(keepaliveTimer);\n keepaliveTimer = undefined;\n }\n\n keepaliveTimer = setInterval(async () => {\n if (keepAliveRetryCount < retryCountThreshold) {\n try {\n const res = await postKeepAlive(accessToken, deviceUrl, url);\n const statusCode = res.status;\n if (keepAliveRetryCount > 0) {\n self.postMessage({\n type: WorkerMessageType.KEEPALIVE_SUCCESS,\n statusCode,\n });\n }\n keepAliveRetryCount = 0;\n } catch (err) {\n keepAliveRetryCount += 1;\n self.postMessage({\n type: WorkerMessageType.KEEPALIVE_FAILURE,\n err,\n keepAliveRetryCount,\n });\n }\n }\n }, interval * 1000);\n }\n\n if (type === WorkerMessageType.CLEAR_KEEPALIVE) {\n if (keepaliveTimer) {\n clearInterval(keepaliveTimer);\n keepaliveTimer = undefined;\n }\n }\n};\n\nself.addEventListener('message', messageHandler);\n`;\n\nexport default webWorkerStr;\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;;AAEA,IAAMA,YAAY,o5EA2FjB;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEaH,YAAY"}