diff --git a/channel.js b/channel.js index 2e19e294..4213e8eb 100644 --- a/channel.js +++ b/channel.js @@ -150,9 +150,7 @@ Channel.prototype.loadDump = function() { } this.queue.push(m); } - this.sendAll("playlist", { - pl: this.queue - }); + this.sendAll("playlist", this.queue); this.broadcastPlaylistMeta(); // Backwards compatibility if(data.currentPosition != undefined) { @@ -559,7 +557,7 @@ Channel.prototype.userJoin = function(user) { // Set the new guy up this.sendPlaylist(user); this.sendMediaUpdate(user); - user.socket.emit("queueLock", {locked: !this.openqueue}); + user.socket.emit("setPlaylistLocked", {locked: !this.openqueue}); this.sendUserlist(user); this.sendRecentChat(user); user.socket.emit("channelCSSJS", {css: this.css, js: this.js}); @@ -569,7 +567,7 @@ Channel.prototype.userJoin = function(user) { user.socket.emit("channelOpts", this.opts); user.socket.emit("setPermissions", this.permissions); user.socket.emit("updateMotd", this.motd); - user.socket.emit("drinkCount", {count: this.drinks}); + user.socket.emit("drinkCount", this.drinks); // Send things that require special permission this.sendRankStuff(user); @@ -714,13 +712,9 @@ Channel.prototype.sendACL = function(user) { } Channel.prototype.sendPlaylist = function(user) { - user.socket.emit("playlist", { - pl: this.queue - }); - user.socket.emit("updatePlaylistIdx", { - idx: this.position - }); - user.socket.emit("updatePlaylistMeta", this.plmeta); + user.socket.emit("playlist", this.queue); + user.socket.emit("setPosition", this.position); + user.socket.emit("setPlaylistMeta", this.plmeta); } Channel.prototype.sendMediaUpdate = function(user) { @@ -779,13 +773,11 @@ Channel.prototype.broadcastPlaylistMeta = function() { time: timestr }; this.plmeta = packet; - this.sendAll("updatePlaylistMeta", packet); + this.sendAll("setPlaylistMeta", packet); } Channel.prototype.broadcastUsercount = function() { - this.sendAll("usercount", { - count: this.users.length - }); + this.sendAll("usercount", this.users.length); } Channel.prototype.broadcastNewUser = function(user) { @@ -928,7 +920,7 @@ Channel.prototype.broadcastMotd = function() { } Channel.prototype.broadcastDrinks = function() { - this.sendAll("drinkCount", {count: this.drinks}); + this.sendAll("drinkCount", this.drinks); } /* REGION Playlist Stuff */ @@ -1134,7 +1126,7 @@ Channel.prototype.setTemp = function(idx, temp) { var med = this.queue[idx]; med.temp = temp; this.sendAll("setTemp", { - idx: idx, + position: idx, temp: temp }); @@ -1147,36 +1139,37 @@ Channel.prototype.trySetTemp = function(user, data) { if(!this.hasPermission(user, "settemp")) { return; } - if(typeof data.idx != "number" || typeof data.temp != "boolean") { + if(typeof data.position != "number" || typeof data.temp != "boolean") { return; } - if(data.idx < 0 || data.idx >= this.queue.length) { + if(data.position < 0 || data.position >= this.queue.length) { return; } - this.setTemp(data.idx, data.temp); + this.setTemp(data.position, data.temp); } -Channel.prototype.dequeue = function(data) { - if(data.pos < 0 || data.pos >= this.queue.length) { + +Channel.prototype.dequeue = function(position) { + if(position < 0 || position >= this.queue.length) { return; } - this.queue.splice(data.pos, 1); - this.sendAll("unqueue", { - pos: data.pos + this.queue.splice(position, 1); + this.sendAll("delete", { + position: position }); this.broadcastPlaylistMeta(); // If you remove the currently playing video, play the next one - if(data.pos == this.position && !data.removeonly) { + if(position == this.position) { this.position--; this.playNext(); return; } // If you remove a video whose position is before the one currently // playing, you have to reduce the position of the one playing - if(data.pos < this.position) { + if(position < this.position) { this.position--; } } @@ -1186,9 +1179,8 @@ Channel.prototype.tryDequeue = function(user, data) { return; } - if(data.pos === undefined) { + if(typeof data !== "number") return; - } this.dequeue(data); } @@ -1250,10 +1242,7 @@ Channel.prototype.jumpTo = function(pos) { this.media.paused = false; this.sendAll("changeMedia", this.media.fullupdate()); - this.sendAll("updatePlaylistIdx", { - old: old, - idx: this.position - }); + this.sendAll("setPosition", this.position); // If it's not a livestream, enable autolead if(this.leader == null && !isLive(this.media.type)) { @@ -1269,11 +1258,11 @@ Channel.prototype.tryJumpTo = function(user, data) { return; } - if(data.pos === undefined) { + if(typeof data !== "number") { return; } - this.jumpTo(data.pos); + this.jumpTo(data); } Channel.prototype.clearqueue = function() { @@ -1343,34 +1332,35 @@ Channel.prototype.tryUpdate = function(user, data) { this.sendAll("mediaUpdate", this.media.timeupdate()); } -Channel.prototype.move = function(data) { - if(data.src < 0 || data.src >= this.queue.length) { +Channel.prototype.move = function(data, user) { + if(data.from < 0 || data.from >= this.queue.length) { return; } - if(data.dest < 0 || data.dest > this.queue.length) { + if(data.to < 0 || data.to > this.queue.length) { return; } - var media = this.queue[data.src]; - var dest = data.dest > data.src ? data.dest + 1 : data.dest; - var src = data.dest > data.src ? data.src : data.src + 1; + var media = this.queue[data.from]; + var to = data.to > data.from ? data.to + 1 : data.to; + var from = data.to > data.from ? data.from : data.from + 1; - this.queue.splice(dest, 0, media); - this.queue.splice(src, 1); + this.queue.splice(to, 0, media); + this.queue.splice(from, 1); this.sendAll("moveVideo", { - src: data.src, - dest: data.dest + from: data.from, + to: data.to, + moveby: user ? user.name : "" }); // Account for moving things around the active video - if(data.src < this.position && data.dest >= this.position) { + if(data.from < this.position && data.to >= this.position) { this.position--; } - else if(data.src > this.position && data.dest < this.position) { + else if(data.from > this.position && data.to < this.position) { this.position++ } - else if(data.src == this.position) { - this.position = data.dest; + else if(data.from == this.position) { + this.position = data.to; } } @@ -1448,7 +1438,7 @@ Channel.prototype.tryVoteskip = function(user) { Channel.prototype.setLock = function(locked) { this.openqueue = !locked; - this.sendAll("queueLock", {locked: locked}); + this.sendAll("setPlaylistLocked", {locked: locked}); } Channel.prototype.trySetLock = function(user, data) { @@ -1463,6 +1453,14 @@ Channel.prototype.trySetLock = function(user, data) { this.setLock(data.locked); } +Channel.prototype.tryToggleLock = function(user) { + if(!Rank.hasPermission(user, "qlock")) { + return; + } + + this.setLock(this.openqueue); +} + Channel.prototype.updateFilter = function(filter) { var found = false; for(var i = 0; i < this.filters.length; i++) { diff --git a/user.js b/user.js index 549ac99e..f333f50b 100644 --- a/user.js +++ b/user.js @@ -206,7 +206,7 @@ User.prototype.initCallbacks = function() { } }.bind(this)); - this.socket.on("unqueue", function(data) { + this.socket.on("delete", function(data) { if(this.channel != null) { this.channel.tryDequeue(this, data); } @@ -248,9 +248,9 @@ User.prototype.initCallbacks = function() { } }.bind(this)); - this.socket.on("queueLock", function(data) { + this.socket.on("togglePlaylistLock", function() { if(this.channel != null) { - this.channel.trySetLock(this, data); + this.channel.tryToggleLock(this); } }.bind(this)); @@ -260,18 +260,18 @@ User.prototype.initCallbacks = function() { } }.bind(this)); - this.socket.on("searchLibrary", function(data) { + this.socket.on("searchMedia", function(data) { if(this.channel != null) { if(data.yt) { var callback = function(vids) { - this.socket.emit("librarySearchResults", { + this.socket.emit("searchResults", { results: vids }); }.bind(this); this.channel.search(data.query, callback); } else { - this.socket.emit("librarySearchResults", { + this.socket.emit("searchResults", { results: this.channel.search(data.query) }); } @@ -331,12 +331,6 @@ User.prototype.initCallbacks = function() { } }.bind(this)); - this.socket.on("adm", function(data) { - if(Rank.hasPermission(this, "acp")) { - this.handleAdm(data); - } - }.bind(this)); - this.socket.on("announce", function(data) { if(Rank.hasPermission(this, "announce")) { if(data.clear) { @@ -500,27 +494,6 @@ User.prototype.initCallbacks = function() { }.bind(this)); } -// Handle administration -User.prototype.handleAdm = function(data) { - if(data.cmd == "listchannels") { - var chans = []; - for(var chan in Server.channels) { - var nowplaying = "-"; - if(Server.channels[chan].media != null) - nowplaying = Server.channels[chan].media.title; - chans.push({ - name: chan, - usercount: Server.channels[chan].users.length, - nowplaying: nowplaying - }); - } - this.socket.emit("adm", { - cmd: "listchannels", - chans: chans - }); - } -}; - var lastguestlogin = {}; // Attempt to login User.prototype.login = function(name, pw, session) { @@ -568,11 +541,10 @@ User.prototype.login = function(name, pw, session) { this.name = name; this.loggedIn = false; this.socket.emit("login", { - success: true - }); - this.socket.emit("rank", { - rank: this.rank + success: true, + name: name }); + this.socket.emit("rank", this.rank); if(this.channel != null) { this.channel.logger.log(this.ip + " signed in as " + name); this.channel.broadcastNewUser(this); @@ -585,7 +557,8 @@ User.prototype.login = function(name, pw, session) { this.loggedIn = true; this.socket.emit("login", { success: true, - session: row.session_hash + session: row.session_hash, + name: name }); Logger.syslog.log(this.ip + " logged in as " + name); this.profile = { @@ -597,9 +570,7 @@ User.prototype.login = function(name, pw, session) { var rank = (chanrank > row.global_rank) ? chanrank : row.global_rank; this.rank = (this.rank > rank) ? this.rank : rank; - this.socket.emit("rank", { - rank: this.rank - }); + this.socket.emit("rank", this.rank); this.name = name; if(this.channel != null) { this.channel.logger.log(this.ip + " logged in as " + name); diff --git a/www/assets/css/ytsync.css b/www/assets/css/ytsync.css index c2cc3159..0026fc93 100644 --- a/www/assets/css/ytsync.css +++ b/www/assets/css/ytsync.css @@ -116,6 +116,7 @@ html, body { #plmeta { border: 1px solid #aaaaaa; + border-top: 0; background-color: #ffffff; padding: 3px; margin: 0; diff --git a/www/assets/js/callbacks.js b/www/assets/js/callbacks.js index ef8702d2..d2faf96e 100644 --- a/www/assets/js/callbacks.js +++ b/www/assets/js/callbacks.js @@ -16,7 +16,7 @@ Callbacks = { socket.emit("joinChannel", { name: CHANNEL.name }); - if(uname && session) { + if(NAME && SESSION) { socket.emit("login", { name: NAME, session: SESSION @@ -231,7 +231,8 @@ Callbacks = { setPermissions: function(perms) { CHANNEL.perms = perms; if(CLIENT.rank >= Rank.Admin) - genPermissionsEditor(); + 1; + //genPermissionsEditor(); handlePermissionChange(); }, @@ -464,9 +465,9 @@ Callbacks = { } }, - drinkCount: function(data) { - if(data.count != 0) { - var text = data.count + " drink"; + drinkCount: function(count) { + if(count != 0) { + var text = count + " drink"; if(data.count != 1) { text += "s"; } @@ -484,7 +485,6 @@ Callbacks = { var q = $("#queue"); q.html(""); - for(var i = 0; i < data.length; i++) { Callbacks.queue({ media: data[i], @@ -550,7 +550,8 @@ Callbacks = { }, moveVideo: function(data) { - playlistMove(data.src, data.dest); + if(data.moveby != CLIENT.name) + playlistMove(data.src, data.dest); }, setPosition: function(data) { @@ -598,22 +599,7 @@ Callbacks = { setPlaylistLocked: function(data) { CHANNEL.openqueue = !data.locked; - // TODO handlePermissionsChange? - if(CHANNEL.openqueue) { - $("#playlist_controls").css("display", ""); - if(RANK < Rank.Moderator) { - $("#qlockbtn").css("display", "none"); - rebuildPlaylist(); - if(!CHANNELOPTS.qopen_allow_qnext) - $("#queue_next").attr("disabled", true); - if(!CHANNELOPTS.qopen_allow_playnext) - $("#play_next").attr("disabled", true); - } - } - else if(RANK < Rank.Moderator && !LEADER) { - $("#playlist_controls").css("display", "none"); - rebuildPlaylist(); - } + handlePermissionChange(); if(CHANNEL.openqueue) { $("#qlockbtn").removeClass("btn-danger") .addClass("btn-success") @@ -802,25 +788,39 @@ Callbacks = { } /* +pl = []; +for(var i = 0; i < 10; i++) { + var m = { + title: "Test " + i, + type: "yt", + id: "test" + i, + seconds: 0, + duration: "00:00" + }; + pl.push(m); +} +setTimeout(function() { + Callbacks.playlist(pl); +}, 1000); +*/ + $.getScript(IO_URL+"/socket.io/socket.io.js", function() { try { socket = io.connect(IO_URL); - for(var key in Callbacks) { - socket.on(key, Callbacks[key]); - } + setupCallbacks(); } catch(e) { Callbacks.disconnect(); } }); -*/ setupCallbacks = function() { for(var key in Callbacks) { (function(key) { - socket.on(key, function() { - Callbacks[key](); + socket.on(key, function(data) { + Callbacks[key](data); }); })(key); } } + diff --git a/www/assets/js/data.js b/www/assets/js/data.js index 6cd8402a..042863fb 100644 --- a/www/assets/js/data.js +++ b/www/assets/js/data.js @@ -17,6 +17,7 @@ var CHANNEL = { }; var PLAYER = false; +var FLUIDLAYOUT = false; var VWIDTH = $("#ytapiplayer").parent().css("width").replace("px", ""); var VHEIGHT = ""+parseInt(parseInt(VWIDTH) * 9 / 16); var POSITION = -1; @@ -39,6 +40,8 @@ var KICKED = false; var NAME = readCookie("cytube_uname"); var SESSION = readCookie("cytube_session"); var LEADTMR = false; +var PL_FROM = 0; +var PL_TO = 0; function getOrDefault(k, def) { var v = localStorage.getItem(k); diff --git a/www/assets/js/player.js b/www/assets/js/player.js new file mode 100644 index 00000000..1b83b179 --- /dev/null +++ b/www/assets/js/player.js @@ -0,0 +1,556 @@ +/* +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 Player = function(data) { + if(!data) { + data = { + id: "", + type: "null" + }; + } + this.id = data.id; + this.type = data.type; + this.diff = 0; + + switch(this.type) { + case "yt": + this.initYouTube(); + break; + case "vi": + this.initVimeo(); + break; + case "dm": + this.initDailymotion(); + break; + case "sc": + this.initSoundcloud(); + break; + case "li": + this.initLivestream(); + break; + case "tw": + this.initTwitch(); + break; + case "jt": + this.initJustinTV(); + break; + case "rt": + this.initRTMP(); + break; + case "jw": + this.initJWPlayer(); + break; + case "us": + this.initUstream(); + break; + case "im": + this.initImgur(); + break; + default: + this.nullPlayer(); + break; + } +} + +Player.prototype.nullPlayer = function() { + this.player = null; + this.load = function(data) { } + this.play = function() { } + this.pause = function() { } + this.getTime = function(callback) { } + this.seek = function(time) { } +} + +Player.prototype.initYouTube = function() { + this.removeOld(); + this.player = new YT.Player("ytapiplayer", { + height: VHEIGHT, + width: VWIDTH, + videoId: this.id, + playerVars: { + "autoplay": 1, + "controls": 1, + }, + events: { + onReady: function() { + socket.emit("playerReady"); + }, + onStateChange: function(ev) { + if(PLAYER.paused && ev.data != YT.PlayerState.PAUSED + || !PLAYER.paused && ev.data == YT.PlayerState.PAUSED) { + PLAYER.paused = (ev.data == YT.PlayerState.PAUSED); + sendVideoUpdate(); + } + else { + PLAYER.paused = (ev.data == YT.PlayerState.PAUSED); + } + if(CLIENT.leader && ev.data == YT.PlayerState.ENDED) { + socket.emit("playNext"); + } + } + } + }); + $("#ytapiplayer").css("border", "none"); + + this.load = function(data) { + if(this.player.loadVideoById) { + this.player.loadVideoById(data.id, data.currentTime); + this.id = data.id; + } + } + + this.pause = function() { + this.player.pauseVideo(); + } + + this.play = function() { + this.player.playVideo(); + } + + this.getTime = function(callback) { + callback(this.player.getCurrentTime()); + } + + this.seek = function(time) { + this.player.seekTo(time, true); + } +} + +Player.prototype.initVimeo = function() { + var iframe = $("