Переработаны роутеры приложения

Переписано APi WebSocket для работы с новыми роутерами
This commit is contained in:
2025-10-03 17:11:31 +03:00
parent d75fb7ec3d
commit 6ec6523d71
54 changed files with 2593 additions and 3749 deletions

8
ws/utils/broadcaster.js Normal file
View File

@@ -0,0 +1,8 @@
function broadcast(wss, message) {
wss.clients.forEach(client => {
if (client.readyState === 1) {
client.send(JSON.stringify(message));
}
});
}
module.exports = { broadcast };

14
ws/utils/ping.js Normal file
View File

@@ -0,0 +1,14 @@
function setupPing(ws) {
const interval = setInterval(() => {
if (ws.readyState === 1) {
ws.ping("ping");
} else {
clearInterval(interval);
}
}, 30000);
ws.on("pong", (data) => {
console.log("📡 PONG from client:", data.toString());
});
}
module.exports = { setupPing };