Переработаны роутеры приложения
Переписано APi WebSocket для работы с новыми роутерами
This commit is contained in:
8
ws/utils/broadcaster.js
Normal file
8
ws/utils/broadcaster.js
Normal 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
14
ws/utils/ping.js
Normal 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 };
|
||||
Reference in New Issue
Block a user