-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrequestHandler.js
40 lines (34 loc) · 1.04 KB
/
requestHandler.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
37
38
39
40
exports = module.exports = function (io, chatData) {
var module = {};
module.newPerson = (person) => {
var p = {};
p.nickname = person.nickname;
chatData.onlineCount++;
chatData.online.add(person.nickname);
console.log('There is ' + chatData.onlineCount + ' users online.');
io.emit('new-person', person);
io.emit('online', Array.from(chatData.online));
console.log(Array.from(chatData.online));
return p;
}
module.newMsg = (person, msg) => {
io.emit('new-msg', person, msg);
}
module.isTyping = (person) => {
chatData.typers.add(person.nickname)
io.emit('is-typing', Array.from(chatData.typers));
}
module.stopTyping = (person) => {
console.log(person);
chatData.typers.delete(person.nickname);
io.emit('is-typing', Array.from(chatData.typers));
}
module.disconnect = (person) => {
console.log(person);
chatData.onlineCount--;
chatData.online.delete(person.nickname);
io.emit('online', Array.from(chatData.online));
console.log('There is ' + chatData.onlineCount + ' users online.');
}
return module;
};