diff --git a/channel.js b/channel.js index 1bdc0100..dd85f49e 100644 --- a/channel.js +++ b/channel.js @@ -94,6 +94,9 @@ Channel.prototype.loadDump = function() { this.position = -1; if(this.queue.length > 0) this.playNext(); + if(this.media && data.currentTime) { + this.media.currentTime = data.currentTime; + } this.opts = data.opts; if(data.filters) { this.filters = new Array(data.filters.length); @@ -123,6 +126,7 @@ Channel.prototype.saveDump = function() { } var dump = { position: this.position, + currentTime: this.media ? this.media.currentTime : 0, queue: this.queue, opts: this.opts, filters: filts, diff --git a/www/assets/css/ytsync.css b/www/assets/css/ytsync.css index 5ca9f3da..28228480 100644 --- a/www/assets/css/ytsync.css +++ b/www/assets/css/ytsync.css @@ -111,6 +111,20 @@ font-family: Monospace; } +.server-msg-disconnect { + border: 1px solid #ff0000; + margin: 5px; + padding: 5px; + color: #ff0000; +} + +.server-msg-reconnect { + border: 1px solid #009900; + margin: 5px; + padding: 5px; + color: #009900; +} + .poll-notify { color: #0000aa; font-weight: bold; diff --git a/www/assets/js/callbacks.js b/www/assets/js/callbacks.js index 72546a25..53a94c05 100644 --- a/www/assets/js/callbacks.js +++ b/www/assets/js/callbacks.js @@ -15,9 +15,7 @@ function initCallbacks() { /* REGION Globals */ socket.on("disconnect", function() { - $("
").addClass("alert").addClass("alert-error") - .insertAfter($(".row")[0])[0] - .innerHTML = "

Disconnected from server

"; + handleDisconnect(); }); socket.on("announcement", function(data) { @@ -130,13 +128,14 @@ function initCallbacks() { div.appendTo($("#messagebuffer")); // Cap chatbox at most recent 100 messages if($("#messagebuffer").children().length > 100) { - $($("#messagebufer").children()[0]).remove(); + $($("#messagebuffer").children()[0]).remove(); } if(SCROLLCHAT) $("#messagebuffer").scrollTop($("#messagebuffer").prop("scrollHeight")); }); socket.on("userlist", function(data) { + $(".userlist_item").each(function() { this.remove(); }); for(var i = 0; i < data.length; i++) { addUser(data[i].name, data[i].rank, data[i].leader); } diff --git a/www/assets/js/client.js b/www/assets/js/client.js index d42a5d07..15b712f7 100644 --- a/www/assets/js/client.js +++ b/www/assets/js/client.js @@ -38,15 +38,20 @@ var Rank = { Siteadmin: 255 }; -var socket = io.connect(IO_URL); -initCallbacks(); +try { + var socket = io.connect(IO_URL); + initCallbacks(); +} +catch(e) { + handleDisconnect(); +} $(window).focus(function() { FOCUSED = true; onWindowFocus(); }) .blur(function() { - FOCUSED = false + FOCUSED = false; }); var params = {}; @@ -89,11 +94,22 @@ else if(!params["channel"].match(/^[a-zA-Z0-9]+$/)) { .innerHTML = "

Invalid Channel Name

Channel names must conain only numbers and letters

"; } -else { + +socket.on("connect", function() { socket.emit("joinChannel", { name: params["channel"] }); -} + if(uname != null && pw != null && pw != "false") { + socket.emit("login", { + name: uname, + pw: pw + }); + } + $("
").addClass("server-msg-reconnect") + .text("Connected") + .appendTo($("#messagebuffer")); + setTimeout(function() { $("#reconnect_box").remove(); }, 3000); +}); // Load the youtube iframe API @@ -102,13 +118,6 @@ tag.src = "http://www.youtube.com/iframe_api"; var firstScriptTag = document.getElementsByTagName("script")[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); -if(uname != null && pw != null && pw != "false") { - socket.emit("login", { - name: uname, - pw: pw - }); -} - var sendVideoUpdate = function() { } setInterval(function() { sendVideoUpdate(); diff --git a/www/assets/js/functions.js b/www/assets/js/functions.js index aa089c24..9fe9f9e2 100644 --- a/www/assets/js/functions.js +++ b/www/assets/js/functions.js @@ -9,6 +9,13 @@ 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. */ +function handleDisconnect() { + $("
") + .addClass("server-msg-disconnect") + .text("Disconnected from server. Attempting reconnection...") + .appendTo($("#messagebuffer")); +} + // Adds a user to the chatbox userlist function addUser(name, rank, leader) { var div = $("
").attr("class", "userlist_item");