I think it works

This commit is contained in:
calzoneman 2013-07-03 15:51:35 -04:00
parent 7d232b80dc
commit 8a54000097
5 changed files with 30 additions and 24 deletions

View File

@ -142,7 +142,7 @@ Channel.prototype.loadDump = function() {
fs.readFile("chandump/" + this.name, function(err, data) { fs.readFile("chandump/" + this.name, function(err, data) {
if(err) { if(err) {
if(err.code == "ENOENT") { 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.initialized = true;
this.saveDump(); this.saveDump();
} }
@ -155,6 +155,9 @@ Channel.prototype.loadDump = function() {
try { try {
this.logger.log("*** Loading channel dump from disk"); this.logger.log("*** Loading channel dump from disk");
data = JSON.parse(data); data = JSON.parse(data);
/* Load the playlist */
// Old
if(data.queue) { if(data.queue) {
for(var i = 0; i < data.queue.length; i++) { for(var i = 0; i < data.queue.length; i++) {
var e = data.queue[i]; var e = data.queue[i];
@ -162,23 +165,21 @@ Channel.prototype.loadDump = function() {
var p = this.playlist.makeItem(m); var p = this.playlist.makeItem(m);
p.queueby = data.queue[i].queueby ? data.queue[i].queueby 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.playlist.items.append(p);
} }
this.sendAll("playlist", this.playlist.items.toArray()); this.sendAll("playlist", this.playlist.items.toArray());
if(this.playlist.current)
this.sendAll("setCurrent", this.playlist.current.uid);
this.broadcastPlaylistMeta(); this.broadcastPlaylistMeta();
this.playlist.current = this.playlist.first;
this.playlist.startPlayback();
} }
// Current
else if(data.playlist) { else if(data.playlist) {
var chan = this; var chan = this;
this.playlist.load(data.playlist, function() { this.playlist.load(data.playlist, function() {
chan.sendAll("playlist", chan.playlist.items.toArray()); chan.sendAll("playlist", chan.playlist.items.toArray());
if(chan.playlist.current)
chan.sendAll("setCurrent", chan.playlist.current.uid);
chan.broadcastPlaylistMeta(); chan.broadcastPlaylistMeta();
chan.playlist.startPlayback(data.playlist.time);
}); });
} }
for(var key in data.opts) { for(var key in data.opts) {

View File

@ -2,7 +2,7 @@
"author": "Calvin Montgomery", "author": "Calvin Montgomery",
"name": "CyTube", "name": "CyTube",
"description": "Online media synchronizer and chat", "description": "Online media synchronizer and chat",
"version": "2.0.1", "version": "2.0.2",
"repository": { "repository": {
"url": "http://github.com/calzoneman/sync" "url": "http://github.com/calzoneman/sync"
}, },

View File

@ -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) { Playlist.prototype.load = function(data, callback) {
this.clear(); this.clear();
for(var i in data.pl) { for(var i in data.pl) {
@ -109,7 +117,6 @@ Playlist.prototype.load = function(data, callback) {
this.items.append(it); this.items.append(it);
if(i == parseInt(data.pos)) { if(i == parseInt(data.pos)) {
this.current = it; this.current = it;
this.startPlayback(data.time);
} }
} }
@ -214,7 +221,6 @@ Playlist.prototype.addYouTubePlaylist = function(data, callback) {
var pl = this; var pl = this;
InfoGetter.getMedia(data.id, data.type, function(err, vids) { InfoGetter.getMedia(data.id, data.type, function(err, vids) {
console.log(vids.length);
if(err) { if(err) {
callback(err, null); callback(err, null);
return; return;
@ -354,26 +360,21 @@ Playlist.prototype.lead = function(lead) {
} }
Playlist.prototype.startPlayback = function(time) { 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.paused = false;
this.current.media.currentTime = time || -1; this.current.media.currentTime = time || -1;
var pl = this; 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._lastUpdate = Date.now();
this._leadInterval = setInterval(function() { this._leadInterval = setInterval(function() {
pl._leadLoop(); pl._leadLoop();
}, 1000); }, 1000);
} }
else if(!this.leading && this._leadInterval) {
clearInterval(this._leadInterval);
this._leadInterval = false;
}
this.on("changeMedia")(this.current.media);
} }
function isLive(type) { function isLive(type) {

View File

@ -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. 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 fs = require("fs");
var Logger = require("./logger.js"); var Logger = require("./logger.js");
@ -185,6 +185,7 @@ exports.unload = function(chan) {
if(chan.registered) { if(chan.registered) {
chan.saveDump(); chan.saveDump();
} }
chan.playlist.die();
exports.channels[chan.name] = null; exports.channels[chan.name] = null;
delete exports.channels[chan.name]; delete exports.channels[chan.name];
} }

View File

@ -720,6 +720,7 @@ Callbacks = {
li.hide("blind", function() { li.hide("blind", function() {
li.remove(); li.remove();
}); });
return true;
} }
}); });
}, },
@ -729,6 +730,7 @@ Callbacks = {
queueAction({ queueAction({
fn: function () { fn: function () {
playlistMove(data.from, data.after); playlistMove(data.from, data.after);
return true;
} }
}); });
} }
@ -749,6 +751,7 @@ Callbacks = {
$("#queue").scrollTop(0); $("#queue").scrollTop(0);
var scroll = li.position().top - $("#queue").position().top; var scroll = li.position().top - $("#queue").position().top;
$("#queue").scrollTop(scroll); $("#queue").scrollTop(scroll);
return true;
}, },
can_wait: true can_wait: true
}); });