-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusers.js
36 lines (31 loc) · 793 Bytes
/
users.js
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
const users = []
function userJoined(id, username, room) {
const user = { id, name: username, room }
users.push(user)
console.log("userJoined:")
console.log(users)
return user
}
function userLeft(id) {
const userIndex = users.findIndex(user => user.id === id)
if (userIndex !== -1) {
const user = users.splice(userIndex, 1)[0]
console.log("userLeft:")
console.log(users)
return user
}
}
function getCurrentUser(id) {
return users.find(user => user.id === id)
}
function getRoomUsers(room) {
console.log(getRoomUsers)
console.log(users.filter(user => user.room === room))
return users.filter(user => user.room === room)
}
module.exports = {
userJoined,
getCurrentUser,
userLeft,
getRoomUsers
}