mirror of https://github.com/calzoneman/sync.git
I think it works
This commit is contained in:
parent
7d232b80dc
commit
8a54000097
17
channel.js
17
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) {
|
||||
|
|
|
@ -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"
|
||||
},
|
||||
|
|
29
playlist.js
29
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) {
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
|
|
|
@ -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
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue