From 511a81e313d0723a2d4f9887c1632ff5fc19658d Mon Sep 17 00:00:00 2001 From: SrGooglo Date: Thu, 24 Apr 2025 12:40:29 +0000 Subject: [PATCH] Fix ping measurement to use first available socket --- src/utils/measurePing.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/utils/measurePing.js b/src/utils/measurePing.js index 90ec5e2..cd72003 100755 --- a/src/utils/measurePing.js +++ b/src/utils/measurePing.js @@ -31,15 +31,18 @@ const fetchers = { resolve("failed") }, 5000) - globalThis.__comty_shared_state.ws.sockets - .get("main") - .once("pong", () => { - failTimeout && clearTimeout(failTimeout) + const sockets = globalThis.__comty_shared_state.ws.sockets + let firstSocket = sockets.keys().next().value - resolve(Date.now() - start) - }) + firstSocket = sockets.get(firstSocket) - globalThis.__comty_shared_state.ws.sockets.get("main").emit("ping") + firstSocket.once("pong", () => { + failTimeout && clearTimeout(failTimeout) + + resolve(Date.now() - start) + }) + + firstSocket.emit("ping") }), }