-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
76 lines (68 loc) · 1.97 KB
/
app.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
65
66
67
68
69
70
71
72
73
74
75
76
var express = require('express'),http = require('http');
var app = express();
var server = http.createServer(app);
app.set('title', 'Moving');
app.set('views',__dirname + '/views');
app.set('view options', { layout: false });
app.get('title');
app.configure(function(){
app.use(express.static(__dirname));
app.use(express.static(__dirname + '/public'));
});
app.get('/',function(req,res){
res.render('index.jade',{layout:false});
});
app.get('/pad.html', function(req, res){
res.sendfile(__dirname + '/pad.html');
});
server.listen(8080);
console.log("Server listen port 8080");
//websockets
var io = require('socket.io').listen(server);
io.sockets.on('connection',function(socket){
console.log("Sockect Connected");
socket.on('prueba', function(conexion){
if(conexion==1){
console.log("New line is open");
var mensaje=1;
io.sockets.emit('nuevoMensaje', mensaje);
}
else {console.log("Conexion False");}
});
socket.on('padCon', function(conexion){
if(conexion==1){
console.log("Pad Detected");
var mensaje=1;
io.sockets.emit('nuevoMensaje', mensaje);
}
else {console.log("Conexion False");}
});
socket.on('upClick', function(conexion){
if(conexion==1){console.log("Click up");
var msg="up";
io.sockets.emit('moveUp', msg);
}
else {console.log("not detected click");}
});
socket.on('downClick', function(conexion){
if(conexion==1){console.log("Click down");
var msg="down";
io.sockets.emit('moveDown', msg);
}
else {console.log("not detected click");}
});
socket.on('rightClick', function(conexion){
if(conexion==1){console.log("Click right");
var msg="right";
io.sockets.emit('moveRight', msg);
}
else {console.log("not detected click");}
});
socket.on('leftClick', function(conexion){
if(conexion==1){console.log("Click left");
var msg="left";
io.sockets.emit('moveLeft', msg);
}
else {console.log("not detected click");}
});
});//Termina io.sockets.on