-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (32 loc) · 971 Bytes
/
index.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
let express = require('express');
let app = express();
let server = app.listen(3000);
let socket = require('socket.io');
let io = socket(server);
let votesFor = 0;
let votesAgainst = 0;
io.sockets.on('connection', newConnection);
app.use('/', express.static('public'));
console.log('My socket server is running')
// app.listen(3000, () => {
// console.log('listening at local host 3000');
// });
function newConnection(socket) {
console.log('new connection ' + socket.id);
socket.on('message', burnMessage);
function burnMessage(data) {
console.log(data.message);
if (data.message === "burn it down") {
votesFor += 1;
}
if (data.message === "save that poor pumpkin") {
votesAgainst += 1;
}
console.log(votesFor, votesAgainst);
let voteData = {
For: votesFor,
Against: votesAgainst
}
io.sockets.emit('message', voteData);
}
}