Resolve merge conflict

This commit is contained in:
calzoneman 2013-10-01 23:05:02 -05:00
commit 9d35636be2
12 changed files with 508 additions and 487 deletions

View File

@ -1,3 +1,17 @@
Tue Oct 01 22:57 2013 CDT
* lib/asyncqueue.js: Add a generalized queue class for queueing async
functions to execute in order
* lib/channel.js, lib/playlist.js: Clean up playlist addition/move/
deletion. Should fix #285.
* lib/server.js: Fix announcement initialization to null
* tests/naokosimulator2013.js: Add a simple bot that authenticates
and vomits a giant list of videos into a channel
* www/assets/js/callbacks.js, www/assets/js/util.js: Clean up
playlist add/move/delete
* www/assets/js/data.js: Update CL_VERSION which I always forget
to do.
* www/assets/js/ui.js: Small fix to comply with server changes
Sun Sep 29 21:30 2013 CDT
* lib/get-info.js: Add an extra check to ytv2 to make sure embedding is
allowed. If not, send a queueFail.

65
lib/asyncqueue.js Normal file
View File

@ -0,0 +1,65 @@
/*
The MIT License (MIT)
Copyright (c) 2013 Calvin Montgomery
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of 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.
*/
var AsyncQueue = function () {
this._q = [];
this._lock = false;
this._tm = 0;
};
AsyncQueue.prototype.next = function () {
if (this._q.length > 0) {
if (!this.lock())
return;
var item = this._q.shift();
var fn = item[0], tm = item[1];
this._tm = Date.now() + item[1];
fn(this);
}
};
AsyncQueue.prototype.lock = function () {
if (this._lock) {
if (this._tm > 0 && Date.now() > this._tm) {
this._tm = 0;
return true;
}
return false;
}
this._lock = true;
return true;
};
AsyncQueue.prototype.release = function () {
var self = this;
if (!self._lock)
return false;
self._lock = false;
setImmediate(function () {
self.next();
});
return true;
};
AsyncQueue.prototype.queue = function (fn) {
var self = this;
self._q.push([fn, 20000]);
self.next();
};
AsyncQueue.prototype.reset = function () {
this._q = [];
this._lock = false;
};
module.exports = AsyncQueue;

View File

