-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
33 lines (25 loc) · 785 Bytes
/
index.js
File metadata and controls
33 lines (25 loc) · 785 Bytes
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
const content = require('fs').readFileSync(__dirname + '/index.html', 'utf8');
const httpServer = require('http').createServer((req, res) => {
// serve the index.html file
res.setHeader('Content-Type', 'text/html');
res.setHeader('Content-Length', Buffer.byteLength(content));
res.end(content);
});
const io = require('socket.io')(httpServer);
io.on('connection', socket => {
console.log('connected');
socket.on('message', (data) => {
io.emit('message',data);
console.log(data);
});
socket.on('LocationUpdated', (data) => {
io.emit('position',data);
console.log(data);
});
socket.on('NewOrder', (data) => {
io.emit('new',data);
console.log(data);
//io.emit('message', data);
});
});
httpServer.listen(process.env.PORT || 5000);