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
| var express = require("express");
var app = express();
var server = require("http").createServer(app);
var io = require("socket.io").listen(server);
const editJsonFile = require("edit-json-file");
let file = editJsonFile(__dirname + "/data.json");
server.listen(8080, function(){
console.log("listening on port 8080");
});
app.get("/",function(req, res){
res.sendFile(__dirname + "/app.html");
if(file.get("NameEquipe1") === undefined){
file.set("NameEquipe1", "");
}else{
}
});
app.get("/telecommande",function(req, res){
res.sendFile(__dirname + "/telecommande.html");
});
io.sockets.on("connection", function(socket){
if(file.get("ScoreEquipe1") === undefined){
file.set("ScoreEquipe1", "");
}else{
var data = file.get("ScoreEquipe1");
io.sockets.emit("newMsg", data);
}
socket.on("scoreEquipe1", function(data){
console.log("message received", data);
io.sockets.emit("newMsg", data);
file.set("ScoreEquipe1", data);
file.save();
})
socket.on("timer", function(data){
console.log("timer", data);
io.sockets.emit("newTimer", data);
})
}) |
Partager