Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
TheConnMan committed Apr 1, 2017
2 parents da5c8b7 + 8c48f7d commit 4edb9ec
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 27 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,5 @@ 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
- **FLUENTD_TAGS** (Optional) Add FluentD context tags (format is tag:value,tag2:value2)
5 changes: 5 additions & 0 deletions api/controllers/ApiController.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const log4js = require('log4js');
const logger = log4js.getLogger('api/controllers/api');

var users = {};
var recentlyLeft = [];

Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions api/controllers/VideoController.js
Original file line number Diff line number Diff line change
@@ -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'));
});
}
};
23 changes: 13 additions & 10 deletions api/services/SyncService.js
Original file line number Diff line number Diff line change
@@ -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, {
Expand Down Expand Up @@ -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.debug('Publishing end song ' + current.key);
Video.publishUpdate(current.id, current);
findNextVideo(current);
});
} else {
findNextVideo(current);
});
}
});
}

Expand All @@ -148,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);
Expand Down
4 changes: 2 additions & 2 deletions api/services/YouTubeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion assets/components/playlist-item.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
({{$ctrl.formatDuration()}})
</div>
<div class="meta" ng-if="!$ctrl.video.played && !$ctrl.video.playing && !$ctrl.isSuggestion">
<i class="calendar icon"></i> {{$ctrl.expectedPlayTime()}}
<i class="green calendar icon"></i> {{$ctrl.expectedPlayTime()}}
</div>
<div class="meta" ng-if="$ctrl.video.playing && !$ctrl.isSuggestion">
<i class="calendar icon"></i> {{$ctrl.startTime()}}
</div>
<div class="meta" ng-if="$ctrl.video.played && !$ctrl.video.playing && !$ctrl.isSuggestion">
<i class="red calendar icon"></i> {{$ctrl.startTime()}}
</div>
<div class="extra">
<heart video="$ctrl.video" classes="'large'"></heart>
Expand Down
4 changes: 4 additions & 0 deletions assets/js/components/playlist-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
7 changes: 6 additions & 1 deletion assets/js/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ angular
return expectedTime.format('LT');
}

function startTime(video) {
return moment(video.startTime).format('LT');
}

return {
push,
add,
Expand All @@ -134,6 +138,7 @@ angular
recent,
videoInUpcoming,
formatDuration,
expectedPlayTime
expectedPlayTime,
startTime
};
}]);
26 changes: 16 additions & 10 deletions config/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
/**
* 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) {
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,
tags
}));
}

Video.findOne({
playing: true
}).then(function(current, err) {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "JukeBot",
"version": "1.4.4",
"version": "1.5.0",
"description": "Slack-Enabled Syncronized Music Listening",
"keywords": [],
"dependencies": {
"ejs": "2.3.4",
"fluent-logger": "github:theconnman/fluent-logger-node",
"grunt": "1.0.1",
"grunt-contrib-clean": "1.0.0",
"grunt-contrib-coffee": "1.0.0",
Expand Down

0 comments on commit 4edb9ec

Please sign in to comment.