From 94037e7de0e716334a27b95af02f752f6a44d632 Mon Sep 17 00:00:00 2001 From: Bronwen Date: Thu, 1 Apr 2021 22:17:43 -0400 Subject: [PATCH] pingtesterooni --- lib/Gateway.js | 9 +++++---- lib/STP/index.js | 7 +++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/Gateway.js b/lib/Gateway.js index af85566..00edcf2 100644 --- a/lib/Gateway.js +++ b/lib/Gateway.js @@ -74,11 +74,12 @@ class Gateway { client.on('ready', async () => { while(pings.length < maxPings) { interactive.info(`[${pings.length + 1}/${maxPings}] Testing connection...`); - // pings.push(await client.ping()); - pings.push(10); - await new Promise(res => setTimeout(res, 1000)); + pings.push(await client.ping()); + // pings.push(10); + await new Promise(res => setTimeout(res, 500)); } - interactive.success(`Test complete. Average Ping: ${pings.reduce((a, v) => a += (v / maxPings), 0)}`) + const average = Math.round(pings.reduce((a, v) => a + v, 0) / maxPings); + interactive.success(`Test complete. Average Ping: ${average}`) client.tcpSocket.destroy(); res(); }); diff --git a/lib/STP/index.js b/lib/STP/index.js index 16d8dea..64bd6f2 100644 --- a/lib/STP/index.js +++ b/lib/STP/index.js @@ -140,6 +140,13 @@ class STPSocket extends EventEmitter { return; } + if (this.readyState === this.SECURED && obj.cmd === 'PONG') { + if (this.pingCallbacks.has(obj.data.id)) { + this.pingCallbacks.get(obj.data.id)(); + } + return; + } + } handshake() {