Notify web clients on bridge connection status: broadcast updates when the bridge connects or disconnects

This commit is contained in:
MayaTheShy
2026-03-21 20:05:45 -04:00
parent 79eca14f4c
commit 9f75866ce7

View File

@@ -554,6 +554,12 @@ wss.on('connection', (ws, req) => {
if (url.startsWith('/ws/bridge')) {
console.log('🌉 CC:Tweaked bridge connected via WebSocket');
bridgeClients.add(ws);
// Notify web clients that the bridge is now connected
broadcastToClients({
type: 'state_update',
bridgeConnected: true,
});
ws.on('message', (raw) => {
try {
@@ -585,11 +591,22 @@ wss.on('connection', (ws, req) => {
ws.on('close', () => {
console.log('🌉 CC:Tweaked bridge disconnected');
bridgeClients.delete(ws);
// Notify web clients that the bridge may be disconnected
broadcastToClients({
type: 'state_update',
bridgeConnected: bridgeClients.size > 0,
});
});
ws.on('error', (error) => {
console.error('❌ Bridge WS error:', error);
bridgeClients.delete(ws);
broadcastToClients({
type: 'state_update',
bridgeConnected: bridgeClients.size > 0,
});
});
return;