Skip to content

Commit

Permalink
Check for inactivity
Browse files Browse the repository at this point in the history
  • Loading branch information
Elitex07 committed Jun 26, 2024
1 parent 106cb28 commit ef5bdba
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions build/structures/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class Node {
this.reconnectTries = options.reconnectTries || 3;
this.reconnectAttempt = null;
this.reconnectAttempted = 1;

this.lastStats = Date.now();
}

connect() {
Expand All @@ -75,6 +77,14 @@ class Node {
this.ws.on("error", this.error.bind(this));
this.ws.on("message", this.message.bind(this));
this.ws.on("close", this.close.bind(this));


setInterval(() => {
if(Date.now() - this.lastStats > 5 * 60 * 1000) {
this.riffy.emit("debug", this.name, `Reconnecting to Lavalink due to inactivity (in sending stats) for 5 minutes.`);
this.reconnect();
}
}, 5 * 60 * 1000)
}

open() {
Expand Down Expand Up @@ -154,6 +164,7 @@ class Node {

if (payload.op === "stats") {
this.stats = { ...payload };
this.lastStats = Date.now();
}

if (payload.op === "ready") {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "riffy",
"description": "Riffy is a pro lavalink client. It is designed to be simple and easy to use, with a focus on stability and more features.",
"version": "1.0.5",
"version": "1.0.6",
"main": "build/index.js",
"types": "build/index.d.ts",
"files": [
Expand Down

0 comments on commit ef5bdba

Please sign in to comment.