@webex/internal-plugin-mercury 3.10.0-multi-llms.1 → 3.10.0-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.
@@ -33,8 +33,6 @@ 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);
38
36
  }
39
37
 
40
38
  /**
@@ -360,20 +358,9 @@ export default class Socket extends EventEmitter {
360
358
  return Promise.reject(new Error('`event.data.id` is required'));
361
359
  }
362
360
 
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
-
368
361
  return this.send({
369
362
  messageId: event.data.id,
370
363
  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
377
364
  });
378
365
  }
379
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(async () => {
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, sessionId: 'mercury-default-session'});
304
+ assert.calledWith(offlineSpy, {code, reason});
323
305
  switch (action) {
324
306
  case 'close':
325
307
  assert.called(permanentSpy);
@@ -77,6 +77,7 @@ describe('plugin-mercury', () => {
77
77
  markFailedUrl: sinon.stub().returns(Promise.resolve()),
78
78
  switchActiveClusterIds: sinon.stub(),
79
79
  invalidateCache: sinon.stub(),
80
+ isValidHost: sinon.stub().returns(Promise.resolve(true)),
80
81
  };
81
82
  webex.internal.metrics.submitClientMetrics = sinon.stub();
82
83
  webex.internal.newMetrics.callDiagnosticMetrics.setMercuryConnectedStatus = sinon.stub();
@@ -99,32 +100,9 @@ describe('plugin-mercury', () => {
99
100
  });
100
101
 
101
102
  mercury = webex.internal.mercury;
102
- mercury.defaultSessionId = 'mercury-default-session';
103
103
  });
104
104
 
105
- afterEach(async () => {
106
- // Clean up Mercury connections and internal state
107
- if (mercury) {
108
- try {
109
- await mercury.disconnectAll();
110
- } catch (e) {
111
- // Ignore cleanup errors
112
- }
113
- // Clear any remaining connection promises
114
- if (mercury._connectPromises) {
115
- mercury._connectPromises.clear();
116
- }
117
- }
118
-
119
- // Ensure mock socket is properly closed
120
- if (mockWebSocket && typeof mockWebSocket.close === 'function') {
121
- try {
122
- mockWebSocket.close();
123
- } catch (e) {
124
- // Ignore cleanup errors
125
- }
126
- }
127
-
105
+ afterEach(() => {
128
106
  if (socketOpenStub) {
129
107
  socketOpenStub.restore();
130
108
  }
@@ -132,9 +110,6 @@ describe('plugin-mercury', () => {
132
110
  if (Socket.getWebSocketConstructor.restore) {
133
111
  Socket.getWebSocketConstructor.restore();
134
112
  }
135
-
136
- // Small delay to ensure all async operations complete
137
- await new Promise(resolve => setTimeout(resolve, 10));
138
113
  });
139
114
 
140
115
  describe('#listen()', () => {
@@ -524,13 +499,9 @@ describe('plugin-mercury', () => {
524
499
 
525
500
  // skipping due to apparent bug with lolex in all browsers but Chrome.
526
501
  skipInBrowser(it)('does not continue attempting to connect', () => {
527
- const promise = mercury.connect();
528
-
529
- // Wait for the connection to be established before proceeding
530
- mockWebSocket.open();
502
+ mercury.connect();
531
503
 
532
- return promise.then(() =>
533
- promiseTick(2)
504
+ return promiseTick(2)
534
505
  .then(() => {
535
506
  clock.tick(6 * webex.internal.mercury.config.backoffTimeReset);
536
507
 
@@ -538,8 +509,7 @@ describe('plugin-mercury', () => {
538
509
  })
539
510
  .then(() => {
540
511
  assert.calledOnce(Socket.prototype.open);
541
- })
542
- );
512
+ });
543
513
  });
544
514
  });
545
515
 
@@ -614,11 +584,11 @@ describe('plugin-mercury', () => {
614
584
  });
615
585
 
616
586
  describe('#logout()', () => {
617
- it('calls disconnectAll and logs', () => {
587
+ it('calls disconnect and logs', () => {
618
588
  sinon.stub(mercury.logger, 'info');
619
- sinon.stub(mercury, 'disconnectAll');
589
+ sinon.stub(mercury, 'disconnect');
620
590
  mercury.logout();
621
- assert.called(mercury.disconnectAll);
591
+ assert.called(mercury.disconnect);
622
592
  assert.calledTwice(mercury.logger.info);
623
593
 
624
594
  assert.calledWith(mercury.logger.info.getCall(0), 'Mercury: logout() called');
@@ -630,24 +600,24 @@ describe('plugin-mercury', () => {
630
600
  });
631
601
 
632
602
  it('uses the config.beforeLogoutOptionsCloseReason to disconnect and will send code 3050 for logout', () => {
633
- sinon.stub(mercury, 'disconnectAll');
603
+ sinon.stub(mercury, 'disconnect');
634
604
  mercury.config.beforeLogoutOptionsCloseReason = 'done (permanent)';
635
605
  mercury.logout();
636
- assert.calledWith(mercury.disconnectAll, {code: 3050, reason: 'done (permanent)'});
606
+ assert.calledWith(mercury.disconnect, {code: 3050, reason: 'done (permanent)'});
637
607
  });
638
608
 
639
609
  it('uses the config.beforeLogoutOptionsCloseReason to disconnect and will send code 3050 for logout if the reason is different than standard', () => {
640
- sinon.stub(mercury, 'disconnectAll');
610
+ sinon.stub(mercury, 'disconnect');
641
611
  mercury.config.beforeLogoutOptionsCloseReason = 'test';
642
612
  mercury.logout();
643
- assert.calledWith(mercury.disconnectAll, {code: 3050, reason: 'test'});
613
+ assert.calledWith(mercury.disconnect, {code: 3050, reason: 'test'});
644
614
  });
645
615
 
646
616
  it('uses the config.beforeLogoutOptionsCloseReason to disconnect and will send undefined for logout if the reason is same as standard', () => {
647
- sinon.stub(mercury, 'disconnectAll');
617
+ sinon.stub(mercury, 'disconnect');
648
618
  mercury.config.beforeLogoutOptionsCloseReason = 'done (forced)';
649
619
  mercury.logout();
650
- assert.calledWith(mercury.disconnectAll, undefined);
620
+ assert.calledWith(mercury.disconnect, undefined);
651
621
  });
652
622
  });
653
623
 
@@ -753,12 +723,12 @@ describe('plugin-mercury', () => {
753
723
  return promiseTick(webex.internal.mercury.config.backoffTimeReset).then(() => {
754
724
  // By this time backoffCall and mercury socket should be defined by the
755
725
  // 'connect' call
756
- assert.isDefined(mercury.backoffCalls.get('mercury-default-session'), 'Mercury backoffCall is not defined');
726
+ assert.isDefined(mercury.backoffCall, 'Mercury backoffCall is not defined');
757
727
  assert.isDefined(mercury.socket, 'Mercury socket is not defined');
758
728
  // Calling disconnect will abort the backoffCall, close the socket, and
759
729
  // reject the connect
760
730
  mercury.disconnect();
761
- assert.isUndefined(mercury.backoffCalls.get('mercury-default-session'), 'Mercury backoffCall is still defined');
731
+ assert.isUndefined(mercury.backoffCall, 'Mercury backoffCall is still defined');
762
732
  // The socket will never be unset (which seems bad)
763
733
  assert.isDefined(mercury.socket, 'Mercury socket is not defined');
764
734
 
@@ -776,15 +746,15 @@ describe('plugin-mercury', () => {
776
746
 
777
747
  let reason;
778
748
 
779
- mercury.backoffCalls.clear();
780
- mercury._attemptConnection('ws://example.com', 'mercury-default-session',(_reason) => {
749
+ mercury.backoffCall = undefined;
750
+ mercury._attemptConnection('ws://example.com', (_reason) => {
781
751
  reason = _reason;
782
752
  });
783
753
 
784
754
  return promiseTick(webex.internal.mercury.config.backoffTimeReset).then(() => {
785
755
  assert.equal(
786
756
  reason.message,
787
- `Mercury: prevent socket open when backoffCall no longer defined for ${mercury.defaultSessionId}`
757
+ 'Mercury: prevent socket open when backoffCall no longer defined'
788
758
  );
789
759
  });
790
760
  });
@@ -806,7 +776,7 @@ describe('plugin-mercury', () => {
806
776
  return assert.isRejected(promise).then((error) => {
807
777
  const lastError = mercury.getLastError();
808
778
 
809
- assert.equal(error.message, `Mercury Connection Aborted for ${mercury.defaultSessionId}`);
779
+ assert.equal(error.message, 'Mercury Connection Aborted');
810
780
  assert.isDefined(lastError);
811
781
  assert.equal(lastError, realError);
812
782
  });
@@ -900,7 +870,7 @@ describe('plugin-mercury', () => {
900
870
  },
901
871
  };
902
872
  assert.isUndefined(mercury.mercuryTimeOffset);
903
- mercury._setTimeOffset('mercury-default-session', event);
873
+ mercury._setTimeOffset(event);
904
874
  assert.isDefined(mercury.mercuryTimeOffset);
905
875
  assert.isTrue(mercury.mercuryTimeOffset > 0);
906
876
  });
@@ -910,7 +880,7 @@ describe('plugin-mercury', () => {
910
880
  wsWriteTimestamp: Date.now() + 60000,
911
881
  },
912
882
  };
913
- mercury._setTimeOffset('mercury-default-session', event);
883
+ mercury._setTimeOffset(event);
914
884
  assert.isTrue(mercury.mercuryTimeOffset < 0);
915
885
  });
916
886
  it('handles invalid wsWriteTimestamp', () => {
@@ -921,7 +891,7 @@ describe('plugin-mercury', () => {
921
891
  wsWriteTimestamp: invalidTimestamp,
922
892
  },
923
893
  };
924
- mercury._setTimeOffset('mercury-default-session', event);
894
+ mercury._setTimeOffset(event);
925
895
  assert.isUndefined(mercury.mercuryTimeOffset);
926
896
  });
927
897
  });
@@ -967,6 +937,15 @@ describe('plugin-mercury', () => {
967
937
  ._prepareUrl()
968
938
  .then((wsUrl) => assert.match(wsUrl, /example-2.com/));
969
939
  });
940
+ it('uses high priority url instead of provided webSocketUrl', () => {
941
+ webex.internal.feature.getFeature.onCall(0).returns(Promise.resolve(true));
942
+ webex.internal.services.convertUrlToPriorityHostUrl = sinon
943
+ .stub()
944
+ .returns(Promise.resolve('ws://example-2.com'));
945
+ return webex.internal.mercury
946
+ ._prepareUrl('ws://provided.com')
947
+ .then((wsUrl) => assert.match(wsUrl, /example-2.com/));
948
+ });
970
949
  });
971
950
 
972
951
  describe("when 'web-shared-socket' is enabled", () => {