forked from zstrenfel/playground
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsocket.js
42 lines (33 loc) · 1.16 KB
/
socket.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
36
37
38
39
40
41
42
/** Socket File */
module.exports = function(socket) {
var clients, newData;
/** On user connecting */
console.log('user connected');
/** On intialization of game, broadcase to the other user name of opponent. */
socket.on('init', (data) => {
socket.broadcast.to(data.room).emit('init', data.user);
})
/** Name emitted by current user already in the room */
socket.on('give_name', (data) => {
socket.broadcast.to(data.room).emit('take_name', data.user);
})
/** Join the correct room */
/** Send current points to the other user */
socket.on('tell_points', (data) => {
console.log('logging points', data.score, 'to: ', data.room);
socket.broadcast.to(data.room).emit('take_points', data.score);
})
/** Send users correct guess to the other side. */
socket.on('push_message', (data) => {
console.log('recieved push');
socket.broadcast.to(data.room).emit('pull_message', (data));
})
/** On user leaving the room */
socket.on('disconnect', function(){
console.log('user diconnected');
});
socket.on('join_room', (data) => {
console.log('user joinning room: ', data.room)
socket.join(data.room);
})
}