Skip to content

Commit

Permalink
Make private things private
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop committed Dec 7, 2024
1 parent 335c520 commit 57f73b5
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions src/sockets/LostConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,32 @@ class LostConnection extends EventEmitter {
ns: 'uwave:sockets', connectionType: 'LostConnection', userID: this.user.id, sessionID,
});

this.initQueued();
this.#initQueued();

this.#removeTimer = setTimeout(() => {
this.close();
this.uw.redis.del(this.key, this.messagesKey);
this.uw.redis.del(this.#key, this.#messagesKey);
}, timeout * 1000);
}

/**
* @private
*/
get key() {
get #key() {
return `http-api:disconnected:${this.sessionID}`;
}

/**
* @private
*/
get messagesKey() {
get #messagesKey() {
return `http-api:disconnected:${this.sessionID}:messages`;
}

/**
* @private
*/
initQueued() {
#initQueued() {
// We expire the keys after timeout*10, because a server restart near the
// end of the timeout might mean that someone fails to reconnect. This way
// we can ensure that everyone still gets the full `timeout` duration to
// reconnect after a server restart, while also not filling up Redis with
// messages to users who left and will never return.
this.uw.redis.multi()
.set(this.key, 'true', 'EX', this.timeout * 10)
.ltrim(this.messagesKey, 0, 0)
.expire(this.messagesKey, this.timeout * 10)
.set(this.#key, 'true', 'EX', this.timeout * 10)
.ltrim(this.#messagesKey, 0, 0)
.expire(this.#messagesKey, this.timeout * 10)
.exec();
}

Expand All @@ -66,7 +57,7 @@ class LostConnection extends EventEmitter {
this.#logger.info({ command, data }, 'queue command');

this.uw.redis.rpush(
this.messagesKey,
this.#messagesKey,
JSON.stringify({ command, data }),
);
}
Expand Down

0 comments on commit 57f73b5

Please sign in to comment.