diff --git a/channel.js b/channel.js index e653bad8..97942c67 100644 --- a/channel.js +++ b/channel.js @@ -142,7 +142,7 @@ Channel.prototype.loadDump = function() { fs.readFile("chandump/" + this.name, function(err, data) { if(err) { if(err.code == "ENOENT") { - Logger.errlog.log("WARN: missing dump for.Media " + this.name); + Logger.errlog.log("WARN: missing dump for " + this.name); this.initialized = true; this.saveDump(); } @@ -155,6 +155,9 @@ Channel.prototype.loadDump = function() { try { this.logger.log("*** Loading channel dump from disk"); data = JSON.parse(data); + /* Load the playlist */ + + // Old if(data.queue) { for(var i = 0; i < data.queue.length; i++) { var e = data.queue[i]; @@ -162,23 +165,21 @@ Channel.prototype.loadDump = function() { var p = this.playlist.makeItem(m); p.queueby = data.queue[i].queueby ? data.queue[i].queueby : ""; - if(e.temp !== undefined) { - p.temp = e.temp; - } + p.temp = e.temp; this.playlist.items.append(p); } this.sendAll("playlist", this.playlist.items.toArray()); - if(this.playlist.current) - this.sendAll("setCurrent", this.playlist.current.uid); this.broadcastPlaylistMeta(); + this.playlist.current = this.playlist.first; + this.playlist.startPlayback(); } + // Current else if(data.playlist) { var chan = this; this.playlist.load(data.playlist, function() { chan.sendAll("playlist", chan.playlist.items.toArray()); - if(chan.playlist.current) - chan.sendAll("setCurrent", chan.playlist.current.uid); chan.broadcastPlaylistMeta(); + chan.playlist.startPlayback(data.playlist.time); }); } for(var key in data.opts) { diff --git a/package.json b/package.json index a1a6de1c..37546e0b 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Calvin Montgomery", "name": "CyTube", "description": "Online media synchronizer and chat", - "version": "2.0.1", + "version": "2.0.2", "repository": { "url": "http://github.com/calzoneman/sync" }, diff --git a/playlist.js b/playlist.js index 9ec73078..56679943 100644 --- a/playlist.js +++ b/playlist.js @@ -98,6 +98,14 @@ Playlist.prototype.dump = function() { }; } +Playlist.prototype.die = function () { + this.clear(); + if(this._leadInterval) { + clearInterval(this._leadInterval); + this._leadInterval = false; + } +} + Playlist.prototype.load = function(data, callback) { this.clear(); for(var i in data.pl) { @@ -109,7 +117,6 @@ Playlist.prototype.load = function(data, callback) { this.items.append(it); if(i == parseInt(data.pos)) { this.current = it; - this.startPlayback(data.time); } } @@ -214,7 +221,6 @@ Playlist.prototype.addYouTubePlaylist = function(data, callback) { var pl = this; InfoGetter.getMedia(data.id, data.type, function(err, vids) { - console.log(vids.length); if(err) { callback(err, null); return; @@ -354,26 +360,21 @@ Playlist.prototype.lead = function(lead) { } Playlist.prototype.startPlayback = function(time) { - if(this.current.media === "loading") { - setTimeout(function() { - this.startPlayback(time); - }.bind(this), 100); - return; - } this.current.media.paused = false; this.current.media.currentTime = time || -1; var pl = this; - if(this.leading && !this._leadInterval && !isLive(this.current.media.type)) { + if(this._leadInterval) { + clearInterval(this._leadInterval); + this._leadInterval = false; + } + this.on("changeMedia")(this.current.media); + if(this.leading && !isLive(this.current.media.type)) { + this.on("changeMedia")(this.current.media); this._lastUpdate = Date.now(); this._leadInterval = setInterval(function() { pl._leadLoop(); }, 1000); } - else if(!this.leading && this._leadInterval) { - clearInterval(this._leadInterval); - this._leadInterval = false; - } - this.on("changeMedia")(this.current.media); } function isLive(type) { diff --git a/server.js b/server.js index c409c99e..c5b3e83b 100644 --- a/server.js +++ b/server.js @@ -9,7 +9,7 @@ The above copyright notice and this permission notice shall be included in all c THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -const VERSION = "2.0.1"; +const VERSION = "2.0.2"; var fs = require("fs"); var Logger = require("./logger.js"); @@ -185,6 +185,7 @@ exports.unload = function(chan) { if(chan.registered) { chan.saveDump(); } + chan.playlist.die(); exports.channels[chan.name] = null; delete exports.channels[chan.name]; } diff --git a/www/assets/js/callbacks.js b/www/assets/js/callbacks.js index 42f5b982..2d6d2f0e 100644 --- a/www/assets/js/callbacks.js +++ b/www/assets/js/callbacks.js @@ -720,6 +720,7 @@ Callbacks = { li.hide("blind", function() { li.remove(); }); + return true; } }); }, @@ -729,6 +730,7 @@ Callbacks = { queueAction({ fn: function () { playlistMove(data.from, data.after); + return true; } }); } @@ -749,6 +751,7 @@ Callbacks = { $("#queue").scrollTop(0); var scroll = li.position().top - $("#queue").position().top; $("#queue").scrollTop(scroll); + return true; }, can_wait: true });