forked from VAR-solutions/socialX-rest-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
socketEvents.js
29 lines (26 loc) · 970 Bytes
/
socketEvents.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
exports = module.exports = function (io) {
// Set socket.io listeners.
io.on('connection', (socket) => {
// console.log('a user connected');
socket.on('connected', (data) => {
socket.broadcast.emit('connected', (data));
})
// socket.on('chat message', function(msg){
// io.emit('chat message', msg);
// });
// On conversation entry, join broadcast channel
socket.on('enter conversation', (conversation) => {
socket.join(conversation);
});
socket.on('leave conversation', (conversation) => {
socket.leave(conversation);
// console.log('left ' + conversation);
})
socket.on('new message', (conversation) => {
io.sockets.in(conversation[0]).emit('new message', conversation[1]);
});
socket.on('disconnect', () => {
//console.log('user disconnected');
});
});
}