-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat.js
More file actions
35 lines (34 loc) · 1.03 KB
/
chat.js
File metadata and controls
35 lines (34 loc) · 1.03 KB
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
const GAME_MESSAGE = 'game-message'
const CHAT_MESSAGE_SELF = 'chat-message-self'
const ERROR_MESSAGE = 'error-message'
const PERSONAL_MESSAGE = 'personal-message'
const CHAT_MESSAGE = 'chat-message'
function Chat(io, socket) {
return {
comms: io,
commsSelf: socket,
error(id, message) {
this.comms.to(id).emit(ERROR_MESSAGE, message)
},
gameExceptSender(roomName, message) {
this.commsSelf.to(roomName).emit(GAME_MESSAGE, message)
},
room(roomName, message) {
this.comms.to(this.commsSelf.id).emit(CHAT_MESSAGE_SELF, message)
this.commsSelf.to(roomName).emit(CHAT_MESSAGE, message)
},
game(roomName, message) {
this.comms.to(roomName).emit(GAME_MESSAGE, message)
},
toSelf(id, message) {
this.comms.to(id).emit(PERSONAL_MESSAGE, message)
},
toSelfInTopic(id, message, topic) {
this.comms.to(id).emit(topic, message)
},
toRoomInTopic(roomName, message, topic) {
this.comms.to(roomName).emit(topic, message)
},
}
}
module.exports = Chat