ваше сообщение коммита

This commit is contained in:
2025-06-06 21:56:17 +03:00
parent 80e0cb5272
commit 75e845b5af
22 changed files with 1123 additions and 488 deletions

22
backend/wsHub.js Normal file
View File

@@ -0,0 +1,22 @@
const WebSocket = require('ws');
let wss = null;
const wsClients = new Set();
function initWSS(server) {
wss = new WebSocket.Server({ server });
wss.on('connection', (ws) => {
wsClients.add(ws);
ws.on('close', () => wsClients.delete(ws));
});
}
function broadcastContactsUpdate() {
for (const ws of wsClients) {
if (ws.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify({ type: 'contacts-updated' }));
}
}
}
module.exports = { initWSS, broadcastContactsUpdate };