@webex/internal-plugin-mercury 3.9.0 → 3.10.0-multi-llms.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.
@@ -33,6 +33,8 @@ export default class Socket extends EventEmitter {
33
33
  this._domain = 'unknown-domain';
34
34
  this.onmessage = this.onmessage.bind(this);
35
35
  this.onclose = this.onclose.bind(this);
36
+ // Increase max listeners to avoid memory leak warning in tests
37
+ this.setMaxListeners(5);
36
38
  }
37
39
 
38
40
  /**
@@ -358,9 +360,20 @@ export default class Socket extends EventEmitter {
358
360
  return Promise.reject(new Error('`event.data.id` is required'));
359
361
  }
360
362
 
363
+ // Don't try to acknowledge if socket is not in open state
364
+ if (this.readyState !== 1) {
365
+ return Promise.resolve(); // Silently ignore acknowledgment for closed sockets
366
+ }
367
+
361
368
  return this.send({
362
369
  messageId: event.data.id,
363
370
  type: 'ack',
371
+ }).catch((error) => {
372
+ // Gracefully handle send errors (like INVALID_STATE_ERROR) to prevent test issues
373
+ if (error.message === 'INVALID_STATE_ERROR') {
374
+ return Promise.resolve(); // Socket was closed, ignore the acknowledgment
375
+ }
376
+ throw error; // Re-throw other errors
364
377
  });
365
378
  }
366
379
 
@@ -38,14 +38,31 @@ describe('plugin-mercury', () => {
38
38
  },
39
39
  timestamp: Date.now(),
40
40
  trackingId: `suffix_${uuid.v4()}_${Date.now()}`,
41
+ sessionId: 'mercury-default-session',
41
42
  };
42
43
 
43
44
  beforeEach(() => {
44
45
  clock = FakeTimers.install({now: Date.now()});
45
46
  });
46
47
 
47
- afterEach(() => {
48
+ afterEach(async () => {
48
49
  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
+ }
49
66
  });
50
67
 
51
68
  beforeEach(() => {
@@ -76,6 +93,7 @@ describe('plugin-mercury', () => {
76
93
  });
77
94
 
78
95
  mercury = webex.internal.mercury;
96
+ mercury.defaultSessionId = 'mercury-default-session';
79
97
  });
80
98
 
81
99
  afterEach(() => {
@@ -301,7 +319,7 @@ describe('plugin-mercury', () => {
301
319
  })
302
320
  .then(() => {
303
321
  assert.called(offlineSpy);
304
- assert.calledWith(offlineSpy, {code, reason});
322
+ assert.calledWith(offlineSpy, {code, reason, sessionId: 'mercury-default-session'});
305
323
  switch (action) {
306
324
  case 'close':
307
325
  assert.called(permanentSpy);