@webex/internal-plugin-mercury 3.12.0-next.9 → 3.12.0-task-refactor.1
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.
- package/README.md +0 -54
- package/dist/mercury.js +198 -395
- package/dist/mercury.js.map +1 -1
- package/dist/socket/socket-base.js +3 -36
- package/dist/socket/socket-base.js.map +1 -1
- package/package.json +17 -17
- package/src/mercury.js +171 -398
- package/src/socket/socket-base.js +3 -40
- package/test/unit/spec/mercury-events.js +2 -20
- package/test/unit/spec/mercury.js +139 -307
- package/test/unit/spec/socket.js +0 -61
- package/dist/socket/constants.js +0 -16
- package/dist/socket/constants.js.map +0 -1
- package/src/socket/constants.js +0 -6
|
@@ -17,7 +17,6 @@ import {
|
|
|
17
17
|
UnknownResponse,
|
|
18
18
|
// NotFound
|
|
19
19
|
} from '../errors';
|
|
20
|
-
import {SOCKET_READY_STATE} from './constants';
|
|
21
20
|
|
|
22
21
|
const sockets = new WeakMap();
|
|
23
22
|
|
|
@@ -34,8 +33,6 @@ export default class Socket extends EventEmitter {
|
|
|
34
33
|
this._domain = 'unknown-domain';
|
|
35
34
|
this.onmessage = this.onmessage.bind(this);
|
|
36
35
|
this.onclose = this.onclose.bind(this);
|
|
37
|
-
// Increase max listeners to avoid memory leak warning in tests
|
|
38
|
-
this.setMaxListeners(10);
|
|
39
36
|
}
|
|
40
37
|
|
|
41
38
|
/**
|
|
@@ -117,10 +114,7 @@ export default class Socket extends EventEmitter {
|
|
|
117
114
|
// logger is defined once open is called
|
|
118
115
|
this.logger.info(`socket,${this._domain}: closing`);
|
|
119
116
|
|
|
120
|
-
if (
|
|
121
|
-
socket.readyState === SOCKET_READY_STATE.CLOSING ||
|
|
122
|
-
socket.readyState === SOCKET_READY_STATE.CLOSED
|
|
123
|
-
) {
|
|
117
|
+
if (socket.readyState === 2 || socket.readyState === 3) {
|
|
124
118
|
this.logger.info(`socket,${this._domain}: already closed`);
|
|
125
119
|
resolve();
|
|
126
120
|
|
|
@@ -167,27 +161,7 @@ export default class Socket extends EventEmitter {
|
|
|
167
161
|
resolve(event);
|
|
168
162
|
};
|
|
169
163
|
|
|
170
|
-
|
|
171
|
-
// because calling close() on a CONNECTING socket may not preserve custom codes
|
|
172
|
-
if (socket.readyState === SOCKET_READY_STATE.CONNECTING) {
|
|
173
|
-
this.logger.info(
|
|
174
|
-
`socket,${this._domain}: socket still connecting, triggering close manually`
|
|
175
|
-
);
|
|
176
|
-
clearTimeout(closeTimer);
|
|
177
|
-
const closeEvent = {code: options.code, reason: options.reason};
|
|
178
|
-
this.onclose(closeEvent);
|
|
179
|
-
resolve(closeEvent);
|
|
180
|
-
try {
|
|
181
|
-
socket.close(options.code, options.reason);
|
|
182
|
-
} catch (error) {
|
|
183
|
-
this.logger.info(
|
|
184
|
-
`socket,${this._domain}: error while closing CONNECTING socket, likely due to browser incompatibility with custom close codes`,
|
|
185
|
-
error
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
} else {
|
|
189
|
-
socket.close(options.code, options.reason);
|
|
190
|
-
}
|
|
164
|
+
socket.close(options.code, options.reason);
|
|
191
165
|
});
|
|
192
166
|
}
|
|
193
167
|
|
|
@@ -354,7 +328,7 @@ export default class Socket extends EventEmitter {
|
|
|
354
328
|
*/
|
|
355
329
|
send(data) {
|
|
356
330
|
return new Promise((resolve, reject) => {
|
|
357
|
-
if (this.readyState !==
|
|
331
|
+
if (this.readyState !== 1) {
|
|
358
332
|
return reject(new Error('INVALID_STATE_ERROR'));
|
|
359
333
|
}
|
|
360
334
|
|
|
@@ -384,20 +358,9 @@ export default class Socket extends EventEmitter {
|
|
|
384
358
|
return Promise.reject(new Error('`event.data.id` is required'));
|
|
385
359
|
}
|
|
386
360
|
|
|
387
|
-
// Don't try to acknowledge if socket is not in open state
|
|
388
|
-
if (this.readyState !== SOCKET_READY_STATE.OPEN) {
|
|
389
|
-
return Promise.resolve(); // Silently ignore acknowledgment for closed sockets
|
|
390
|
-
}
|
|
391
|
-
|
|
392
361
|
return this.send({
|
|
393
362
|
messageId: event.data.id,
|
|
394
363
|
type: 'ack',
|
|
395
|
-
}).catch((error) => {
|
|
396
|
-
// Gracefully handle send errors (like INVALID_STATE_ERROR) to prevent test issues
|
|
397
|
-
if (error.message === 'INVALID_STATE_ERROR') {
|
|
398
|
-
return Promise.resolve(); // Socket was closed, ignore the acknowledgment
|
|
399
|
-
}
|
|
400
|
-
throw error; // Re-throw other errors
|
|
401
364
|
});
|
|
402
365
|
}
|
|
403
366
|
|
|
@@ -38,31 +38,14 @@ describe('plugin-mercury', () => {
|
|
|
38
38
|
},
|
|
39
39
|
timestamp: Date.now(),
|
|
40
40
|
trackingId: `suffix_${uuid.v4()}_${Date.now()}`,
|
|
41
|
-
sessionId: 'mercury-default-session',
|
|
42
41
|
};
|
|
43
42
|
|
|
44
43
|
beforeEach(() => {
|
|
45
44
|
clock = FakeTimers.install({now: Date.now()});
|
|
46
45
|
});
|
|
47
46
|
|
|
48
|
-
afterEach(
|
|
47
|
+
afterEach(() => {
|
|
49
48
|
clock.uninstall();
|
|
50
|
-
// Clean up mercury socket and mockWebSocket
|
|
51
|
-
if (mercury && mercury.socket) {
|
|
52
|
-
try {
|
|
53
|
-
await mercury.socket.close();
|
|
54
|
-
} catch (e) {}
|
|
55
|
-
}
|
|
56
|
-
if (mockWebSocket && typeof mockWebSocket.close === 'function') {
|
|
57
|
-
mockWebSocket.close();
|
|
58
|
-
}
|
|
59
|
-
// Restore stubs
|
|
60
|
-
if (Socket.getWebSocketConstructor.restore) {
|
|
61
|
-
Socket.getWebSocketConstructor.restore();
|
|
62
|
-
}
|
|
63
|
-
if (socketOpenStub && socketOpenStub.restore) {
|
|
64
|
-
socketOpenStub.restore();
|
|
65
|
-
}
|
|
66
49
|
});
|
|
67
50
|
|
|
68
51
|
beforeEach(() => {
|
|
@@ -93,7 +76,6 @@ describe('plugin-mercury', () => {
|
|
|
93
76
|
});
|
|
94
77
|
|
|
95
78
|
mercury = webex.internal.mercury;
|
|
96
|
-
mercury.defaultSessionId = 'mercury-default-session';
|
|
97
79
|
});
|
|
98
80
|
|
|
99
81
|
afterEach(() => {
|
|
@@ -319,7 +301,7 @@ describe('plugin-mercury', () => {
|
|
|
319
301
|
})
|
|
320
302
|
.then(() => {
|
|
321
303
|
assert.called(offlineSpy);
|
|
322
|
-
assert.calledWith(offlineSpy, {code, reason
|
|
304
|
+
assert.calledWith(offlineSpy, {code, reason});
|
|
323
305
|
switch (action) {
|
|
324
306
|
case 'close':
|
|
325
307
|
assert.called(permanentSpy);
|