@ -22,6 +22,7 @@ var Playlist = require("./playlist");
var sanitize = require("validator").sanitize;
var $util = require("./utilities");
var url = require("url");
var AsyncQueue = require("./asyncqueue");
var Channel = function(name, Server) {
var self = this;
@ -36,6 +37,7 @@ var Channel = function(name, Server) {
self.registered = false;
self.users = [];
self.playlist = new Playlist(self);
self.plqueue = new AsyncQueue();
self.position = -1;
self.drinks = 0;
self.leader = null;
@ -1313,7 +1315,7 @@ Channel.prototype.tryQueue = function(user, data) {
return;
}
if(data.pos == "next" && !this.hasPermission(user, "playlistnext")) {
if (data.pos === "next" && !this.hasPermission(user, "playlistnext")) {
return;
}
@ -1334,17 +1336,35 @@ Channel.prototype.tryQueue = function(user, data) {
return;
}
if(typeof data.title !== "string")
if (typeof data.title !== "string" || data.type !== "cu")
data.title = false;
data.queueby = user ? user.name : "";
data.temp = !this.hasPermission(user, "addnontemp");
if(data.list)
this.addMediaList(data, user);
else
if (data.list) {
if (data.pos === "next") {
data.list.reverse();
if (this.playlist.items.length === 0)
data.list.unshift(data.list.pop());
}
var i = 0;
var self = this;
var next = function () {
if (self.dead)
return;
if (i < data.list.length) {
data.list[i].pos = data.pos;
self.tryQueue(user, data.list[i]);
i++;
setTimeout(next, 2000);
}
};
next();
} else {
this.addMedia(data, user);
}
}
Channel.prototype.addMedia = function(data, user) {
var self = this;
@ -1371,65 +1391,98 @@ Channel.prototype.addMedia = function(data, user) {
data.maxlength = self.hasPermission(user, "exceedmaxlength")
? 0
: this.opts.maxlength;
if (data.pos === "end")
data.pos = "append";
var postAdd = function (item, cached) {
if (self.dead)
return;
if(item.media.type === "cu" && data.title) {
if (data.type === "cu" && data.title) {
var t = data.title;
if(t.length > 100)
t = t.substring(0, 97) + "...";
item.media.title = t;
data.title = t;
}
self.logger.log("### " + user.name + " queued " + item.media.title);
var afterData = function (q, c, m) {
if (data.maxlength && data.seconds > data.maxlength) {
user.socket.emit("queueFail",
"Media is too long!");
q.release();
return;
}
m.pos = data.pos;
m.queueby = data.queueby;
m.temp = data.temp;
var res = self.playlist.addMedia(m);
if (res.error) {
user.socket.emit("queueFail", res.error);
q.release();
return;
}
var item = res.item;
self.logger.log("### " + user.name + " queued " +
item.media.title);
self.sendAll("queue", {
item: item.pack(),
after: item.prev ? item.prev.uid : "prepend"
});
self.broadcastPlaylistMeta();
if(!cached && !item.temp)
if (!c && !item.temp)
self.cacheMedia(item.media);
}
q.release();
};
// No need to check library for livestreams - they aren't cached
if(isLive(data.type)) {
self.playlist.addMedia(data, function (err, data) {
// special case for youtube playlists
if (data.type === "yp") {
self.plqueue.queue(function (q) {
if (self.dead)
return;
if(err) {
if(err === true)
err = false;
if(user)
user.socket.emit("queueFail", err);
self.server.infogetter.getMedia(data.id, data.type,
function (e, vids) {
if (e) {
user.socket.emit("queueFail", e);
q.release();
return;
}
else {
postAdd(data, false);
if (data.pos === "next") {
vids.reverse();
if (self.playlist.length === 0)
vids.unshift(vids.pop());
}
var fake = { release: function () { } };
var cb = afterData.bind(self, fake, false);
for (var i = 0; i < vids.length; i++) {
cb(vids[i]);
}
q.release();
});
});
return;
}
// Don't search library if the channel isn't registered
if(!self.registered) {
self.playlist.addMedia(data, function(err, item) {
// Don't check library for livestreams or if the channel is
// unregistered
if (!self.registered || isLive(data.type)) {
self.plqueue.queue(function (q) {
if (self.dead)
return;
if(err) {
if(err === true)
err = false;
if(user)
user.socket.emit("queueFail", err);
var cb = afterData.bind(self, q, false);
self.server.infogetter.getMedia(data.id, data.type,
function (e, m) {
if (self.dead)
return;
if (e) {
user.socket.emit("queueFail", e);
q.release();
return;
}
cb(m);
});
});
} else {
postAdd(item, false);
}
});
return;
}
self.server.db.getLibraryItem(self.name, data.id,
function (err, item) {
if (self.dead)
@ -1441,84 +1494,46 @@ Channel.prototype.addMedia = function(data, user) {
}
if (item !== null) {
var m = new Media(item.id, item.title, item.seconds, item.type);
if(data.maxlength && m.seconds > data.maxlength) {
if (data.maxlength && item.seconds > data.maxlength) {
user.socket.emit("queueFail", "Media is too long!");
return;
}
data.media = m;
self.playlist.addCachedMedia(data, function (err, item) {
self.plqueue.queue(function (q) {
if (self.dead)
return;
if(err) {
if(err === true)
err = false;
if(user)
user.socket.emit("queueFail", err);
return;
} else {
postAdd(item, true);
}
afterData.bind(self, q, true)(item);
});
} else {
self.playlist.addMedia(data, function(err, item) {
self.plqueue.queue(function (q) {
if (self.dead)
return;
if(err) {
if(err === true)
err = false;
if(user)
user.socket.emit("queueFail", err);
self.server.infogetter.getMedia(data.id, data.type,
function (e, m) {
if (self.dead)
return;
} else {
postAdd(item, false);
}
});
}
});
}
Channel.prototype.addMediaList = function(data, user) {
var chan = this;
this.playlist.addMediaList(data, function(err, item) {
if (chan.dead)
return;
if(err) {
if(err === true)
err = false;
if(user)
user.socket.emit("queueFail", err);
if (e) {
user.socket.emit("queueFail", e);
q.release();
return;
}
else {
chan.logger.log("### " + user.name + " queued " + item.media.title);
item.temp = data.temp;
item.queueby = data.queueby;
chan.sendAll("queue", {
item: item.pack(),
after: item.prev ? item.prev.uid : "prepend"
afterData.bind(self, q, false)(m);
});
});
chan.broadcastPlaylistMeta();
if(!item.temp)
chan.cacheMedia(item.media);
}
});
}
};
Channel.prototype.tryQueuePlaylist = function(user, data) {
var self = this;
if(!this.hasPermission(user, "playlistaddlist")) {
if (!self.hasPermission(user, "playlistaddlist")) {
return;
}
if(typeof data.name != "string" ||
typeof data.pos != "string") {
if(typeof data.name !== "string" ||
typeof data.pos !== "string") {
return;
}
@ -1537,10 +1552,18 @@ Channel.prototype.tryQueuePlaylist = function(user, data) {
});
return;
}
data.list = pl;
data.queueby = user.name;
data.temp = !self.hasPermission(user, "addnontemp");
self.addMediaList(data, user);
if (data.pos === "next") {
pl.reverse();
if (self.playlist.items.length === 0)
pl.unshift(pl.pop());
}
for (var i = 0; i < pl.length; i++) {
pl[i].pos = data.pos;
pl[i].temp = !self.hasPermission(user, "addnontemp");
self.addMedia(pl[i], user);
}
});
}
@ -1572,15 +1595,20 @@ Channel.prototype.trySetTemp = function(user, data) {
Channel.prototype.dequeue = function(uid) {
var chan = this;
function afterDelete() {
chan.sendAll("delete", {
var self = this;
self.plqueue.queue(function (q) {
if (self.dead)
return;
if (self.playlist.remove(uid)) {
self.sendAll("delete", {
uid: uid
});
chan.broadcastPlaylistMeta();
self.broadcastPlaylistMeta();
}
if(!this.playlist.remove(uid, afterDelete))
return;
q.release();
});
}
Channel.prototype.tryDequeue = function(user, data) {
@ -1651,6 +1679,7 @@ Channel.prototype.tryJumpTo = function(user, data) {
Channel.prototype.clearqueue = function() {
this.playlist.clear();
this.plqueue.reset();
this.sendAll("playlist", this.playlist.items.toArray());
this.broadcastPlaylistMeta();
}
@ -1668,6 +1697,7 @@ Channel.prototype.shufflequeue = function() {
var n = [];
var pl = this.playlist.items.toArray(false);
this.playlist.clear();
this.plqueue.reset();
while(pl.length > 0) {
var i = parseInt(Math.random() * pl.length);
var item = this.playlist.makeItem(pl[i].media);
@ -1717,32 +1747,36 @@ Channel.prototype.tryUpdate = function(user, data) {
}
Channel.prototype.move = function(data, user) {
var chan = this;
function afterMove() {
if (chan.dead)
var self = this;
self.plqueue.queue(function (q) {
if (self.dead)
return;
if (self.playlist.move(data.from, data.after)) {
var moveby = user && user.name ? user.name : null;
if (typeof data.moveby !== "undefined")
moveby = data.moveby;
var fromit = chan.playlist.items.find(data.from);
var afterit = chan.playlist.items.find(data.after);
var aftertitle = afterit && afterit.media ? afterit.media.title : "";
var fromit = self.playlist.items.find(data.from);
var afterit = self.playlist.items.find(data.after);
var aftertitle = (afterit && afterit.media)
? afterit.media.title : "";
if (fromit) {
chan.logger.log("### " + user.name + " moved " + fromit.media.title
+ (aftertitle ? " after " + aftertitle : ""));
self.logger.log("### " + user.name + " moved " +
fromit.media.title +
(aftertitle ? " after " + aftertitle : ""));
}
chan.sendAll("moveVideo", {
self.sendAll("moveVideo", {
from: data.from,
after: data.after,
moveby: moveby
});
}
this.playlist.move(data.from, data.after, afterMove);
q.release();
});
}
Channel.prototype.tryMove = function(user, data) {

View File

@ -23,6 +23,7 @@ module.exports = function (Server) {
// This should cut down on needing to restart the server
var d = domain.create();
d.on("error", function (err) {
Logger.errlog.log(err.trace());
Logger.errlog.log("urlRetrieve failed: " + err);
Logger.errlog.log("Request was: " + options.host + options.path);
callback(503, err);
@ -81,14 +82,18 @@ module.exports = function (Server) {
} else if(status === 403) {
callback("Private video", null);
return;
} else if(status === 400) {
callback("Invalid video", null);
return;
} else if(status === 503) {
callback("API failure", null);
return;
} else if(status !== 200) {
callback(true, null);
callback("HTTP " + status, null);
return;
}
var buffer = data;
try {
data = JSON.parse(data);
if (data.entry.yt$accessControl) {
@ -611,6 +616,8 @@ module.exports = function (Server) {
getMedia: function (id, type, callback) {
if(type in this.Getters) {
this.Getters[type](id, callback);
} else {
callback("Unknown media type '" + type + "'", null);
}
}
};

View File

@ -10,6 +10,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
*/
ULList = require("./ullist").ULList;
var AsyncQueue = require("./asyncqueue");
var Media = require("./media").Media;
var AllPlaylists = {};
@ -50,9 +51,7 @@ function Playlist(chan) {
"mediaUpdate": [],
"remove": [],
};
this.lock = false;
this.action_queue = [];
this._qaInterval = false;
this.fnqueue = new AsyncQueue();
AllPlaylists[name] = this;
this.channel = chan;
@ -86,28 +85,6 @@ function Playlist(chan) {
});
}
Playlist.prototype.queueAction = function(data) {
this.action_queue.push(data);
if(this._qaInterval)
return;
var pl = this;
this._qaInterval = setInterval(function() {
var data = pl.action_queue.shift();
if(data.waiting) {
if(!("expire" in data))
data.expire = Date.now() + 10000;
if(Date.now() < data.expire)
pl.action_queue.unshift(data);
}
else
data.fn();
if(pl.action_queue.length == 0) {
clearInterval(pl._qaInterval);
pl._qaInterval = false;
}
}, 100);
}
Playlist.prototype.dump = function() {
var arr = this.items.toArray();
var pos = 0;
@ -222,204 +199,54 @@ Playlist.prototype.add = function(item, pos) {
return false;
}
Playlist.prototype.addCachedMedia = function(data, callback) {
var pos = "append";
if(data.pos == "next") {
if(!this.current)
pos = "prepend";
else
Playlist.prototype.addMedia = function (data) {
var pos = data.pos;
if (pos === "next") {
if (this.current !== null)
pos = this.current.uid;
else
pos = "append";
}
var it = this.makeItem(data.media);
it.temp = data.temp;
it.queueby = data.queueby;
var pl = this;
var action = {
fn: function() {
var err = pl.add(it, pos);
callback(err, err ? null : it);
},
waiting: false
var m = new Media(data.id, data.title, data.seconds, data.type);
var item = this.makeItem(m);
item.queueby = data.queueby;
item.temp = data.temp;
return {
item: item,
error: this.add(item, pos)
};
this.queueAction(action);
}
Playlist.prototype.addMedia = function(data, callback) {
if(data.type == "yp") {
this.addYouTubePlaylist(data, callback);
return;
}
var pos = "append";
if(data.pos == "next") {
if(!this.current)
pos = "prepend";
else
pos = this.current.uid;
}
var it = this.makeItem(null);
var pl = this;
var action = {
fn: function() {
var err = pl.add(it, pos);
callback(err, err ? null : it);
},
waiting: true
};
this.queueAction(action);
// Pre-cached data
if(typeof data.title === "string" &&
typeof data.seconds === "number") {
if(data.maxlength && data.seconds > data.maxlength) {
action.expire = 0;
callback("Media is too long!", null);
return;
}
it.media = new Media(data.id, data.title, data.seconds, data.type);
action.waiting = false;
return;
}
this.server.infogetter.getMedia(data.id, data.type, function(err, media) {
if(err) {
action.expire = 0;
callback(err, null);
return;
}
if(data.maxlength && media.seconds > data.maxlength) {
action.expire = 0;
callback("Media is too long!", null);
return;
}
it.media = media;
it.temp = data.temp;
it.queueby = data.queueby;
action.waiting = false;
});
}
Playlist.prototype.addMediaList = function(data, callback) {
var start = false;
if(data.pos == "next") {
data.list = data.list.reverse();
start = data.list[data.list.length - 1];
}
if(this.items.length != 0)
start = false;
var pl = this;
for(var i = 0; i < data.list.length; i++) {
var x = data.list[i];
x.pos = data.pos;
if(start && x == start) {
pl.addMedia(x, function (err, item) {
if(err) {
callback(err, item);
}
else {
callback(err, item);
pl.current = item;
pl.startPlayback();
}
});
}
else {
pl.addMedia(x, callback);
Playlist.prototype.remove = function (uid) {
var self = this;
var item = self.items.find(uid);
if (item && self.items.remove(uid)) {
if (item === self.current) {
setImmediate(function () { self._next(); });
}
return true;
} else {
return false;
}
}
Playlist.prototype.addYouTubePlaylist = function(data, callback) {
var pos = "append";
if(data.pos == "next") {
if(!this.current)
pos = "prepend";
else
pos = this.current.uid;
}
var pl = this;
this.server.infogetter.getMedia(data.id, data.type, function(err, vids) {
if(err) {
callback(err, null);
return;
}
if(data.pos === "next")
vids.reverse();
vids.forEach(function(media) {
if(data.maxlength && media.seconds > data.maxlength) {
callback("Media is too long!", null);
return;
}
var it = pl.makeItem(media);
it.temp = data.temp;
it.queueby = data.queueby;
pl.queueAction({
fn: function() {
var err = pl.add(it, pos);
callback(err, err ? null : it);
},
});
});
});
}
Playlist.prototype.remove = function(uid, callback) {
var pl = this;
this.queueAction({
fn: function() {
var item = pl.items.find(uid);
if(pl.items.remove(uid)) {
if(callback)
callback();
if(item == pl.current)
pl._next();
}
},
waiting: false
});
}
Playlist.prototype.move = function(from, after, callback) {
var pl = this;
this.queueAction({
fn: function() {
pl._move(from, after, callback);
},
waiting: false
});
}
Playlist.prototype._move = function(from, after, callback) {
Playlist.prototype.move = function (from, after) {
var it = this.items.find(from);
if (!this.items.remove(from))
return;
return false;
if (after === "prepend") {
if (!this.items.prepend(it))
return;
}
else if(after === "append") {
return false;
} else if (after === "append") {
if (!this.items.append(it))
return;
return false;
} else if (!this.items.insertAfter(it, after)) {
return false;
}
else if(!this.items.insertAfter(it, after))
return;
callback();
return true;
}
Playlist.prototype.next = function() {
@ -429,12 +256,10 @@ Playlist.prototype.next = function() {
var it = this.current;
if (it.temp) {
var pl = this;
this.remove(it.uid, function() {
pl.on("remove")(it);
});
if (this.remove(it.uid)) {
this.on("remove")(it);
}
else {
} else {
this._next();
}
@ -470,10 +295,9 @@ Playlist.prototype.jump = function(uid) {
}
if(it.temp) {
var pl = this;
this.remove(it.uid, function () {
pl.on("remove")(it);
});
if (this.remove(it.uid)) {
this.on("remove")(it);
}
}
return this.current;
@ -599,10 +423,12 @@ Playlist.prototype.clean = function (filter) {
if (count < matches.length) {
var uid = matches[count].uid;
count++;
if (self.remove(uid)) {
self.channel.sendAll("delete", {
uid: uid
});
self.remove(uid, deleteNext);
}
deleteNext();
} else {
// refresh meta only once, at the end
self.channel.broadcastPlaylistMeta();

View File

@ -8,7 +8,7 @@ var Logger = require("./logger");
var Channel = require("./channel");
var User = require("./user");
const VERSION = "2.4.2";
const VERSION = "2.4.3";
function getIP(req) {
var raw = req.connection.remoteAddress;
@ -79,6 +79,7 @@ var Server = {
db: null,
ips: {},
acp: null,
announcement: null,
httpaccess: null,
actionlog: null,
logHTTP: function (req, status) {

View File

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

View File

@ -0,0 +1,38 @@
var fs = require('fs');
var io = require('socket.io-client');
var socket = io.connect('http://localhost:1337');
socket.on('connect', function () {
socket.emit('login', { name: 'test', pw: 'test' });
socket.emit('joinChannel', { name: 'test' });
});
socket.on('queueFail', function (msg) {
console.log(msg);
});
/* Stress test adding a lot of videos in a very short timespan */
function testAddVideos() {
var pl = fs.readFileSync('largepl.json') + '';
pl = JSON.parse(pl);
var ids = [];
for (var i = 0; i < pl.length; i++) {
if (pl[i].type === 'yt')
ids.push(pl[i].id);
}
for (var i = 0; i < ids.length; i++) {
(function (i) {
setTimeout(function () {
console.log('queue', ids[i]);
socket.emit('queue', {
id: ids[i],
type: 'yt',
pos: 'end'
});
}, 1050 * i);
})(i);
}
}
testAddVideos();

View File

@ -764,9 +764,10 @@ Callbacks = {
},
queue: function(data) {
queueAction({
fn: function () {
PL_ACTION_QUEUE.queue(function (plq) {
var li = makeQueueEntry(data.item, true);
if (data.item.uid === PL_CURRENT)
li.addClass("queue_active");
li.hide();
var q = $("#queue");
li.attr("title", data.item.queueby
@ -774,33 +775,53 @@ Callbacks = {
: "Added by: Unknown");
if (data.after === "prepend") {
li.prependTo(q);
li.show("blind");
return true;
}
else if(data.after === "append") {
li.show("blind", function () {
plq.release();
});
} else if (data.after === "append") {
li.appendTo(q);
li.show("blind");
return true;
}
else {
li.show("blind", function () {
plq.release();
});
} else {
var liafter = playlistFind(data.after);
if (!liafter) {
return false;
plq.release();
return;
}
li.insertAfter(liafter);
li.show("blind");
return true;
}
li.show("blind", function () {
plq.release();
});
}
});
},
queueFail: function(data) {
if(!data) {
if (!data || data === true) {
data = "Queue failed. Check your link to make sure it is valid.";
}
var alerts = $(".qfalert");
for (var i = 0; i < alerts.length; i++) {
var al = $(alerts[i]);
var cl = al.clone();
cl.children().remove();
if (cl.text() === data) {
var tag = al.find(".label-important");
if (tag.length > 0) {
var count = parseInt(tag.text().match(/\d+/)[0]) + 1;
tag.text(tag.text().replace(/\d+/, ""+count));
} else {
$("<span/>")
.addClass("label label-important pull-right")
.text("+ 1 more")
.appendTo(al);
}
return;
}
}
makeAlert("Error", data, "alert-error")
.addClass("span12")
.addClass("span12 qfalert")
.insertBefore($("#extended_controls"));
},
@ -829,52 +850,40 @@ Callbacks = {
},
"delete": function(data) {
queueAction({
fn: function () {
PL_ACTION_QUEUE.queue(function (plq) {
PL_WAIT_SCROLL = true;
var li = $(".pluid-" + data.uid);
li.hide("blind", function() {
li.remove();
plq.release();
PL_WAIT_SCROLL = false;
});
return true;
}
});
},
moveVideo: function(data) {
if (data.moveby != CLIENT.name) {
queueAction({
fn: function () {
playlistMove(data.from, data.after);
return true;
}
PL_ACTION_QUEUE.queue(function (plq) {
playlistMove(data.from, data.after, function () {
plq.release();
});
});
}
},
setCurrent: function(uid) {
queueAction({
fn: function () {
PL_CURRENT = uid;
var qli = $("#queue li");
qli.removeClass("queue_active");
$("#queue li").removeClass("queue_active");
var li = $(".pluid-" + uid);
if(li.length == 0) {
return false;
}
if (li.length !== 0) {
li.addClass("queue_active");
var timer = setInterval(function () {
var tmr = setInterval(function () {
if (!PL_WAIT_SCROLL) {
scrollQueue();
clearInterval(timer);
clearInterval(tmr);
}
}, 100);
return true;
},
can_wait: true
});
}
},
changeMedia: function(data) {

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.
*/
var CL_VERSION = "2.0.0";
var CL_VERSION = "2.4.3";
var CLIENT = {
rank: -1,
@ -44,9 +44,6 @@ if($("#videowidth").length > 0) {
VWIDTH = $("#videowidth").css("width").replace("px", "");
VHEIGHT = ""+parseInt(parseInt(VWIDTH) * 9 / 16);
}
var PL_MOVING = false;
var PL_ADDING = false;
var PL_DELETING = false;
var REBUILDING = false;
var socket = {
emit: function() {

View File

@ -323,9 +323,6 @@ function queue(pos) {
return;
}
var links = $("#mediaurl").val().split(",");
if(pos == "next") {
links = links.reverse();
}
var parsed = [];
links.forEach(function(link) {
var data = parseMediaLink(link);

View File

@ -1191,30 +1191,59 @@ function addLibraryButtons(li, id, source) {
/* queue stuff */
var PL_QUEUED_ACTIONS = [];
var PL_ACTION_INTERVAL = false;
var AsyncQueue = function () {
this._q = [];
this._lock = false;
this._tm = 0;
};
function queueAction(data) {
PL_QUEUED_ACTIONS.push(data);
if(PL_ACTION_INTERVAL)
AsyncQueue.prototype.next = function () {
if (this._q.length > 0) {
if (!this.lock())
return;
PL_ACTION_INTERVAL = setInterval(function () {
var data = PL_QUEUED_ACTIONS.shift();
if(!("expire" in data))
data.expire = Date.now() + 5000;
if(!data.fn()) {
if(data.can_wait && Date.now() < data.expire)
PL_QUEUED_ACTIONS.push(data);
else if(Date.now() < data.expire)
PL_QUEUED_ACTIONS.unshift(data);
var item = this._q.shift();
var fn = item[0], tm = item[1];
this._tm = Date.now() + item[1];
fn(this);
}
if(PL_QUEUED_ACTIONS.length == 0) {
clearInterval(PL_ACTION_INTERVAL);
PL_ACTION_INTERVAL = false;
};
AsyncQueue.prototype.lock = function () {
if (this._lock) {
if (this._tm > 0 && Date.now() > this._tm) {
this._tm = 0;
return true;
}
}, 100);
return false;
}
this._lock = true;
return true;
};
AsyncQueue.prototype.release = function () {
var self = this;
if (!self._lock)
return false;
self._lock = false;
self.next();
return true;
};
AsyncQueue.prototype.queue = function (fn) {
var self = this;
self._q.push([fn, 20000]);
self.next();
};
AsyncQueue.prototype.reset = function () {
this._q = [];
this._lock = false;
};
var PL_ACTION_QUEUE = new AsyncQueue();
// Because jQuery UI does weird things
function playlistFind(uid) {
var children = document.getElementById("queue").children;
@ -1227,10 +1256,12 @@ function playlistFind(uid) {
return false;
}
function playlistMove(from, after) {
function playlistMove(from, after, cb) {
var lifrom = $(".pluid-" + from);
if(lifrom.length == 0)
return false;
if(lifrom.length == 0) {
cb(false);
return;
}
var q = $("#queue");
@ -1238,24 +1269,26 @@ function playlistMove(from, after) {
lifrom.hide("blind", function() {
lifrom.detach();
lifrom.prependTo(q);
lifrom.show("blind");
lifrom.show("blind", cb);
});
}
else if(after === "append") {
lifrom.hide("blind", function() {
lifrom.detach();
lifrom.appendTo(q);
lifrom.show("blind");
lifrom.show("blind", cb);
});
}
else {
var liafter = $(".pluid-" + after);
if(liafter.length == 0)
return false;
if(liafter.length == 0) {
cb(false);
return;
}
lifrom.hide("blind", function() {
lifrom.detach();
lifrom.insertAfter(liafter);
lifrom.show("blind");
lifrom.show("blind", cb);
});
}
}