-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (30 loc) · 1 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
var express = require("express"),
app = require("express")(),
server = require('http').createServer(app),
io = require("socket.io").listen(server),
connections = 0;
server.listen(9966);
app.use(express.static(__dirname + "/public"));
io.sockets.on('connection', function (socket) {
connections++;
socket.emit('client connected', connections);
socket.on('left', function(speed) {
socket.broadcast.emit('left', -speed);
});
socket.on('right', function(speed) {
socket.broadcast.emit('right', speed);
});
socket.on('up', function(speed) {
socket.broadcast.emit('up', -speed);
});
socket.on('down', function(speed) {
socket.broadcast.emit('down', speed);
});
socket.on('render style', function(style) {
socket.broadcast.emit('render style', style);
});
socket.on('disconnect', function (socket) {
connections--;
io.sockets.emit('client disconnected', connections);
});
});