-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.js
More file actions
70 lines (56 loc) · 1.61 KB
/
Copy pathapp.js
File metadata and controls
70 lines (56 loc) · 1.61 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
const express = require('express');
const app = express();
const http = require('http');
const server = http.createServer(app);
const io = require('socket.io')(server); // get package and instantiate with server
const LISTEN_PORT = 8080;
app.use(function (req, res, next)
{
res.set('X-Clacks-Overhead', 'GNU Terry Pratchet');
next();
});
app.use((express.static(__dirname + '/public'))); //set root dir to the public folder
// Routes
app.get('/', function(req, res)
{
res.sendFile(__dirname + '/public/index.html');
});
app.get('/livingroom', function(req, res)
{
res.sendFile(__dirname + '/public/livingroom.html');
});
app.get('/warehouse', function(req, res)
{
res.sendFile(__dirname + '/public/warehouse.html');
});
// Websocket events
io.on('connection', function(socket)
{
console.log(socket.id + ' has connected');
//socket.broadcast.emit('playerConnect');
socket.on('disconnect', function(data)
{
console.log(socket.id + ' has disconnected');
//socket.broadcast.emit('playerDisconnect');
});
// Custom events
socket.on('buildChosen', function (data)
{
socket.broadcast.emit('setBuild', data);
});
socket.on('sendInstructs', function (data)
{
socket.broadcast.emit('nextStep', data);
});
socket.on('sendPiece', function(data)
{
socket.broadcast.emit('spawnPiece', data);
});
socket.on('buildComplete', function (data)
{
socket.broadcast.emit('endGame');
});
});
// Start server
server.listen(LISTEN_PORT);
console.log('listening to port: ' + LISTEN_PORT);