cleaning up tuning and untuning keeping it simple

This commit is contained in:
talksik
2022-05-14 11:08:37 -05:00
parent 7c66a6a4f3
commit 723427b7cc
3 changed files with 32 additions and 14 deletions
+10 -2
View File
@@ -85,9 +85,13 @@ export default function InitializeWs(io: any) {
const roomName = `connectedLine:${req.lineId}`;
socket.join(roomName);
const clientUserIdsInRoom = [...(io.sockets.adapter.rooms.get(roomName) ?? [])].map(
(otherUserSocketId: string) => socketIdsToUserIds[otherUserSocketId],
);
io.in(roomName).emit(
ServerResponseChannels.SOMEONE_CONNECTED_TO_LINE,
new SomeoneConnectedResponse(req.lineId, userInfo.userId),
new SomeoneConnectedResponse(req.lineId, userInfo.userId, clientUserIdsInRoom),
);
});
@@ -98,12 +102,16 @@ export default function InitializeWs(io: any) {
const roomName = `tunedLine:${req.lineId}`;
socket.join(roomName);
const clientUserIdsInRoom = [...(io.sockets.adapter.rooms.get(roomName) ?? [])].map(
(otherUserSocketId: string) => socketIdsToUserIds[otherUserSocketId],
);
// we want to notify everyone connected to the line even if they are not tuned in
const connectedLineRoomName = `connectedLine:${req.lineId}`;
io.in(connectedLineRoomName).emit(
ServerResponseChannels.SOMEONE_TUNED_INTO_LINE,
new SomeoneTunedResponse(req.lineId, userInfo.userId),
new SomeoneTunedResponse(req.lineId, userInfo.userId, clientUserIdsInRoom),
);
});
+2 -2
View File
@@ -71,7 +71,7 @@ export class ConnectToLineRequest {
constructor(public lineId: string) {}
}
export class SomeoneConnectedResponse {
constructor(public lineId: string, public userId: string) {}
constructor(public lineId: string, public userId: string, public allUsers: string[]) {}
}
export class SomeoneDisconnectedResponse {
@@ -81,7 +81,7 @@ export class TuneToLineRequest {
constructor(public lineId: string) {}
}
export class SomeoneTunedResponse {
constructor(public lineId: string, public userId: string) {}
constructor(public lineId: string, public userId: string, public allUsers: string[]) {}
}
export class UntuneFromLineRequest {
constructor(public lineId: string) {}
@@ -25,11 +25,29 @@ import { useAsyncFn } from 'react-use';
import { updateLineMemberState } from '../api/NirvanaApi';
import UpdateLineMemberState from '@nirvana/core/requests/updateLineMemberState.request';
import useAuth from './AuthProvider';
import { User } from '@nirvana/core/models/user.model';
type LineIdToMasterLine = {
[lineId: string]: MasterLineData;
};
// TODO: implement the below to save renders
type TunedMembersMap = {
[lineId: string]: string[];
};
type ConnectedMembesMap = {
[lineId: string]: string[];
};
type UserMap = {
[userId: string]: User;
};
type BroadcastersMap = {
[lineId: string]: string[];
};
interface IRealTimeRoomProvider {
roomsMap: LineIdToMasterLine;
@@ -103,11 +121,7 @@ export function RealTimeRoomProvider({ children }: { children: React.ReactChild
return;
}
if (draft[res.lineId].connectedMemberIds) {
draft[res.lineId].connectedMemberIds.push(res.userId);
} else {
draft[res.lineId].connectedMemberIds = [res.userId];
}
draft[res.lineId].connectedMemberIds = res.allUsers;
});
});
@@ -121,11 +135,7 @@ export function RealTimeRoomProvider({ children }: { children: React.ReactChild
return;
}
if (draft[res.lineId].tunedInMemberIds) {
draft[res.lineId].tunedInMemberIds.push(res.userId);
} else {
draft[res.lineId].tunedInMemberIds = [res.userId];
}
draft[res.lineId].tunedInMemberIds = res.allUsers;
});
});