Skip to content

Commit 17f60e5

Browse files
committed
Merge branch 'collab-post-ms6-risky' into deploy-risky
2 parents f2fb11f + 78011ce commit 17f60e5

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

comms/server.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,30 @@ const io = require("socket.io")(server, {
1515
io.on("connection", (socket) => {
1616
// emit endCall to the room it was in.
1717
socket.on("disconnecting", () => {
18-
socket.to(Array.from(socket.rooms))
19-
.except(socket.id)
20-
.emit("endCall");
18+
// for each room in the disconnecting socket...
19+
socket.rooms.forEach((target) => {
20+
// ignoring the room matching its own id...
21+
if (target === socket.id) {
22+
return;
23+
}
24+
// get the user ids within the room...
25+
io.sockets.adapter.rooms
26+
.get(target)
27+
.forEach(
28+
(id) => {
29+
// and for each user id in the room not matching
30+
// its own id...
31+
if (id === socket.id) {
32+
return;
33+
}
34+
// leave the target room...
35+
io.sockets.sockets.get(id).leave(target);
36+
console.log(id + " leaves " + target);
37+
// then tell the user id to endCall.
38+
io.to(id).emit("endCall");
39+
}
40+
);
41+
});
2142
});
2243

2344
// join a room and inform the peer that the other person has joined
@@ -27,11 +48,6 @@ io.on("connection", (socket) => {
2748
socket.to(data.target).emit("peerConnected");
2849
});
2950

30-
// leave the room - this is performed as part of a cleanup function.
31-
socket.on("leaveRoom", (data) => {
32-
socket.leave(data.target);
33-
});
34-
3551
// propagate the socket events for starting and handshaking a call forward.
3652
socket.on("startCall", (data) => {
3753
console.log(socket.id + " is starting call in "+ data.target);

peerprep/components/questionpage/CommsPanel.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,6 @@ function CommsPanel({ className, roomId }: Props) {
139139
}
140140

141141
function destroyCallListeners(roomId: string) {
142-
socket.emit("leaveRoom", {
143-
target: roomId,
144-
});
145142
socket.removeAllListeners("startCall");
146143
socket.removeAllListeners("peerConnected");
147144
socket.removeAllListeners("handshakeCall");

0 commit comments

Comments
 (0)