-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
40 lines (31 loc) · 1.09 KB
/
app.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
var express = require('express');
var app = express();
app.use(express.static('public'));
var http = require('http').Server(app);
var port = process.env.PORT || 3000;
// setup my socket server
var io = require('socket.io')(http);
io.on('connection', function(socket) {
const ts = Math.floor(Date.now() / 1000);
console.log('new connection: '+ ts);
const count = io.engine.clientsCount;
console.log("Connected clients: " + count);
// not working
/* socket.on('connected_clients', function(count){
socket.broadcast.emit('connected_clients',count);
}); */
/* socket.on('message', function(msg) {
console.log('Got message from client: ' + msg);
}); */
// Called when the client calls socket.emit('move')
socket.on('move', function(msg) {
console.log('client moving on room: '+msg.room);
socket.broadcast.emit('move', msg.move);
});
});
app.get('/', function(req, res) {
res.sendFile(__dirname + '/public/default.html');
});
http.listen(port, function() {
console.log('listening on *: ' + port);
});