Skip to content

Commit 77a50c8

Browse files
committed
Fix switching rooms didn't remove you from prior room and refactor
1 parent d034c0d commit 77a50c8

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

index.js

+16-6
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,16 @@ emitter.on("participant-room-data", async (entity) => {
165165
}
166166

167167
if (!participantNameToEntity[participantName]) {
168-
participantNameToEntity[participantName] = { faceMarkerImagePath };
168+
participantNameToEntity[participantName] = {};
169169
}
170170

171+
// Always want to have the latest of these
172+
participantNameToEntity[participantName] = {
173+
...participantNameToEntity[participantName],
174+
faceMarkerImagePath,
175+
lastBatch,
176+
};
177+
171178
let hubStatusVerb = "";
172179
if (inTheHub && !participantNameToEntity[participantName]?.inTheHub) {
173180
hubStatusVerb = "enterred";
@@ -184,7 +191,6 @@ emitter.on("participant-room-data", async (entity) => {
184191
participantNameToEntity[participantName] = {
185192
...participantNameToEntity[participantName],
186193
inTheHub,
187-
lastBatch,
188194
};
189195
emitter.emit("in-the-hub-change");
190196
}
@@ -197,6 +203,14 @@ emitter.on("participant-room-data", async (entity) => {
197203
// Ignore, we already have this person in the right zoom room
198204
return;
199205
}
206+
207+
// Remove them from their previous room
208+
if (previousRoomName) {
209+
roomNameToParticipantNames[previousRoomName] = roomNameToParticipantNames[
210+
previousRoomName
211+
].filter((name) => name !== participantName);
212+
}
213+
200214
if (!roomNameToParticipantNames[roomName]) {
201215
roomNameToParticipantNames[roomName] = [];
202216
}
@@ -206,8 +220,6 @@ emitter.on("participant-room-data", async (entity) => {
206220
participantNameToEntity[participantName] = {
207221
...participantNameToEntity[participantName],
208222
roomName,
209-
faceMarkerImagePath,
210-
lastBatch,
211223
};
212224

213225
verb = "enterred";
@@ -227,8 +239,6 @@ emitter.on("participant-room-data", async (entity) => {
227239
participantNameToEntity[participantName] = {
228240
...participantNameToEntity[participantName],
229241
roomName,
230-
faceMarkerImagePath,
231-
lastBatch,
232242
};
233243

234244
verb = "departed";

0 commit comments

Comments
 (0)