Skip to content

Commit 4872130

Browse files
committed
Emit user join and disconnect events for real-time updates
1 parent 1b44a0c commit 4872130

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

server.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ io.on("connection", (socket) => {
145145
return;
146146
}
147147
handleJoin(socket, docId);
148+
io.to(docId).emit("userJoined", { docId, userId: socket.id });
148149
console.log("Channels:", channels);
149150
});
150151

@@ -174,6 +175,9 @@ io.on("connection", (socket) => {
174175
socket.on("disconnect", () => {
175176
console.log(`Client ${socket.id} disconnected`);
176177
channel.subscribers.delete(socket.id);
178+
for (const docId of channel.docIds) {
179+
io.to(docId).emit("userDisconnected", { docId, userId: socket.id });
180+
}
177181
if (channel.publishers.has(socket.id)) {
178182
const docId = channel.publishers.get(socket.id);
179183
io.to(docId).emit("slideshowStopped", { docId });

0 commit comments

Comments
 (0)