-
Notifications
You must be signed in to change notification settings - Fork 27
/
sendUserCount.ts
47 lines (43 loc) · 1.26 KB
/
sendUserCount.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { ServerType } from "../common/types/socket/types";
import { TimerStore } from "../common/types/types";
import { frontendRouteRooms } from "../common/common";
interface ISendUserCount {
io: ServerType;
roomName: string;
timerStore: TimerStore;
}
export default ({ io, roomName, timerStore }: ISendUserCount): void => {
// emit the updated number of users in the room
io.to(roomName).emit("usersInRoom", {
numUsers: timerStore[roomName]?.users?.length,
userList: timerStore[roomName]?.users,
});
io.to("public-timers").emit("publicTimers", {
roomStats: Object.keys(timerStore)
.filter((x) => !frontendRouteRooms.includes(x))
.filter((x) => timerStore[x].isPublic)
.sort(
(a, b) =>
timerStore[b].users.length - timerStore[a].users.length
)
.map((room) => ({
room,
numUsers: timerStore[room].users.length,
userList: timerStore[room].users,
isPublic: timerStore[room].isPublic,
})),
});
io.to("admin").emit("publicTimers", {
roomStats: Object.keys(timerStore)
.sort(
(a, b) =>
timerStore[b].users.length - timerStore[a].users.length
)
.map((room) => ({
room,
numUsers: timerStore[room].users.length,
userList: timerStore[room].users,
isPublic: timerStore[room].isPublic,
})),
});
};