This repository has been archived by the owner on Jan 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
64 lines (57 loc) · 1.55 KB
/
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
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
var express = require('express');
var cors = require('cors')
var app = express();
var http = require('http').createServer(app);
var io = require('socket.io')(http);
var port = process.env.PORT || 3000;
app.use(cors());
app.use(express.static('static'));
io.on('connection', function (socket) {
console.log('a client connected');
socket.on('up', () => {
console.log('Input command: UP');
socket.broadcast.emit('up');
});
socket.on('down', () => {
console.log('Input command: DOWN');
socket.broadcast.emit('down');
});
socket.on('left', () => {
console.log('Input command: LEFT');
socket.broadcast.emit('left');
});
socket.on('right', () => {
console.log('Input command: RIGHT');
socket.broadcast.emit('right');
});
socket.on('upright', () => {
console.log('Input command: UP RIGHT');
socket.broadcast.emit('upright');
});
socket.on('downright', () => {
console.log('Input command: DOWN RIGHT');
socket.broadcast.emit('downright');
});
socket.on('upleft', () => {
console.log('Input command: UP LEFT');
socket.broadcast.emit('upleft');
});
socket.on('downleft', () => {
console.log('Input command: DOWN LEFT');
socket.broadcast.emit('downleft');
});
socket.on('brake', () => {
console.log('Input command: BRAKE');
socket.broadcast.emit('brake');
});
socket.on('disconnect', () => {
console.log('user disconnected');
});
socket.on('error', (error) => {
console.log('Error: ', error);
});
});
http.listen(port, () => {
console.log('Listening at port: ', port);
console.log('On localhost, visit: http://localhost:3000');
});