From abf52839dbd804afdc1430efcbc0cb2e7f5cf41b Mon Sep 17 00:00:00 2001
From: Christopher DuBois <chdubois@cisco.com>
Date: Tue, 19 Nov 2024 13:04:01 -0800
Subject: [PATCH 1/3] fix(mercury): add client timestamp

---
 packages/@webex/internal-plugin-mercury/src/mercury.js          | 1 +
 .../@webex/internal-plugin-mercury/test/unit/spec/mercury.js    | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/packages/@webex/internal-plugin-mercury/src/mercury.js b/packages/@webex/internal-plugin-mercury/src/mercury.js
index 25d0a7bbc69..0eb914d74d9 100644
--- a/packages/@webex/internal-plugin-mercury/src/mercury.js
+++ b/packages/@webex/internal-plugin-mercury/src/mercury.js
@@ -211,6 +211,7 @@ const Mercury = WebexPlugin.extend({
         attemptWSUrl = webSocketUrl;
 
         let options = {
+          clientTimestamp: Date.now(),
           forceCloseDelay: this.config.forceCloseDelay,
           pingInterval: this.config.pingInterval,
           pongTimeout: this.config.pongTimeout,
diff --git a/packages/@webex/internal-plugin-mercury/test/unit/spec/mercury.js b/packages/@webex/internal-plugin-mercury/test/unit/spec/mercury.js
index 275cc9c8494..a2c9cdb06cc 100644
--- a/packages/@webex/internal-plugin-mercury/test/unit/spec/mercury.js
+++ b/packages/@webex/internal-plugin-mercury/test/unit/spec/mercury.js
@@ -448,7 +448,7 @@ describe('plugin-mercury', () => {
             assert.calledWith(
               Socket.prototype.open,
               sinon.match(/ws:\/\/providedurl.com/),
-              sinon.match.any
+              sinon.match.has('clientTimestamp', clock.now + 2) // 2 for 2 ticks
             );
           });
         });

From e852931d61b29cd20b287aa9ed247bb642e8b757 Mon Sep 17 00:00:00 2001
From: Christopher DuBois <chdubois@cisco.com>
Date: Tue, 19 Nov 2024 13:37:48 -0800
Subject: [PATCH 2/3] fix(tick): only tick once for mockWebsocket

---
 .../@webex/internal-plugin-mercury/test/unit/spec/mercury.js  | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/packages/@webex/internal-plugin-mercury/test/unit/spec/mercury.js b/packages/@webex/internal-plugin-mercury/test/unit/spec/mercury.js
index a2c9cdb06cc..ca28720bfbe 100644
--- a/packages/@webex/internal-plugin-mercury/test/unit/spec/mercury.js
+++ b/packages/@webex/internal-plugin-mercury/test/unit/spec/mercury.js
@@ -435,6 +435,8 @@ describe('plugin-mercury', () => {
 
       describe('when webSocketUrl is provided', () => {
         it('connects to Mercury with provided url', () => {
+          const clientTimestamp = Date.now();
+          sinon.useFakeTimers(clientTimestamp);
           const webSocketUrl = 'ws://providedurl.com';
           const promise = mercury.connect(webSocketUrl);
 
@@ -448,7 +450,7 @@ describe('plugin-mercury', () => {
             assert.calledWith(
               Socket.prototype.open,
               sinon.match(/ws:\/\/providedurl.com/),
-              sinon.match.has('clientTimestamp', clock.now + 2) // 2 for 2 ticks
+              sinon.match.has('clientTimestamp', clientTimestamp + 1) // process.nextTick(() => mockWebSocket.open()); the mock websocket has a clock.tick of 1
             );
           });
         });

From f8665298be7cdd546b47407191639993ba6add0e Mon Sep 17 00:00:00 2001
From: Christopher DuBois <chdubois@cisco.com>
Date: Wed, 20 Nov 2024 17:52:46 -0800
Subject: [PATCH 3/3] fix(mercury): query param instead

---
 .../@webex/internal-plugin-mercury/src/mercury.js    |  3 ++-
 .../test/unit/spec/mercury.js                        | 12 +++++-------
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/packages/@webex/internal-plugin-mercury/src/mercury.js b/packages/@webex/internal-plugin-mercury/src/mercury.js
index 0eb914d74d9..5c94ebc4265 100644
--- a/packages/@webex/internal-plugin-mercury/src/mercury.js
+++ b/packages/@webex/internal-plugin-mercury/src/mercury.js
@@ -185,6 +185,8 @@ const Mercury = WebexPlugin.extend({
           webSocketUrl.query.multipleConnections = true;
         }
 
+        webSocketUrl.query.clientTimestamp = Date.now();
+
         return url.format(webSocketUrl);
       });
   },
@@ -211,7 +213,6 @@ const Mercury = WebexPlugin.extend({
         attemptWSUrl = webSocketUrl;
 
         let options = {
-          clientTimestamp: Date.now(),
           forceCloseDelay: this.config.forceCloseDelay,
           pingInterval: this.config.pingInterval,
           pongTimeout: this.config.pongTimeout,
diff --git a/packages/@webex/internal-plugin-mercury/test/unit/spec/mercury.js b/packages/@webex/internal-plugin-mercury/test/unit/spec/mercury.js
index ca28720bfbe..cd65a870e0c 100644
--- a/packages/@webex/internal-plugin-mercury/test/unit/spec/mercury.js
+++ b/packages/@webex/internal-plugin-mercury/test/unit/spec/mercury.js
@@ -435,8 +435,6 @@ describe('plugin-mercury', () => {
 
       describe('when webSocketUrl is provided', () => {
         it('connects to Mercury with provided url', () => {
-          const clientTimestamp = Date.now();
-          sinon.useFakeTimers(clientTimestamp);
           const webSocketUrl = 'ws://providedurl.com';
           const promise = mercury.connect(webSocketUrl);
 
@@ -449,8 +447,8 @@ describe('plugin-mercury', () => {
             assert.isFalse(mercury.connecting, 'Mercury is not connecting');
             assert.calledWith(
               Socket.prototype.open,
-              sinon.match(/ws:\/\/providedurl.com/),
-              sinon.match.has('clientTimestamp', clientTimestamp + 1) // process.nextTick(() => mockWebSocket.open()); the mock websocket has a clock.tick of 1
+              sinon.match(/ws:\/\/providedurl.com.*clientTimestamp[=]\d+/),
+              sinon.match.any
             );
           });
         });
@@ -785,16 +783,16 @@ describe('plugin-mercury', () => {
       it('uses provided webSocketUrl', () =>
         webex.internal.mercury
           ._prepareUrl('ws://provided.com')
-          .then((wsUrl) => assert.match(wsUrl, /provided.com/)));
+          .then((wsUrl) => assert.match(wsUrl, /.*provided.com.*/)));
       it('requests text-mode WebSockets', () =>
         webex.internal.mercury
           ._prepareUrl()
-          .then((wsUrl) => assert.match(wsUrl, /outboundWireFormat=text/)));
+          .then((wsUrl) => assert.match(wsUrl, /.*outboundWireFormat=text.*/)));
 
       it('requests the buffer state message', () =>
         webex.internal.mercury
           ._prepareUrl()
-          .then((wsUrl) => assert.match(wsUrl, /bufferStates=true/)));
+          .then((wsUrl) => assert.match(wsUrl, /.*bufferStates=true.*/)));
 
       it('does not add conditional properties', () =>
         webex.internal.mercury._prepareUrl().then((wsUrl) => {