cleaning up tuning and untuning keeping it simple
This commit is contained in:
@@ -85,9 +85,13 @@ export default function InitializeWs(io: any) {
|
|||||||
const roomName = `connectedLine:${req.lineId}`;
|
const roomName = `connectedLine:${req.lineId}`;
|
||||||
socket.join(roomName);
|
socket.join(roomName);
|
||||||
|
|
||||||
|
const clientUserIdsInRoom = [...(io.sockets.adapter.rooms.get(roomName) ?? [])].map(
|
||||||
|
(otherUserSocketId: string) => socketIdsToUserIds[otherUserSocketId],
|
||||||
|
);
|
||||||
|
|
||||||
io.in(roomName).emit(
|
io.in(roomName).emit(
|
||||||
ServerResponseChannels.SOMEONE_CONNECTED_TO_LINE,
|
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}`;
|
const roomName = `tunedLine:${req.lineId}`;
|
||||||
socket.join(roomName);
|
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
|
// we want to notify everyone connected to the line even if they are not tuned in
|
||||||
const connectedLineRoomName = `connectedLine:${req.lineId}`;
|
const connectedLineRoomName = `connectedLine:${req.lineId}`;
|
||||||
|
|
||||||
io.in(connectedLineRoomName).emit(
|
io.in(connectedLineRoomName).emit(
|
||||||
ServerResponseChannels.SOMEONE_TUNED_INTO_LINE,
|
ServerResponseChannels.SOMEONE_TUNED_INTO_LINE,
|
||||||
new SomeoneTunedResponse(req.lineId, userInfo.userId),
|
new SomeoneTunedResponse(req.lineId, userInfo.userId, clientUserIdsInRoom),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ export class ConnectToLineRequest {
|
|||||||
constructor(public lineId: string) {}
|
constructor(public lineId: string) {}
|
||||||
}
|
}
|
||||||
export class SomeoneConnectedResponse {
|
export class SomeoneConnectedResponse {
|
||||||
constructor(public lineId: string, public userId: string) {}
|
constructor(public lineId: string, public userId: string, public allUsers: string[]) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SomeoneDisconnectedResponse {
|
export class SomeoneDisconnectedResponse {
|
||||||
@@ -81,7 +81,7 @@ export class TuneToLineRequest {
|
|||||||
constructor(public lineId: string) {}
|
constructor(public lineId: string) {}
|
||||||
}
|
}
|
||||||
export class SomeoneTunedResponse {
|
export class SomeoneTunedResponse {
|
||||||
constructor(public lineId: string, public userId: string) {}
|
constructor(public lineId: string, public userId: string, public allUsers: string[]) {}
|
||||||
}
|
}
|
||||||
export class UntuneFromLineRequest {
|
export class UntuneFromLineRequest {
|
||||||
constructor(public lineId: string) {}
|
constructor(public lineId: string) {}
|
||||||
|
|||||||
@@ -25,11 +25,29 @@ import { useAsyncFn } from 'react-use';
|
|||||||
import { updateLineMemberState } from '../api/NirvanaApi';
|
import { updateLineMemberState } from '../api/NirvanaApi';
|
||||||
import UpdateLineMemberState from '@nirvana/core/requests/updateLineMemberState.request';
|
import UpdateLineMemberState from '@nirvana/core/requests/updateLineMemberState.request';
|
||||||
import useAuth from './AuthProvider';
|
import useAuth from './AuthProvider';
|
||||||
|
import { User } from '@nirvana/core/models/user.model';
|
||||||
|
|
||||||
type LineIdToMasterLine = {
|
type LineIdToMasterLine = {
|
||||||
[lineId: string]: MasterLineData;
|
[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 {
|
interface IRealTimeRoomProvider {
|
||||||
roomsMap: LineIdToMasterLine;
|
roomsMap: LineIdToMasterLine;
|
||||||
|
|
||||||
@@ -103,11 +121,7 @@ export function RealTimeRoomProvider({ children }: { children: React.ReactChild
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (draft[res.lineId].connectedMemberIds) {
|
draft[res.lineId].connectedMemberIds = res.allUsers;
|
||||||
draft[res.lineId].connectedMemberIds.push(res.userId);
|
|
||||||
} else {
|
|
||||||
draft[res.lineId].connectedMemberIds = [res.userId];
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -121,11 +135,7 @@ export function RealTimeRoomProvider({ children }: { children: React.ReactChild
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (draft[res.lineId].tunedInMemberIds) {
|
draft[res.lineId].tunedInMemberIds = res.allUsers;
|
||||||
draft[res.lineId].tunedInMemberIds.push(res.userId);
|
|
||||||
} else {
|
|
||||||
draft[res.lineId].tunedInMemberIds = [res.userId];
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user