initially get all tuned in users everywhere as well for visibility

This commit is contained in:
talksik
2022-06-19 12:41:44 -05:00
parent 6df9d1dd40
commit 2642224bb6
3 changed files with 25 additions and 9 deletions
+17 -7
View File
@@ -70,18 +70,28 @@ export default function InitializeWs(io: any) {
socket.on(ServerRequestChannels.CONNECT_TO_LINE, (req: ConnectToLineRequest) => {
// add this user to the room
const roomName = `connectedLine:${req.lineId}`;
socket.join(roomName);
const connectedRoomName = `connectedLine:${req.lineId}`;
const tunedRoomName = `tunedLine:${req.lineId}`;
socket.join(connectedRoomName);
console.log(`${socket.id} user CONNECTED room for line ${Object.keys(socket.rooms)}`);
const clientUserIdsInRoom = [...(io.sockets.adapter.rooms.get(roomName) ?? [])].map(
(otherUserSocketId: string) => socketIdsToUserIds[otherUserSocketId],
);
const clientUserIdsInConnectedRoom = [
...(io.sockets.adapter.rooms.get(connectedRoomName) ?? []),
].map((otherUserSocketId: string) => socketIdsToUserIds[otherUserSocketId]);
io.in(roomName).emit(
const clientUserIdsInTunedRoom = [
...(io.sockets.adapter.rooms.get(tunedRoomName) ?? []),
].map((otherUserSocketId: string) => socketIdsToUserIds[otherUserSocketId]);
io.in(connectedRoomName).emit(
ServerResponseChannels.SOMEONE_CONNECTED_TO_LINE,
new SomeoneConnectedResponse(req.lineId, userInfo.userId, clientUserIdsInRoom),
new SomeoneConnectedResponse(
req.lineId,
userInfo.userId,
clientUserIdsInConnectedRoom,
clientUserIdsInTunedRoom,
),
);
});
+6 -1
View File
@@ -31,7 +31,12 @@ export class ConnectToLineRequest {
constructor(public lineId: string) {}
}
export class SomeoneConnectedResponse {
constructor(public lineId: string, public userId: string, public allUsers: string[]) {}
constructor(
public lineId: string,
public userId: string,
public allConnectedUsers: string[],
public allTunedUsers: string[],
) {}
}
export class SomeoneDisconnectedResponse {
@@ -101,7 +101,8 @@ export function ConversationProvider({ children }: { children: React.ReactNode }
return;
}
draft[res.lineId].connectedUserIds = res.allUsers;
draft[res.lineId].connectedUserIds = res.allConnectedUsers;
draft[res.lineId].tunedInUsers = res.allTunedUsers;
});
});