From 0f9bfe1429cac858717514105385434fb69a252d Mon Sep 17 00:00:00 2001 From: calzoneman Date: Sun, 9 Feb 2014 20:10:11 -0600 Subject: [PATCH] JWPlayer serverside synchronization --- lib/channel.js | 13 +++++++++++++ lib/playlist.js | 8 +++++--- www/assets/js/ui.js | 27 ++++++++++++++++++++++++++- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/lib/channel.js b/lib/channel.js index 020b60b9..21b65756 100644 --- a/lib/channel.js +++ b/lib/channel.js @@ -1514,6 +1514,12 @@ Channel.prototype.handleQueue = function (user, data) { var queueby = user != null ? user.name : ""; var temp = data.temp || !this.hasPermission(user, "addnontemp"); + // Allow override of duration for live content + var duration = undefined; + if (util.isLive(data.type) && typeof data.duration === "number") { + duration = !isNaN(data.duration) ? data.duration : undefined; + } + // Throttle video adds var limit = { burst: 3, @@ -1543,6 +1549,7 @@ Channel.prototype.handleQueue = function (user, data) { queueby: queueby, temp: temp, type: type, + duration: duration, maxlength: this.hasPermission(user, "exceedmaxlength") ? 0 : this.opts.maxlength }, function (err, media) { if (err) { @@ -1681,6 +1688,12 @@ Channel.prototype.addMedia = function (data, callback) { return; } + if (data.duration) { + media.seconds = data.duration; + media.live = false; + } else { + media.live = true; + } afterLookup(lock, false, media); }); }); diff --git a/lib/playlist.js b/lib/playlist.js index 061f0ec0..41f4e8db 100644 --- a/lib/playlist.js +++ b/lib/playlist.js @@ -181,7 +181,8 @@ Playlist.prototype.add = function(item, pos) { self.channel.sendAll("delete", { uid: it.uid }); - self.channel.broadcastPlaylistMeta(); + self.channel.updatePlaylistMeta(); + self.channel.sendPlaylistMeta(self.channel.users); } if(pos == "append") { @@ -387,7 +388,7 @@ Playlist.prototype.startPlayback = function (time) { self._leadInterval = false; } self.on("changeMedia")(self.current.media); - if(!util.isLive(self.current.media.type)) { + if(!self.current.media.live) { self._lastUpdate = Date.now(); self._leadInterval = setInterval(function() { self._leadLoop(); @@ -453,7 +454,8 @@ Playlist.prototype.clean = function (filter) { deleteNext(); } else { // refresh meta only once, at the end - self.channel.broadcastPlaylistMeta(); + self.channel.updatePlaylistMeta(); + self.channel.sendPlaylistMeta(self.channel.users); } }; // start initial callback diff --git a/www/assets/js/ui.js b/www/assets/js/ui.js index c71b9974..e3dec75f 100644 --- a/www/assets/js/ui.js +++ b/www/assets/js/ui.js @@ -329,16 +329,26 @@ function queue(pos, src) { } else { var link = $("#mediaurl").val(); var data = parseMediaLink(link); + var duration = undefined; + if (link.indexOf("jw:") === 0) { + duration = parseInt($("#addfromurl-duration-val").val()); + if (duration <= 0 || isNaN(duration)) { + duration = undefined; + } + } + if (data.id == null || data.type == null) { makeAlert("Error", "Failed to parse link. Please check that it is correct", "alert-danger") .insertAfter($("#addfromurl")); } else { $("#mediaurl").val(""); + $("#addfromurl-duration").remove(); socket.emit("queue", { id: data.id, type: data.type, pos: pos, + duration: duration, temp: $(".add-temp").prop("checked") }); } @@ -350,9 +360,24 @@ $("#queue_end").click(queue.bind(this, "end", "url")); $("#ce_queue_next").click(queue.bind(this, "next", "customembed")); $("#ce_queue_end").click(queue.bind(this, "end", "customembed")); -$("#mediaurl").keydown(function(ev) { +$("#mediaurl").keyup(function(ev) { if (ev.keyCode === 13) { queue("end", "url"); + } else if ($("#mediaurl").val().indexOf("jw:") === 0) { + var duration = $("#addfromurl-duration"); + if (duration.length === 0) { + duration = $("
") + .attr("id", "addfromurl-duration") + .appendTo($("#addfromurl")); + $("").text("JWPlayer Duration (seconds) (optional)") + .appendTo(duration); + $("").addClass("form-control") + .attr("type", "text") + .attr("id", "addfromurl-duration-val") + .appendTo($("#addfromurl-duration")); + } + } else { + $("#addfromurl-duration").remove(); } });