summaryrefslogtreecommitdiffstats
path: root/index.js
diff options
context:
space:
mode:
authorokalintu <ilkka.oks4nen@gmail.com>2016-01-17 21:01:08 +0200
committerokalintu <ilkka.oks4nen@gmail.com>2016-01-17 21:01:08 +0200
commitbbe122289cd2757b04ff1032d0af03c9ab02f995 (patch)
tree73c1cd05f703030f09d0a7d871ea323baed8eebd /index.js
parent1f9a0537db8d1a28db411843b800510b6846dc8f (diff)
parentd53ac7d764c6eb9f17f6f1403d98cf031136a377 (diff)
fixed minor bugs in logbroadcast
Diffstat (limited to 'index.js')
-rw-r--r--index.js26
1 files changed, 18 insertions, 8 deletions
diff --git a/index.js b/index.js
index f357c41..150c711 100644
--- a/index.js
+++ b/index.js
@@ -2,8 +2,8 @@ var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var port = 1337;
-
-//get port from commandline parameteres if supplied
+var LOGBROADCAST = true;
+//get port from commandline parameteres
if (process.argv.length== 3){
port = process.argv[2];
}
@@ -17,6 +17,10 @@ app.get('/', function(req, res){
app.get('/adm', function(req, res){
res.sendFile(__dirname + '/f/templates/adm.html');
});
+app.get('/log', function(req, res){
+ res.sendFile(__dirname + '/f/templates/log.html');
+});
+
//route all paths beginning with /f/ to real files
app.get('/f/*', function(req, res){
@@ -32,10 +36,13 @@ io.on('connection', function(socket){
socket.emit("userinfo",{"uid":uid,"pw":pw});
socket.emit("quedata",que);
-
+ socket.on("logsubscribe",function(data){
+ log("User "+data.uid+ " has subscribed in logging");
+ socket.join("log");
+ });
socket.on("queadd",function(data){
- log("adding new que entry with user: " +data.name+ " , row " +data.row);
+ log("User " +data.name+ " on row " +data.row+" added to queue");
data.qid= Date.now();
que.push(data);
@@ -43,7 +50,7 @@ io.on('connection', function(socket){
});
socket.on("quepopfirst",function(data){
var deleted = que.shift();
- log("admin deleted "+ deleted.name +" from que");
+ log("admin deleted "+ deleted.name +" from queue");
io.emit("quedata",que);
});
@@ -54,7 +61,7 @@ io.on('connection', function(socket){
socket.emit("err",{"msg":"you're not allowed to remove this entry"});
break;
}
- log(que[i].name+" deleted himself from que");
+ log(que[i].name+" deleted himself from queue");
que.splice(i,1);
io.emit("quedata",que);
break;
@@ -70,9 +77,12 @@ function getTimeString()
}
function log(msg){
- console.log(getTimeString()+": "+msg);
+ var logmsg=getTimeString()+": "+msg;
+ console.log(logmsg);
+ if(LOGBROADCAST){
+ io.to("log").emit("logmessage",logmsg);
+ }
}
-log(port);
http.listen(port, function(){
log('listening on port '+port);
});