From 770bb29eb7e496cc2c1bf84933d373f4c1af66d5 Mon Sep 17 00:00:00 2001 From: TheConnMan Date: Sat, 18 Mar 2017 12:28:01 -0400 Subject: [PATCH 1/9] Add video controller to return currently playing video title --- api/controllers/VideoController.js | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 api/controllers/VideoController.js diff --git a/api/controllers/VideoController.js b/api/controllers/VideoController.js new file mode 100644 index 0000000..2cbb549 --- /dev/null +++ b/api/controllers/VideoController.js @@ -0,0 +1,9 @@ +module.exports = { + current: function(req, res) { + return Video.findOne({ + playing: true + }).then(video => { + res.send('Currently playing: ' + (video ? video.title : 'No video playing')); + }); + } +}; From e426185d5e0e24f6a7bfc70c77fb0fced3cb6298 Mon Sep 17 00:00:00 2001 From: TheConnMan Date: Sat, 18 Mar 2017 14:05:57 -0400 Subject: [PATCH 2/9] Better handle ending the current video if there is not a playing video Closes #168 --- api/services/SyncService.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/api/services/SyncService.js b/api/services/SyncService.js index e1b0b99..8425f3b 100644 --- a/api/services/SyncService.js +++ b/api/services/SyncService.js @@ -118,15 +118,19 @@ function endCurrentVideo(username) { Video.findOne({ playing: true }).exec(function(err, current) { - if (username) { - ChatService.addMachineMessage(username + ' skipped ' + current.title, username, 'videoSkipped'); - } - current.playing = false; - current.save(function() { - logger.info('Publishing end song ' + current.key); - Video.publishUpdate(current.id, current); + if (current) { + if (username) { + ChatService.addMachineMessage(username + ' skipped ' + current.title, username, 'videoSkipped'); + } + current.playing = false; + current.save(function() { + logger.info('Publishing end song ' + current.key); + Video.publishUpdate(current.id, current); + findNextVideo(current); + }); + } else { findNextVideo(current); - }); + } }); } From 1b7dd4924d8acf3d1f24a3feb3fbf4961dd1c92f Mon Sep 17 00:00:00 2001 From: TheConnMan Date: Sat, 18 Mar 2017 14:24:59 -0400 Subject: [PATCH 3/9] Show start times of previously played or currently playing videos Closes #169 --- assets/components/playlist-item.html | 8 +++++++- assets/js/components/playlist-item.js | 4 ++++ assets/js/video.js | 7 ++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/assets/components/playlist-item.html b/assets/components/playlist-item.html index 4121a96..3a5838d 100644 --- a/assets/components/playlist-item.html +++ b/assets/components/playlist-item.html @@ -12,7 +12,13 @@ ({{$ctrl.formatDuration()}})
- {{$ctrl.expectedPlayTime()}} + {{$ctrl.expectedPlayTime()}} +
+
+ {{$ctrl.startTime()}} +
+
+ {{$ctrl.startTime()}}
diff --git a/assets/js/components/playlist-item.js b/assets/js/components/playlist-item.js index f24dd84..6dc70cd 100644 --- a/assets/js/components/playlist-item.js +++ b/assets/js/components/playlist-item.js @@ -7,6 +7,10 @@ function PlaylistItemController($scope, $http, $video, $storage) { return $video.expectedPlayTime(this.video); }; + this.startTime = function() { + return $video.startTime(this.video); + }; + this.skip = function() { return $video.skip(this.username); }; diff --git a/assets/js/video.js b/assets/js/video.js index 698fda1..af8fd82 100644 --- a/assets/js/video.js +++ b/assets/js/video.js @@ -115,6 +115,10 @@ angular return expectedTime.format('LT'); } + function startTime(video) { + return moment(video.startTime).format('LT'); + } + return { push, add, @@ -134,6 +138,7 @@ angular recent, videoInUpcoming, formatDuration, - expectedPlayTime + expectedPlayTime, + startTime }; }]); From 5a717a22e06a420399c0e9297a2bbe699ae75550 Mon Sep 17 00:00:00 2001 From: TheConnMan Date: Sun, 19 Mar 2017 13:41:39 -0400 Subject: [PATCH 4/9] Mark dev build versions with dev --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 41ac31a..c04a9a5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,12 +12,14 @@ script: after_success: - docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"; + VERSION=`node -e "console.log(require('./package.json').version);"`; if [ "$TRAVIS_BRANCH" == "master" ]; then - VERSION=`node -e "console.log(require('./package.json').version);"`; docker tag theconnman/jukebot theconnman/jukebot:$VERSION; docker push theconnman/jukebot:latest; docker push theconnman/jukebot:$VERSION; elif [ "$TRAVIS_BRANCH" == "dev" ]; then + sed -i "s/$VERSION/$VERSION-dev/g" package.json; + docker build -t theconnman/jukebot .; docker tag theconnman/jukebot theconnman/jukebot:latest-dev; docker push theconnman/jukebot:latest-dev; fi From 337c3e7d2d686fd794be597c83b77b649efd1b4e Mon Sep 17 00:00:00 2001 From: TheConnMan Date: Wed, 22 Mar 2017 22:24:50 -0400 Subject: [PATCH 5/9] Add optional Fluent logging --- README.md | 1 + config/bootstrap.js | 19 +++++++++---------- package.json | 1 + 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 3ea591a..209c044 100644 --- a/README.md +++ b/README.md @@ -86,3 +86,4 @@ After that run `docker-compose up -d` and you should be able to access the UI at - **GOOGLE_ANALYTICS_ID** (Optional) - [Google Analytics](https://analytics.google.com/) Tracking ID for site analytics - **VIDEO_HISTORY** (default: 24 * 60) - Number of minutes played videos will stay in the video playlist - **CHAT_HISTORY** (default: 24 * 60) - Number of minutes chats will stay in the chat bar +- **FLUENTD_HOST** (Optional) Fluent host for logging diff --git a/config/bootstrap.js b/config/bootstrap.js index 9ef4094..19afa93 100644 --- a/config/bootstrap.js +++ b/config/bootstrap.js @@ -1,16 +1,15 @@ -/** - * Bootstrap - * (sails.config.bootstrap) - * - * An asynchronous bootstrap function that runs before your Sails app gets lifted. - * This gives you an opportunity to set up your data model, run jobs, or perform some special logic. - * - * For more information on bootstrapping your app, check out: - * http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.bootstrap.html - */ +var log4js = require('log4js'); +var logger = log4js.getLogger('config/bootstrap'); module.exports.bootstrap = function(cb) { + if (process.env.FLUENTD_HOST) { + log4js.addAppender(require('fluent-logger').support.log4jsAppender('jukebot', { + host: process.env.FLUENTD_HOST, + timeout: 3.0 + })); + } + Video.findOne({ playing: true }).then(function(current, err) { diff --git a/package.json b/package.json index 479f06a..046997d 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "keywords": [], "dependencies": { "ejs": "2.3.4", + "fluent-logger": "^2.3.0", "grunt": "1.0.1", "grunt-contrib-clean": "1.0.0", "grunt-contrib-coffee": "1.0.0", From dcf6e577f7708a46c3eb1ee16ea80b2b0aed4beb Mon Sep 17 00:00:00 2001 From: TheConnMan Date: Thu, 23 Mar 2017 17:18:12 -0400 Subject: [PATCH 6/9] Add additional FluentD context tags --- README.md | 1 + config/bootstrap.js | 9 ++++++++- package.json | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 209c044..83cd0d1 100644 --- a/README.md +++ b/README.md @@ -87,3 +87,4 @@ After that run `docker-compose up -d` and you should be able to access the UI at - **VIDEO_HISTORY** (default: 24 * 60) - Number of minutes played videos will stay in the video playlist - **CHAT_HISTORY** (default: 24 * 60) - Number of minutes chats will stay in the chat bar - **FLUENTD_HOST** (Optional) Fluent host for logging +- **FLUENTD_TAGS** (Optional) Add FluentD context tags (format is tag:value,tag2:value2) diff --git a/config/bootstrap.js b/config/bootstrap.js index 19afa93..657641c 100644 --- a/config/bootstrap.js +++ b/config/bootstrap.js @@ -4,9 +4,16 @@ var logger = log4js.getLogger('config/bootstrap'); module.exports.bootstrap = function(cb) { if (process.env.FLUENTD_HOST) { + var tags = (process.env.FLUENTD_TAGS ? process.env.FLUENTD_TAGS.split(',') : []).reduce((allTags, tag) => { + var pair = tag.split(':'); + allTags[pair[0].trim()] = pair.length === 1 ? true : pair[1].trim(); + return allTags; + }, {}); + tags.function = 'JukeBot'; log4js.addAppender(require('fluent-logger').support.log4jsAppender('jukebot', { host: process.env.FLUENTD_HOST, - timeout: 3.0 + timeout: 3.0, + tags })); } diff --git a/package.json b/package.json index 046997d..6e84c21 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "keywords": [], "dependencies": { "ejs": "2.3.4", - "fluent-logger": "^2.3.0", + "fluent-logger": "github:theconnman/fluent-logger-node", "grunt": "1.0.1", "grunt-contrib-clean": "1.0.0", "grunt-contrib-coffee": "1.0.0", From dc4c4481682f1b0e9894d431ac3bc87d44b61b79 Mon Sep 17 00:00:00 2001 From: TheConnMan Date: Thu, 23 Mar 2017 17:24:32 -0400 Subject: [PATCH 7/9] Add Git to the Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index f5a8429..026fcbd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM alpine:3.4 -RUN apk add --no-cache nodejs +RUN apk add --no-cache nodejs git WORKDIR /usr/src/app From b4f2b12759fb523a2683d36c8dc1f1439d394240 Mon Sep 17 00:00:00 2001 From: TheConnMan Date: Sat, 25 Mar 2017 16:59:29 -0400 Subject: [PATCH 8/9] Improve logging statements and levels --- api/controllers/ApiController.js | 5 +++++ api/services/SyncService.js | 5 ++--- api/services/YouTubeService.js | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/api/controllers/ApiController.js b/api/controllers/ApiController.js index af607df..564c1a4 100644 --- a/api/controllers/ApiController.js +++ b/api/controllers/ApiController.js @@ -1,3 +1,6 @@ +const log4js = require('log4js'); +const logger = log4js.getLogger('api/controllers/api'); + var users = {}; var recentlyLeft = []; @@ -12,6 +15,7 @@ module.exports = { var index = recentlyLeft.indexOf(username); if (index === -1) { + logger.debug(users[id] + ' entered the room'); ChatService.addMachineMessage(users[id] + ' entered the room', username, 'userEnter'); } else { recentlyLeft.splice(index, 1); @@ -141,6 +145,7 @@ function userDisconnected(username) { var index = recentlyLeft.indexOf(username); if (index !== -1) { recentlyLeft.splice(index, 1); + logger.debug(username + ' left the room'); ChatService.addMachineMessage(username + ' left the room', username, 'userLeft'); emitListeners(); if (Object.keys(users).length === 0) { diff --git a/api/services/SyncService.js b/api/services/SyncService.js index 8425f3b..92447ac 100644 --- a/api/services/SyncService.js +++ b/api/services/SyncService.js @@ -1,6 +1,6 @@ var Promise = require('promise'); var log4js = require('log4js'); -var logger = log4js.getLogger('api/services/SyncService'); +var logger = log4js.getLogger('api/services/sync'); var SlackWebhook = require('slack-webhook'); var slack = sails.config.globals.slackWebhook ? new SlackWebhook(sails.config.globals.slackWebhook, { @@ -124,7 +124,7 @@ function endCurrentVideo(username) { } current.playing = false; current.save(function() { - logger.info('Publishing end song ' + current.key); + logger.debug('Publishing end song ' + current.key); Video.publishUpdate(current.id, current); findNextVideo(current); }); @@ -152,7 +152,6 @@ function startVideo(video) { video.playing = true; video.played = true; video.startTime = new Date(); - logger.info('Setting timeout'); videoTimeout = setTimeout(endCurrentVideo, video.duration); video.save(() => { Video.publishUpdate(video.id, video); diff --git a/api/services/YouTubeService.js b/api/services/YouTubeService.js index ab8d3d3..6df8f97 100644 --- a/api/services/YouTubeService.js +++ b/api/services/YouTubeService.js @@ -3,7 +3,7 @@ const request = require('request'); const moment = require('moment'); const log4js = require('log4js'); const Youtube = require("youtube-api"); -const logger = log4js.getLogger(); +const logger = log4js.getLogger('api/services/youtube'); Youtube.authenticate({ type: 'key', @@ -40,7 +40,7 @@ function getYouTubeVideo(key, user, canSave=true) { resolve(video); }); } catch (e) { - logger.debug(`Video ${key}: ${e}`); + logger.error(`Error parsing video ${key}: ${e}`); resolve(null); } } else { From 8c48f7d63eea657fc043b13ff6852039b8b84e6b Mon Sep 17 00:00:00 2001 From: TheConnMan Date: Sat, 1 Apr 2017 19:26:38 -0400 Subject: [PATCH 9/9] Version bump to v1.5.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6e84c21..81fb1fc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "JukeBot", - "version": "1.4.4", + "version": "1.5.0", "description": "Slack-Enabled Syncronized Music Listening", "keywords": [], "dependencies": {