-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
57 lines (47 loc) · 1.37 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
48
49
50
51
52
53
54
55
56
57
var express = require('express');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var path = require('path');
// Initialize appication with route / (that means root of the application)
// app.get('/', function(req, res){
// var express=require('express');
// app.use(express.static(path.join(__dirname)));
// res.sendFile(path.join(__dirname, '', 'index.html'));
// });
var voteStats = [0, 0, 0, 0, 0];
app.use(express.static('./'));
var userSockets = [""];
// Register events on socket connection
io.on('connection', function(socket) {
userSockets.push(socket);
//console.log(socket);
socket.on('chatMessage', function(from, msg) {
io.emit('chatMessage', from, msg);
});
socket.on('notifyUser', function(user) {
//console.log(user)
io.emit('notifyUser', user);
});
socket.on('caroPlay', function(posX, posY) {
//console.log('caroPlay: ', posX, ' ', posY);
socket.broadcast.emit('caroPlay', posX, posY);
})
socket.on('getData', function() {
socket.emit('returnData', voteStats);
});
socket.on('p', function(x) {
socket.broadcast.emit('p', x);
voteStats[x]++;
//console.log(voteStats);
});
socket.on('m', function(x) {
socket.broadcast.emit('m', x);
voteStats[x]--;
});
});
// Listen application request on port 3000
var port = 8124;
http.listen(port, function() {
console.log('listening on *: ', port);
})