Show users in voice channels before joining
Build and Publish / Metadata (push) Successful in 1s
Build and Publish / BuildAndDeployAmd64 (push) Successful in 24s

This commit is contained in:
mats committed 2026-09-22 10:45:08 +02:00
1 parent a29bd58b0c
commit dee8ef4f7c
3 files changed
+185 -82

No files matched your search

+27 -1
View File
@@ -102,6 +102,11 @@ const server = http.createServer((req, res) => {
res.end(JSON.stringify(iceConfig()));
return;
}
if (req.url.startsWith('/api/rooms')) {
res.writeHead(200, { 'Content-Type': 'application/json', 'Cache-Control': 'no-cache' });
res.end(JSON.stringify(allRoomsSnapshot()));
return;
}
serveStatic(req, res);
});
@@ -131,6 +136,24 @@ function broadcast(room, msg, exceptId) {
}
}
function allRoomsSnapshot() {
const out = {};
for (const [rId, r] of rooms.entries()) {
out[rId] = [...r.values()].map(snapshot);
}
return out;
}
function broadcastRosters() {
const snap = allRoomsSnapshot();
const data = JSON.stringify({ type: 'rosters', rooms: snap });
for (const client of wss.clients) {
if (client.readyState === 1) {
client.send(data);
}
}
}
wss.on('connection', (socket, req) => {
const q = new URL(req.url, 'http://x').searchParams;
const roomId = (q.get('room') || 'general').slice(0, 64);
@@ -146,6 +169,7 @@ wss.on('connection', (socket, req) => {
send({ type: 'hello', id, room: roomId, peers: [...room.values()].filter((p) => p.id !== id).map(snapshot) });
broadcast(room, { type: 'joined', peer: snapshot(client) }, id);
broadcastRosters();
console.log(`[signaling] ${name} (${id}) joined #${roomId} — ${room.size} in room`);
socket.on('message', (raw) => {
@@ -178,6 +202,7 @@ wss.on('connection', (socket, req) => {
sharing: !!msg.state?.sharing,
};
broadcast(room, { type: 'state', from: id, state: client.state }, id);
broadcastRosters();
break;
}
case 'offer':
@@ -200,6 +225,7 @@ wss.on('connection', (socket, req) => {
room.delete(id);
if (room.size === 0) rooms.delete(roomId);
else broadcast(room, { type: 'left', id });
broadcastRosters();
console.log(`[signaling] ${name} (${id}) left #${roomId} — ${room.size} in room`);
});
});
@@ -235,6 +261,6 @@ if (require.main === module) {
startServer();
}
module.exports = { server, wss, iceConfig, interval, startServer };
module.exports = { server, wss, iceConfig, allRoomsSnapshot, interval, startServer };