Compare commits

...

2 Commits

Author SHA1 Message Date
1a151b197b this is so nigger rigged dude I really should just use a class or
something
2025-07-03 11:39:57 -04:00
70180c5d5f muh dik 2025-07-03 10:42:39 -04:00

View File

@ -8,6 +8,7 @@ import {
import striptags from "striptags";
import { PrismaClient } from "../generated/prisma/client.js";
import { createWebsocket } from "./websocket.js";
import { WebSocket } from "ws";
const prisma = new PrismaClient();
@ -151,7 +152,24 @@ const postReplyToStatus = async (
}
};
const ws = createWebsocket();
let ws = createWebsocket();
const reconnect = (ws: WebSocket) => {
if (ws) {
ws.close();
}
return createWebsocket();
};
ws.on("close", () => {
for (let i = 0; i < 5; i++) {
if (ws.readyState !== WebSocket.OPEN) {
setTimeout(() => {
ws = reconnect(ws);
}, 5000);
}
}
});
ws.on("upgrade", () => {
console.log(
@ -159,10 +177,6 @@ ws.on("upgrade", () => {
);
});
ws.on("close", (event: CloseEvent) => {
console.log(`Connection closed: ${event.reason}`);
});
ws.on("open", () => {
setInterval(() => {
ws.send(JSON.stringify({ type: "ping" }));
@ -170,6 +184,10 @@ ws.on("open", () => {
}, 20000);
});
ws.on("pong", (data) => {
console.log(`Pong received: ${JSON.stringify(data.toString("utf-8"))}`);
});
ws.on("message", async (data) => {
try {
const message: WSEvent = JSON.parse(data.toString("utf-8"));