Merge remote-tracking branch 'origin/npmjsisdown'

This commit is contained in:
Andrew Kelley 2013-11-25 11:39:13 -05:00
commit 5331c55306
3 changed files with 25 additions and 3 deletions

View file

@ -129,6 +129,12 @@ var actions = {
cb({});
},
},
'whattimeisit': {
permission: null,
fn: function(client, msg, cb) {
cb({msg: new Date()});
},
},
};
function PlayerServer(player, authenticate) {

View file

@ -2157,15 +2157,20 @@ function compareArrays(arr1, arr2) {
}
function formatTime(seconds) {
var sign = "";
if (seconds < 0) {
sign = "-";
seconds = -seconds;
}
seconds = Math.floor(seconds);
var minutes = Math.floor(seconds / 60);
seconds -= minutes * 60;
var hours = Math.floor(minutes / 60);
minutes -= hours * 60;
if (hours !== 0) {
return hours + ":" + zfill(minutes, 2) + ":" + zfill(seconds, 2);
return sign + hours + ":" + zfill(minutes, 2) + ":" + zfill(seconds, 2);
} else {
return minutes + ":" + zfill(seconds, 2);
return sign + minutes + ":" + zfill(seconds, 2);
}
}

View file

@ -54,6 +54,7 @@ function PlayerClient(socket) {
PlayerClient.prototype.handleConnectionStart = function(){
var self = this;
this.updateLibrary(function(){
self.updateServerTime();
self.updateStatus();
self.updatePlaylist();
});
@ -114,6 +115,16 @@ PlayerClient.prototype.updatePlaylist = function(callback){
});
};
PlayerClient.prototype.updateServerTime = function(callback) {
var self = this;
callback = callback || noop;
this.sendCommandName('whattimeisit', function(err, o){
if (err) return callback(err);
self.serverTimeOffset = new Date(o) - new Date();
callback();
});
};
PlayerClient.prototype.updateStatus = function(callback){
var self = this;
callback = callback || noop;
@ -122,7 +133,7 @@ PlayerClient.prototype.updateStatus = function(callback){
self.volume = o.volume;
self.repeat = o.repeat;
self.state = o.state;
self.trackStartDate = o.trackStartDate != null ? new Date(o.trackStartDate) : null;
self.trackStartDate = o.trackStartDate != null ? new Date(new Date(o.trackStartDate) - self.serverTimeOffset) : null;
self.pausedTime = o.pausedTime;
});
this.sendCommandName('currentsong', function(err, id){