From fef2fed9ed9ae448edd4159010073c59921ee433 Mon Sep 17 00:00:00 2001 From: okalintu Date: Thu, 12 Mar 2015 15:16:30 +0200 Subject: fixed few log messages --- index.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 6462631..9860482 100644 --- a/index.js +++ b/index.js @@ -35,7 +35,7 @@ io.on('connection', function(socket){ 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 +43,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 +54,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; @@ -72,7 +72,6 @@ function getTimeString() function log(msg){ console.log(getTimeString()+": "+msg); } -log(port); http.listen(port, function(){ log('listening on port '+port); }); -- cgit v1.3 From d53ac7d764c6eb9f17f6f1403d98cf031136a377 Mon Sep 17 00:00:00 2001 From: okalintu Date: Thu, 12 Mar 2015 16:55:27 +0200 Subject: added subscribable webinterface for log --- f/scripts/log.js | 15 +++++++++++++++ f/templates/log.html | 16 ++++++++++++++++ index.js | 17 ++++++++++++++--- 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 f/scripts/log.js create mode 100644 f/templates/log.html diff --git a/f/scripts/log.js b/f/scripts/log.js new file mode 100644 index 0000000..5b5409e --- /dev/null +++ b/f/scripts/log.js @@ -0,0 +1,15 @@ +var logapp = angular.module('logapp',[]); + +logapp.controller("logctrl",function($scope){ + $scope.logmessages = []; + var socket= io(); + socket.on("connect",function(data){ + socket.emit("logsubscribe","logclient"); + console.log("socket connected"); + }); + socket.on("logmessage",function(data){ + + $scope.logmessages.push(data); + $scope.$apply(); + }); +}); diff --git a/f/templates/log.html b/f/templates/log.html new file mode 100644 index 0000000..43ae8ff --- /dev/null +++ b/f/templates/log.html @@ -0,0 +1,16 @@ + + + +Queuelog + + + + + + +
+

{{msg}}

+
+ + + diff --git a/index.js b/index.js index 9860482..150c711 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,7 @@ var app = require('express')(); var http = require('http').Server(app); var io = require('socket.io')(http); var port = 1337; - +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,7 +36,10 @@ 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("User " +data.name+ " on row " +data.row+" added to queue"); @@ -70,7 +77,11 @@ function getTimeString() } function log(msg){ - console.log(getTimeString()+": "+msg); + var logmsg=getTimeString()+": "+msg; + console.log(logmsg); + if(LOGBROADCAST){ + io.to("log").emit("logmessage",logmsg); + } } http.listen(port, function(){ log('listening on port '+port); -- cgit v1.3