Skip to content

Commit

Permalink
fix: connection were created when write is sent
Browse files Browse the repository at this point in the history
  • Loading branch information
Elin Angelow committed Feb 8, 2024
1 parent 6a9b631 commit 8d9faa5
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/wss.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -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];
Expand All @@ -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
Expand All @@ -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) => {
Expand Down

0 comments on commit 8d9faa5

Please sign in to comment.