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() {