IO-2935-Add-Enhanced-Websocket-Provider - PR notes, Admin UI, Expanded Join/Leave room functionality, moved test button to the client id (Imex / Rome) in footer, so it is still there, just invisible.
Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
@@ -11,12 +11,17 @@ function createLogEvent(socket, level, message) {
|
||||
logger.log("ioredis-log-event", level, socket.user.email, null, { wsmessage: message });
|
||||
}
|
||||
|
||||
const redisSocketEvents = (io) => {
|
||||
const redisSocketEvents = (io, { addUserToRoom, getUsersInRoom, removeUserFromRoom }) => {
|
||||
// Room management and broadcasting events
|
||||
function registerRoomAndBroadcastEvents(socket) {
|
||||
socket.on("join-bodyshop-room", async (bodyshopUUID) => {
|
||||
socket.join(bodyshopUUID);
|
||||
await addUserToRoom(bodyshopUUID, { uid: socket.user.uid, email: socket.user.email });
|
||||
createLogEvent(socket, "DEBUG", `Client joined bodyshop room: ${bodyshopUUID}`);
|
||||
|
||||
// Notify all users in the room about the updated user list
|
||||
const usersInRoom = await getUsersInRoom(bodyshopUUID);
|
||||
io.to(bodyshopUUID).emit("room-users-updated", usersInRoom);
|
||||
});
|
||||
|
||||
socket.on("leave-bodyshop-room", async (bodyshopUUID) => {
|
||||
@@ -24,10 +29,30 @@ const redisSocketEvents = (io) => {
|
||||
createLogEvent(socket, "DEBUG", `Client left bodyshop room: ${bodyshopUUID}`);
|
||||
});
|
||||
|
||||
socket.on("get-room-users", async (bodyshopUUID, callback) => {
|
||||
const usersInRoom = await getUsersInRoom(bodyshopUUID);
|
||||
callback(usersInRoom);
|
||||
});
|
||||
|
||||
socket.on("broadcast-to-bodyshop", async (bodyshopUUID, message) => {
|
||||
io.to(bodyshopUUID).emit("bodyshop-message", message);
|
||||
createLogEvent(socket, "INFO", `Broadcast message to bodyshop ${bodyshopUUID}`);
|
||||
});
|
||||
|
||||
socket.on("disconnect", async () => {
|
||||
createLogEvent(socket, "DEBUG", `User disconnected.`);
|
||||
|
||||
// Get all rooms the socket is part of
|
||||
const rooms = Array.from(socket.rooms).filter((room) => room !== socket.id);
|
||||
|
||||
for (const bodyshopUUID of rooms) {
|
||||
await removeUserFromRoom(bodyshopUUID, { uid: socket.user.uid, email: socket.user.email });
|
||||
|
||||
// Notify all users in the room about the updated user list
|
||||
const usersInRoom = await getUsersInRoom(bodyshopUUID);
|
||||
io.to(bodyshopUUID).emit("room-users-updated", usersInRoom);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Register all socket events for a given socket connection
|
||||
|
||||
Reference in New Issue
Block a user