-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
32 lines (25 loc) · 893 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
var express = require('express');
var app = express();
var server = require('http').Server(app);
var io = require('socket.io')(server);
app.engine('html', require('ejs').renderFile);
// use statements
app.use('/', express.static(__dirname + '/public'));
// set statements
app.set('view engine', 'html');
app.set('views', __dirname + '/public/');
app.get('/', (req, res) => {
res.render('index');
});
io.on('connection', (socket) => {
socket.emit('playerNumber', io.engine.clientsCount);
socket.on('selection', (selectionData) => {
console.log("Player " + selectionData.playerNumber + " seleceted: " + selectionData.selected);
socket.emit('newSelectionMade', selectionData);
});
});
server.listen(process.env.PORT || 3000, () => {
var host = server.address().address;
var port = server.address().port;
console.log('listening at http://%s:%s', host, port);
});