-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsocketEvents.js
More file actions
31 lines (27 loc) · 914 Bytes
/
socketEvents.js
File metadata and controls
31 lines (27 loc) · 914 Bytes
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
module.exports = (io, modal) => {
// Set socket.io listeners.
io.on('connection', (socket) => {
// console.log('a user connected');
// On conversation entry, join broadcast channel
socket.on('validate email', (email) => {
modal.users.findOne({ where: { email } }).then((item) => {
if (item) {
socket.emit('email exist', 'Email already exist.');
} else {
socket.emit('new email', 'Email doesn\'t exist.');
}
});
// console.log('joined ' + conversation);
});
socket.on('leave conversation', (conversation) => {
socket.leave(conversation);
// console.log('left ' + conversation);
});
socket.on('new message', (conversation) => {
io.sockets.in(conversation).emit('refresh messages', conversation);
});
socket.on('disconnect', () => {
// console.log('user disconnected');
});
});
};