-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
47 lines (39 loc) · 1.03 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
var express = require('express');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var path = require('path');
var userCount = 0;
app.use(express.static(path.join(__dirname, 'public')));
io.on('connection', function(socket){
console.log('a user connected');
userCount++;
io.emit('userCount', userCount);
socket.on('disconnect', function(){
userCount--;
console.log('user disconnected');
});
socket.on('next', function(msg){
io.emit('next', msg);
console.log('Next Level');
});
socket.on('1', function(msg){
io.emit('1', msg);
console.log('message: ' + msg);
});
socket.on('2', function(msg){
io.emit('2', msg);
console.log('message: ' + msg);
});
socket.on('player', function(msg){
io.emit('player', msg);
console.log('player: ' + msg);
});
socket.on('player2', function(msg){
io.emit('player2', msg);
console.log('player2: ' + msg);
});
});
http.listen(3000, function(){
console.log('listening on *:3000');
});