From 90ec516fbb88c09a9ccd33583d9266f4ccc8b21d Mon Sep 17 00:00:00 2001 From: Jack Anderson Date: Fri, 31 Mar 2017 12:32:21 -0400 Subject: [PATCH 1/3] more server side logging, for science --- app.js | 14 ++++++++++++-- logger.js | 7 +++++++ package.json | 1 + public/javascripts/host.js | 7 ++++++- public/javascripts/join.js | 6 ++++++ 5 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 logger.js diff --git a/app.js b/app.js index 4eded85..647dc6e 100644 --- a/app.js +++ b/app.js @@ -8,10 +8,18 @@ var app = express(); var server = http.createServer(app); var io = require('socket.io').listen(server, {log: false}); var lessCompiler = require('express-less-middleware')(); +var logger = require('./logger'); var rooms = {}; var userCount = 0; +var logEvent = function(event, data) { + logger.info({ + event: event, + data: data + }, 'socket event'); +}; + /** * Method for passing events between host and clients * Use this method only when incoming event name matches @@ -20,6 +28,7 @@ var userCount = 0; var setupRoomEvents = function(socket,room,events) { var emitFn = function(eventName) { return function(data) { + logEvent(eventName, data); io.sockets.in(room).emit(eventName, data); }; }; @@ -96,7 +105,7 @@ app.get(/^\/([0-9a-z]{1,5})$/, routes.invite); // Listen on the port. server.listen(app.get('port'), function() { - console.log('BitPoints is ready to go at http://localhost:' + config.port); + logger.info('BitPoints is ready to go at http://localhost:' + config.port); }); // Socket stuff. @@ -108,8 +117,8 @@ io.sockets.on('connection', function (socket) { var hostRoomId; socket.on('createRoom', function (data) { + logEvent('createRoom', data); - console.log('Room', data.roomId, 'created.'); rooms[data.roomId] = data; socket.join(data.roomId); host = true; @@ -123,6 +132,7 @@ io.sockets.on('connection', function (socket) { }); socket.on('joinRoom', function (data) { + logEvent('joinRoom', data); // Set client socket metadata. myName = data.name; diff --git a/logger.js b/logger.js new file mode 100644 index 0000000..c588f2d --- /dev/null +++ b/logger.js @@ -0,0 +1,7 @@ +var bunyan = require('bunyan'); + +module.exports = bunyan.createLogger({ + name: 'bitpoints-logger', + level: 'info' +}); + diff --git a/package.json b/package.json index b6cd776..f1da539 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ }, "dependencies": { "body-parser": "^1.15.0", + "bunyan": "^1.8.9", "cookie-parser": "^1.4.1", "errorhandler": "^1.4.3", "express": "4.13.4", diff --git a/public/javascripts/host.js b/public/javascripts/host.js index 9a73d2f..33c8325 100644 --- a/public/javascripts/host.js +++ b/public/javascripts/host.js @@ -97,6 +97,7 @@ var getNumVotes = function() { var processVotes = function() { voteData = { + votes: votes, average: -1, trueAverage: -1, min: -1, @@ -327,7 +328,11 @@ var page = new BP.Page({ } } - socket.emit('roundEnd',{roomId: roomId, outcome: outcomeText}); + socket.emit('roundEnd',{ + roomId: roomId, + roundData: voteData, + outcome: outcomeText + }); }, toggleRound: function(e, $el){ diff --git a/public/javascripts/join.js b/public/javascripts/join.js index 141f2b1..b43e8ca 100644 --- a/public/javascripts/join.js +++ b/public/javascripts/join.js @@ -49,6 +49,8 @@ var page = new BP.Page({ socket: socket, + voting: false, + socketEvents: { 'roomRefresh': 'joinRoom', 'newRound': 'reset', @@ -138,6 +140,7 @@ var page = new BP.Page({ }, reset: function(data) { + this.voting = true; this.$lastVote.removeClass('lastVote'); if(data.ticket){ this.$ticketInfo.html(': '+data.ticket.key+''); } this.$status.hide().filter('.newRound').show(); @@ -145,6 +148,7 @@ var page = new BP.Page({ }, endRound: function(data) { + this.voting = false; var text = 'Voting is closed.'; if (data.outcome) { @@ -207,6 +211,8 @@ var page = new BP.Page({ }, submitEstimate: function(e, $el) { + if (!this.voting) { return; } + $('.lastVote').removeClass('lastVote'); var points = $el.addClass('lastVote').data('value'), From 4da5dd77e65fb5ef91d13872e9ed8190d0a224b8 Mon Sep 17 00:00:00 2001 From: Jack Anderson Date: Mon, 3 Apr 2017 16:13:23 -0400 Subject: [PATCH 2/3] fix some mobile style problems re avatars --- public/stylesheets/style.less | 10 ++++++++++ public/stylesheets/voterRoom.less | 21 +++++++++------------ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/public/stylesheets/style.less b/public/stylesheets/style.less index 975c32a..363166b 100644 --- a/public/stylesheets/style.less +++ b/public/stylesheets/style.less @@ -125,6 +125,16 @@ html { padding-top: 80px; } + #voterRoomInfo { + padding: 5px 10px; + + .voterImageSmall { + width: 20px; + height: 20px; + margin: 0 0 0 5px; + } + } + table#estimateOptions { td { font-size: 2em; diff --git a/public/stylesheets/voterRoom.less b/public/stylesheets/voterRoom.less index 8c99714..7f36e6c 100644 --- a/public/stylesheets/voterRoom.less +++ b/public/stylesheets/voterRoom.less @@ -3,26 +3,21 @@ */ #voterRoomInfo { display: block; - height: 60px; - padding: 0 20px; + padding: 10px 20px; background: rgba(0,0,0,0.5); - line-height: 60px; font-size: 14px; font-weight: bold; - #voterList { - float: right; - - .avatars { - float: right; - } + #voterList .avatars { + display: inline-block; + vertical-align: middle; } .voterImageSmall { float: left; height: 30px; width: 30px; - margin: 15px 5px; + margin: 0 0 0 5px; } } @@ -33,14 +28,15 @@ .status { display: none; - width: 100%; height: 20px; padding: 10px; margin: 10px 0; border-radius: 6px; line-height: 20px; background: rgba(0,0,0,0.5); - color: white; + color: @text; + font-size: 14px; + font-weight: bold; &.roundEnd { display: block; @@ -48,6 +44,7 @@ &.newRound { background: @accentColor; + color: white; } } From 0bbfe0a3c708059d2d085d0892ca29fd1db5482e Mon Sep 17 00:00:00 2001 From: Jack Anderson Date: Mon, 3 Apr 2017 16:36:10 -0400 Subject: [PATCH 3/3] do not log deckChange...this kills the fluentd --- app.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app.js b/app.js index 647dc6e..09ffccd 100644 --- a/app.js +++ b/app.js @@ -13,6 +13,10 @@ var logger = require('./logger'); var rooms = {}; var userCount = 0; +var loggableEvents = [ + 'newVote','newRound','roundEnd','kickVoter','updateVoters' +]; + var logEvent = function(event, data) { logger.info({ event: event, @@ -28,7 +32,9 @@ var logEvent = function(event, data) { var setupRoomEvents = function(socket,room,events) { var emitFn = function(eventName) { return function(data) { - logEvent(eventName, data); + if (_.includes(loggableEvents, eventName)) { + logEvent(eventName, data); + } io.sockets.in(room).emit(eventName, data); }; };