this is so nigger rigged dude I really should just use a class or

something
This commit is contained in:
2025-07-03 11:39:57 -04:00
parent 70180c5d5f
commit 1a151b197b

View File

@ -8,6 +8,7 @@ import {
import striptags from "striptags"; import striptags from "striptags";
import { PrismaClient } from "../generated/prisma/client.js"; import { PrismaClient } from "../generated/prisma/client.js";
import { createWebsocket } from "./websocket.js"; import { createWebsocket } from "./websocket.js";
import { WebSocket } from "ws";
const prisma = new PrismaClient(); const prisma = new PrismaClient();
@ -153,16 +154,29 @@ const postReplyToStatus = async (
let 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", () => { ws.on("upgrade", () => {
console.log( console.log(
`Websocket connection to ${process.env.PLEROMA_INSTANCE_DOMAIN} successful.` `Websocket connection to ${process.env.PLEROMA_INSTANCE_DOMAIN} successful.`
); );
}); });
ws.on("close", (event: CloseEvent) => {
console.log(`Connection closed: ${event.reason}`);
});
ws.on("open", () => { ws.on("open", () => {
setInterval(() => { setInterval(() => {
ws.send(JSON.stringify({ type: "ping" })); ws.send(JSON.stringify({ type: "ping" }));