From 7401f35e4ad430ebd968e68c0fd313d3417f2d87 Mon Sep 17 00:00:00 2001 From: Mattias Petter Johansson Date: Sat, 5 May 2012 19:32:50 +0200 Subject: [PATCH] Fixed problems with server.js + cleaned up --- server/server.js | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/server/server.js b/server/server.js index 2eef8b9..ed1a76a 100644 --- a/server/server.js +++ b/server/server.js @@ -53,20 +53,25 @@ var handle = query.observe({ */ function checkForSkipping(playlistItemId) { var pli = PlaylistItems.findOne(playlistItemId), - isStillPlaying = !!pli.playing_since, - isPastEnd = ((Number(new Date()) - pli.playing_since + pli.position)) > pli.duration; - - if (!isStillPlaying) { - // Not playing anymore (somebody probably changed tracks, or scrubbed) - return; - } - - if(isPastEnd) { - // Is playing, and has went past the end of the track. - // This means that we should skip to the next track. - var nextSibling = findNextSibling(pli); - if (nextSibling) player.play(nextSibling); + now = Number(new Date()), + hasPlayedPastEnd = !!pli.playing_since && + now - pli.playing_since + pli.position > pli.duration; + + if (hasPlayedPastEnd) { + + // Is playing, and has went past the end of the track. + // This means that we should skip to the next track. + var nextSibling = findNextSibling(pli); + if (nextSibling) player.play(nextSibling); + + } else { + + // Do nothing - this playlistItem did not play past + // end when we expected it to - somebody probably + // changed tracks, or scrubbed. + } + } /*