4 Commits

Author SHA1 Message Date
f621f6c5ae attempt to close the old socket
All checks were successful
deploy / deploy (push) Successful in 20s
2024-01-16 15:37:58 +00:00
3621941a0d e
All checks were successful
deploy / deploy (push) Successful in 22s
2024-01-16 15:36:30 +00:00
fe15f660e6 e
All checks were successful
deploy / deploy (push) Successful in 36s
2024-01-16 15:33:50 +00:00
5c2416e7ee e
Some checks failed
deploy / deploy (push) Has been cancelled
2024-01-16 15:33:11 +00:00
3 changed files with 11 additions and 4 deletions

View File

@ -6,6 +6,7 @@
"scripts": { "scripts": {
"start": "node dist/index.js", "start": "node dist/index.js",
"tsc": "tsc -w", "tsc": "tsc -w",
"build": "tsc",
"dev": "nodemon dist/index.js" "dev": "nodemon dist/index.js"
}, },
"author": "", "author": "",

View File

@ -13,6 +13,7 @@ let totalDeleted: number | undefined;
// Thee last time a map was heard // Thee last time a map was heard
let lastMap: number = Date.now(); let lastMap: number = Date.now();
let socket: WebsocketClient | undefined;
async function update() { async function update() {
if (totalCreated == undefined) { if (totalCreated == undefined) {
@ -45,7 +46,7 @@ async function update() {
} }
async function connectWebsocket() { async function connectWebsocket() {
const socket = new WebsocketClient(WEBSOCKET_URL); socket = new WebsocketClient(WEBSOCKET_URL);
await connectMongo(); await connectMongo();
let beatSaver = await BeatSaverSchema.findOne({ _id: "beatsaver" }); let beatSaver = await BeatSaverSchema.findOne({ _id: "beatsaver" });
if (!beatSaver) { if (!beatSaver) {
@ -129,8 +130,10 @@ async function connectWebsocket() {
connectWebsocket(); connectWebsocket();
cron.schedule("*/5 * * * *", update); cron.schedule("*/5 * * * *", update);
cron.schedule("*/1 * * * *", () => { cron.schedule("*/1 * * * *", () => {
if (lastMap && Date.now() - lastMap > 10000) { // 1 minute
if (lastMap && Date.now() - lastMap > 60_000) {
console.log("Beatsaver websocket is dead, reconnecting"); console.log("Beatsaver websocket is dead, reconnecting");
socket?.close();
connectWebsocket(); connectWebsocket();
} }
}); });

View File

@ -12,6 +12,7 @@ let totalScores: number | undefined;
// Thee last time a score was heard // Thee last time a score was heard
let lastScore: number = Date.now(); let lastScore: number = Date.now();
let socket: WebsocketClient | undefined;
/** /**
* Updates the player count and adds data to influx * Updates the player count and adds data to influx
@ -50,7 +51,7 @@ async function connectWebsocket() {
// set total scores to the current total plays in the database // set total scores to the current total plays in the database
totalScores = leaderboard?.totalPlays || 0; totalScores = leaderboard?.totalPlays || 0;
const socket = new WebsocketClient("wss://scoresaber.com/ws"); socket = new WebsocketClient("wss://scoresaber.com/ws");
socket.onopen = () => { socket.onopen = () => {
console.log("Connected to scoresaber websocket"); console.log("Connected to scoresaber websocket");
}; };
@ -157,8 +158,10 @@ update();
connectWebsocket(); connectWebsocket();
cron.schedule("*/1 * * * *", update); cron.schedule("*/1 * * * *", update);
cron.schedule("*/1 * * * *", () => { cron.schedule("*/1 * * * *", () => {
if (lastScore && Date.now() - lastScore > 10000) { // 1 minute
if (lastScore && Date.now() - lastScore > 60_000) {
console.log("Scoresaber websocket is dead, reconnecting"); console.log("Scoresaber websocket is dead, reconnecting");
socket?.close();
connectWebsocket(); connectWebsocket();
} }
}); });