diff --git a/lib/wss.js b/lib/wss.js index 2701d48..efd2974 100644 --- a/lib/wss.js +++ b/lib/wss.js @@ -79,7 +79,7 @@ const Wss = ({ for (const [id, conn] of this.connections) { if (message.params.connectionIds.indexOf(id) > -1) { this.dumper && this.dumper(encoded, connectionId); - this.connection(id).send(encoded); + this.connection(id)?.send(encoded); } } } else { @@ -106,7 +106,7 @@ const Wss = ({ }); this.dumper && this.dumper(encoded, message.params.connectionId); this.connection(message.params.connectionId) - .send(encoded); + ?.send(encoded); const response = await rq.wait; return response; } catch (e) { @@ -220,7 +220,7 @@ const Wss = ({ id: decoded.id }, decoded); this.dumper && this.dumper(encoded, connectionId); - this.connection(connectionId).send(encoded); + this.connection(connectionId)?.send(encoded); // metrics const ct = process.hrtime(); const f = ct[0] - response.meta.passTrough.time[0]; @@ -236,6 +236,9 @@ const Wss = ({ } refreshConnection(id, connection) { const existing = this.connections.get(id); + if (!existing && !connection) { + return; + } if (existing?.timeOut) { clearTimeout(existing.timeOut); if (!connection) { // update only timeout @@ -261,7 +264,7 @@ const Wss = ({ } connection(id) { this.refreshConnection(id); - return this.connections.get(id).connection; + return this.connections.get(id)?.connection; } async connect() { return await (new Promise((resolve, reject) => {