-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
35 lines (29 loc) · 903 Bytes
/
server.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
const app = require('./app');
const db = require('./db');
const http = require('http').Server(app);
const io = require('socket.io')(http);
db.connect(err => {
if (err) {
console.error('There was an error connecting to MySQL. ' + err);
process.exit(1);
}
const listener = http.listen(process.env.PORT, (process.env.HOST || 'localhost'), () => {
console.log('Your app is listening on port ' + listener.address().port);
});
});
io.on('connection', socket => {
socket.emit('new', 'New user connected');
socket.on('confirm', msg => console.log(msg));
socket.on('join room', tasklist => {
socket.join(tasklist);
});
socket.on('leave room', tasklist => {
socket.leave(tasklist);
});
socket.on('tasks', tasklist => {
socket.to(tasklist).emit('tasks');
});
socket.on('labels', (type, tasklist) => {
socket.to(tasklist).emit('labels', type);
});
});