-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathio.js
More file actions
40 lines (33 loc) · 875 Bytes
/
io.js
File metadata and controls
40 lines (33 loc) · 875 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
32
33
34
35
36
37
38
39
40
var socketCtrl = require('./controllers/socket');
var Room = require('./models/room');
var io;
function init(server) {
io = require('socket.io')(server);
io.on('connection', function(socket) {
socket.on('register', function(payload) {
socket.user = payload.user;
if (payload.room) socket.join(payload.room._id);
});
socket.on('create-room', function() {
socketCtrl.newRoom(socket.user).then(room => {
socket.join(room.id, () => {
io.to(room.id).emit('update-room', room)
})
})
});
socket.on('join-room', function(roomId) {
socketCtrl.joinRoom(roomId, socket.user).then(room => {
socket.join(room.id, () => {
io.to(room.id).emit('update-room', room)
})
})
});
});
}
function getIo() {
return io;
}
module.exports = {
init,
getIo
}