Skip to content

Commit

Permalink
broadcast heartbeat pings in lobbies
Browse files Browse the repository at this point in the history
  • Loading branch information
p2r3 committed Sep 26, 2024
1 parent a82d96b commit d18d1e0
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions util/lobbies.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,23 @@ module.exports = async function (args, context = epochtal) {
// Create the lobby creation event
await events(["create", "lobby_" + cleanName, auth, message, null, disconnect], context);

// Broadcast a heartbeat ping every 30 seconds
let lobbyHeartbeat;
lobbyHeartbeat = setInterval(async function () {

let lobbyName = null;
for (const name in lobbies.list) {
if (lobbies.list[name] === listEntry) {
lobbyName = name;
break;
}
}
if (!lobbyName) return clearInterval(lobbyHeartbeat);

await events(["send", "lobby_" + lobbyName, { type: "ping" }], context);

}, 30000);

return "SUCCESS";

}
Expand Down

0 comments on commit d18d1e0

Please sign in to comment.