mirror of https://github.com/calzoneman/sync.git
commit
4ef059ddaa
113
channel.js
113
channel.js
|
@ -19,6 +19,7 @@ var Logger = require("./logger.js");
|
|||
var InfoGetter = require("./get-info.js");
|
||||
var Server = require("./server.js");
|
||||
var io = Server.io;
|
||||
var NWS = require("./notwebsocket");
|
||||
var Rank = require("./rank.js");
|
||||
var Auth = require("./auth.js");
|
||||
var ChatCommand = require("./chatcommand.js");
|
||||
|
@ -54,7 +55,7 @@ var Channel = function(name) {
|
|||
playlistdelete: 2,
|
||||
playlistjump: 1.5,
|
||||
playlistaddlist: 1.5,
|
||||
playlistadd: 1.5,
|
||||
playlistaddlive: 1.5,
|
||||
addnontemp: 2,
|
||||
settemp: 2,
|
||||
playlistgeturl: 1.5,
|
||||
|
@ -75,7 +76,8 @@ var Channel = function(name) {
|
|||
customcss: "",
|
||||
customjs: "",
|
||||
chat_antiflood: false,
|
||||
show_public: false
|
||||
show_public: false,
|
||||
enable_link_regex: true
|
||||
};
|
||||
this.filters = [
|
||||
new Filter("monospace", "`([^`]+)`", "g", "<code>$1</code>"),
|
||||
|
@ -197,7 +199,9 @@ Channel.prototype.loadDump = function() {
|
|||
}
|
||||
data.logins = data.logins || {};
|
||||
for(var ip in data.logins) {
|
||||
this.logins[ip] = data.logins[ip];
|
||||
for(var i = 0; i < data.logins.length; i++) {
|
||||
this.logins[ip].push(data.logins[ip][i]);
|
||||
}
|
||||
}
|
||||
this.setLock(!(data.openqueue || false));
|
||||
this.chatbuffer = data.chatbuffer || [];
|
||||
|
@ -536,12 +540,7 @@ Channel.prototype.userJoin = function(user) {
|
|||
if(user.name != "") {
|
||||
for(var i = 0; i < this.users.length; i++) {
|
||||
if(this.users[i].name.toLowerCase() == user.name.toLowerCase()) {
|
||||
user.name = "";
|
||||
user.loggedIn = false;
|
||||
user.socket.emit("login", {
|
||||
success: false,
|
||||
error: "The username " + user.name + " is already in use on this channel"
|
||||
});
|
||||
this.kick(this.users[i], "Duplicate login");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -650,13 +649,12 @@ Channel.prototype.sendRankStuff = function(user) {
|
|||
var ents = [];
|
||||
for(var ip in this.ipbans) {
|
||||
if(this.ipbans[ip] != null) {
|
||||
var name;
|
||||
var name = [];
|
||||
if(ip in this.logins) {
|
||||
name = this.logins[ip].join(", ");
|
||||
}
|
||||
else {
|
||||
name = this.ipbans[ip][0];
|
||||
name = this.logins[ip];
|
||||
}
|
||||
name.push(this.ipbans[ip][0]);
|
||||
name = name.join(", ");
|
||||
var id = this.hideIP(ip);
|
||||
var disp = ip;
|
||||
if(user.rank < Rank.Siteadmin) {
|
||||
|
@ -760,6 +758,15 @@ Channel.prototype.sendRecentChat = function(user) {
|
|||
|
||||
Channel.prototype.sendAll = function(message, data) {
|
||||
io.sockets.in(this.name).emit(message, data);
|
||||
NWS.inRoom(this.name).emit(message, data);
|
||||
}
|
||||
|
||||
Channel.prototype.sendAllWithPermission = function(perm, msg, data) {
|
||||
for(var i = 0; i < this.users.length; i++) {
|
||||
if(Rank.hasPermission(this.users[i], perm)) {
|
||||
this.users[i].socket.emit(msg, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Channel.prototype.broadcastPlaylistMeta = function() {
|
||||
|
@ -954,12 +961,13 @@ function mediaUpdate(chan, id) {
|
|||
}
|
||||
|
||||
function isLive(type) {
|
||||
return type == "li"
|
||||
|| type == "tw"
|
||||
|| type == "jt"
|
||||
|| type == "rt"
|
||||
|| type == "jw"
|
||||
|| type == "us";
|
||||
return type == "li" // Livestream.com
|
||||
|| type == "tw" // Twitch.tv
|
||||
|| type == "jt" // Justin.tv
|
||||
|| type == "rt" // RTMP
|
||||
|| type == "jw" // JWPlayer
|
||||
|| type == "us" // Ustream.tv
|
||||
|| type == "im";// Imgur album
|
||||
}
|
||||
|
||||
Channel.prototype.queueAdd = function(media, idx) {
|
||||
|
@ -986,6 +994,11 @@ Channel.prototype.autoTemp = function(media, user) {
|
|||
Channel.prototype.enqueue = function(data, user) {
|
||||
var idx = data.pos == "next" ? this.position + 1 : this.queue.length;
|
||||
|
||||
if(isLive(data.type) && !this.hasPermission(user, "playlistaddlive")) {
|
||||
user.socket.emit("queueFail", "You don't have permission to queue livestreams");
|
||||
return;
|
||||
}
|
||||
|
||||
// Prefer cache over looking up new data
|
||||
if(data.id in this.library) {
|
||||
var media = this.library[data.id].dup();
|
||||
|
@ -1052,6 +1065,12 @@ Channel.prototype.enqueue = function(data, user) {
|
|||
this.autoTemp(media, user);
|
||||
this.queueAdd(media, idx);
|
||||
break;
|
||||
case "im":
|
||||
var media = new Media(data.id, "Imgur Album", "--:--", "im");
|
||||
media.queueby = user ? user.name : "";
|
||||
this.autoTemp(media, user);
|
||||
this.queueAdd(media, idx);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -1448,8 +1467,12 @@ Channel.prototype.trySetLock = function(user, data) {
|
|||
Channel.prototype.updateFilter = function(filter) {
|
||||
var found = false;
|
||||
for(var i = 0; i < this.filters.length; i++) {
|
||||
if(this.filters[i].name == filter.name
|
||||
&& this.filters[i].source == filter.source) {
|
||||
if(this.filters[i].name == "" && filter.name == ""
|
||||
&& this.filters[i].source == filter.source) {
|
||||
found = true;
|
||||
this.filters[i] = filter;
|
||||
}
|
||||
else if(filter.name != "" && this.filters[i].name == filter.name) {
|
||||
found = true;
|
||||
this.filters[i] = filter;
|
||||
}
|
||||
|
@ -1624,7 +1647,7 @@ Channel.prototype.filterMessage = function(msg) {
|
|||
var subs = msg.split(link);
|
||||
// Apply other filters
|
||||
for(var j = 0; j < subs.length; j++) {
|
||||
if(subs[j].match(link)) {
|
||||
if(this.opts.enable_link_regex && subs[j].match(link)) {
|
||||
subs[j] = subs[j].replace(link, "<a href=\"$1\" target=\"_blank\">$1</a>");
|
||||
continue;
|
||||
}
|
||||
|
@ -1661,6 +1684,46 @@ Channel.prototype.sendMessage = function(username, msg, msgclass, data) {
|
|||
|
||||
/* REGION Rank stuff */
|
||||
|
||||
Channel.prototype.trySetRank = function(user, data) {
|
||||
if(!Rank.hasPermission(user, "promote"))
|
||||
return;
|
||||
|
||||
if(typeof data.user !== "string" || typeof data.rank !== "number")
|
||||
return;
|
||||
|
||||
if(data.rank >= user.rank)
|
||||
return;
|
||||
|
||||
if(data.rank < 1)
|
||||
return;
|
||||
|
||||
var receiver;
|
||||
for(var i = 0; i < this.users.length; i++) {
|
||||
if(this.users[i].name == data.user) {
|
||||
receiver = this.users[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(receiver) {
|
||||
if(receiver.rank >= user.rank)
|
||||
return;
|
||||
receiver.rank = data.rank;
|
||||
if(receiver.loggedIn) {
|
||||
this.saveRank(receiver);
|
||||
}
|
||||
this.broadcastUserUpdate(receiver);
|
||||
}
|
||||
else {
|
||||
var rrank = this.getRank(data.user);
|
||||
if(rrank >= user.rank)
|
||||
return;
|
||||
Database.setChannelRank(this.name, data.user, data.rank);
|
||||
}
|
||||
|
||||
this.sendAllWithPermission("acl", "setChannelRank", data);
|
||||
}
|
||||
|
||||
Channel.prototype.tryPromoteUser = function(actor, data) {
|
||||
if(!Rank.hasPermission(actor, "promote")) {
|
||||
return;
|
||||
|
@ -1695,7 +1758,7 @@ Channel.prototype.tryPromoteUser = function(actor, data) {
|
|||
Database.setChannelRank(this.name, data.name, rank);
|
||||
}
|
||||
this.logger.log("*** " + actor.name + " promoted " + data.name + " from " + (rank - 1) + " to " + rank);
|
||||
this.broadcastRankTable();
|
||||
//this.broadcastRankTable();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1732,7 +1795,7 @@ Channel.prototype.tryDemoteUser = function(actor, data) {
|
|||
Database.setChannelRank(this.name, data.name, rank);
|
||||
}
|
||||
this.logger.log("*** " + actor.name + " demoted " + data.name + " from " + (rank + 1) + " to " + rank);
|
||||
this.broadcastRankTable();
|
||||
//this.broadcastRankTable();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ function handle(chan, user, msg, data) {
|
|||
handleBan(chan, user, msg.substring(5).split(" "));
|
||||
}
|
||||
else if(msg.indexOf("/ipban ") == 0) {
|
||||
handleIPBan(chan, user, msg.substring(5).split(" "));
|
||||
handleIPBan(chan, user, msg.substring(7).split(" "));
|
||||
}
|
||||
else if(msg.indexOf("/unban ") == 0) {
|
||||
handleUnban(chan, user, msg.substring(7).split(" "));
|
||||
|
@ -86,12 +86,11 @@ function handleIPBan(chan, user, args) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
if(kickee && kickee.rank < user.rank) {
|
||||
chan.logger.log("*** " + user.name + " banned " + args[0]);
|
||||
args[0] = "";
|
||||
var reason = args.join(" ");
|
||||
chan.kick(kickee, "(banned) " + reason);
|
||||
chan.banIP(user, kickee);
|
||||
if(kickee) {
|
||||
chan.tryIPBan(user, {
|
||||
id: chan.hideIP(kickee.ip),
|
||||
name: kickee.name
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
11
database.js
11
database.js
|
@ -1,3 +1,14 @@
|
|||
/*
|
||||
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 mysql = require("mysql-libmysqlclient");
|
||||
var Logger = require("./logger");
|
||||
var Media = require("./media").Media;
|
||||
|
|
11
filter.js
11
filter.js
|
@ -1,3 +1,14 @@
|
|||
/*
|
||||
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 Filter = function(name, regex, flags, replace) {
|
||||
this.name = name;
|
||||
this.source = regex;
|
||||
|
|
|
@ -0,0 +1,194 @@
|
|||
/*
|
||||
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 Logger = require("./logger");
|
||||
|
||||
const chars = "abcdefghijklmnopqsrtuvwxyz" +
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
|
||||
"0123456789";
|
||||
|
||||
var NotWebsocket = function() {
|
||||
this.hash = "";
|
||||
for(var i = 0; i < 30; i++) {
|
||||
this.hash += chars[parseInt(Math.random() * (chars.length - 1))];
|
||||
}
|
||||
|
||||
this.pktqueue = [];
|
||||
this.handlers = {};
|
||||
this.room = "";
|
||||
this.lastpoll = Date.now();
|
||||
this.noflood = {};
|
||||
}
|
||||
|
||||
NotWebsocket.prototype.checkFlood = function(id, rate) {
|
||||
if(id in this.noflood) {
|
||||
this.noflood[id].push(Date.now());
|
||||
}
|
||||
else {
|
||||
this.noflood[id] = [Date.now()];
|
||||
}
|
||||
if(this.noflood[id].length > 10) {
|
||||
this.noflood[id].shift();
|
||||
var hz = 10000 / (this.noflood[id][9] - this.noflood[id][0]);
|
||||
if(hz > rate) {
|
||||
throw "Rate is too high: " + id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NotWebsocket.prototype.emit = function(msg, data) {
|
||||
var pkt = [msg, data];
|
||||
this.pktqueue.push(pkt);
|
||||
}
|
||||
|
||||
NotWebsocket.prototype.poll = function() {
|
||||
this.checkFlood("poll", 100);
|
||||
this.lastpoll = Date.now();
|
||||
var q = [];
|
||||
for(var i = 0; i < this.pktqueue.length; i++) {
|
||||
q.push(this.pktqueue[i]);
|
||||
}
|
||||
this.pktqueue.length = 0;
|
||||
return q;
|
||||
}
|
||||
|
||||
NotWebsocket.prototype.on = function(msg, callback) {
|
||||
if(!(msg in this.handlers))
|
||||
this.handlers[msg] = [];
|
||||
this.handlers[msg].push(callback);
|
||||
}
|
||||
|
||||
NotWebsocket.prototype.recv = function(urlstr) {
|
||||
this.checkFlood("recv", 100);
|
||||
var msg, data;
|
||||
try {
|
||||
var js = JSON.parse(urlstr);
|
||||
msg = js[0];
|
||||
data = js[1];
|
||||
}
|
||||
catch(e) {
|
||||
Logger.errlog.log("Failed to parse NWS string");
|
||||
Logger.errlog.log(urlstr);
|
||||
}
|
||||
if(!msg)
|
||||
return;
|
||||
if(!(msg in this.handlers))
|
||||
return;
|
||||
for(var i = 0; i < this.handlers[msg].length; i++) {
|
||||
this.handlers[msg][i](data);
|
||||
}
|
||||
}
|
||||
|
||||
NotWebsocket.prototype.join = function(rm) {
|
||||
if(!(rm in rooms)) {
|
||||
rooms[rm] = [];
|
||||
}
|
||||
|
||||
rooms[rm].push(this);
|
||||
}
|
||||
|
||||
NotWebsocket.prototype.leave = function(rm) {
|
||||
if(rm in rooms) {
|
||||
var idx = rooms[rm].indexOf(this);
|
||||
if(idx >= 0) {
|
||||
rooms[rm].splice(idx, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NotWebsocket.prototype.disconnect = function() {
|
||||
for(var rm in rooms) {
|
||||
this.leave(rm);
|
||||
}
|
||||
|
||||
this.recv(JSON.stringify(["disconnect", undefined]));
|
||||
this.emit("disconnect");
|
||||
|
||||
clients[this.hash] = null;
|
||||
delete clients[this.hash];
|
||||
}
|
||||
|
||||
function sendJSON(res, obj) {
|
||||
var response = JSON.stringify(obj, null, 4);
|
||||
if(res.callback) {
|
||||
response = res.callback + "(" + response + ")";
|
||||
}
|
||||
var len = unescape(encodeURIComponent(response)).length;
|
||||
|
||||
res.setHeader("Content-Type", "application/json");
|
||||
res.setHeader("Content-Length", len);
|
||||
res.end(response);
|
||||
}
|
||||
|
||||
var clients = {};
|
||||
var rooms = {};
|
||||
|
||||
function newConnection(req, res) {
|
||||
var nws = new NotWebsocket();
|
||||
clients[nws.hash] = nws;
|
||||
res.callback = req.query.callback;
|
||||
sendJSON(res, nws.hash);
|
||||
return nws;
|
||||
}
|
||||
exports.newConnection = newConnection;
|
||||
|
||||
function msgReceived(req, res) {
|
||||
var h = req.params.hash;
|
||||
if(h in clients && clients[h] != null) {
|
||||
var str = req.params.str;
|
||||
res.callback = req.query.callback;
|
||||
try {
|
||||
if(str == "poll") {
|
||||
sendJSON(res, clients[h].poll());
|
||||
}
|
||||
else {
|
||||
clients[h].recv(unescape(str));
|
||||
sendJSON(res, "");
|
||||
}
|
||||
}
|
||||
catch(e) {
|
||||
res.send(429); // 429 Too Many Requests
|
||||
}
|
||||
}
|
||||
else {
|
||||
res.send(404);
|
||||
}
|
||||
}
|
||||
exports.msgReceived = msgReceived;
|
||||
|
||||
function inRoom(rm) {
|
||||
var cl = [];
|
||||
|
||||
if(rm in rooms) {
|
||||
for(var i = 0; i < rooms[rm].length; i++) {
|
||||
cl.push(rooms[rm][i]);
|
||||
}
|
||||
}
|
||||
|
||||
cl.emit = function(msg, data) {
|
||||
for(var i = 0; i < this.length; i++) {
|
||||
this[i].emit(msg, data);
|
||||
}
|
||||
};
|
||||
|
||||
return cl;
|
||||
}
|
||||
exports.inRoom = inRoom;
|
||||
|
||||
function checkDeadSockets() {
|
||||
for(var h in clients) {
|
||||
if(Date.now() - clients[h].lastpoll >= 2000) {
|
||||
clients[h].disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setInterval(checkDeadSockets, 2000);
|
|
@ -2,7 +2,7 @@
|
|||
"author": "Calvin Montgomery",
|
||||
"name": "CyTube",
|
||||
"description": "Online media synchronizer and chat",
|
||||
"version": "1.9.3",
|
||||
"version": "1.9.4",
|
||||
"repository": {
|
||||
"url": "http://github.com/calzoneman/sync"
|
||||
},
|
||||
|
|
50
server.js
50
server.js
|
@ -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 = "1.9.3";
|
||||
const VERSION = "1.9.4";
|
||||
|
||||
var fs = require("fs");
|
||||
var Logger = require("./logger.js");
|
||||
|
@ -18,6 +18,7 @@ Logger.syslog.log("Starting CyTube v" + VERSION);
|
|||
var Config = require("./config.js");
|
||||
var express = require("express");
|
||||
var API = require("./api.js");
|
||||
var NWS = require("./notwebsocket");
|
||||
|
||||
var app = express();
|
||||
app.get("/r/:channel(*)", function(req, res, next) {
|
||||
|
@ -34,6 +35,53 @@ app.get("/api/:apireq(*)", function(req, res, next) {
|
|||
API.handle(req.url.substring(5), req, res);
|
||||
});
|
||||
|
||||
function getClientIP(req) {
|
||||
var ip;
|
||||
var forward = req.header("x-forwarded-for");
|
||||
if(forward) {
|
||||
ip = forward.split(",")[0];
|
||||
}
|
||||
if(!ip) {
|
||||
ip = req.connection.remoteAddress;
|
||||
}
|
||||
return ip;
|
||||
}
|
||||
|
||||
app.get("/nws/connect", function(req, res, next) {
|
||||
var socket = NWS.newConnection(req, res);
|
||||
var ip = getClientIP(req);
|
||||
if(Database.checkGlobalBan(ip)) {
|
||||
Logger.syslog.log("Disconnecting " + ip + " - bant");
|
||||
socket.emit("kick", {
|
||||
reason: "You're globally banned!"
|
||||
});
|
||||
socket.disconnect(true);
|
||||
return;
|
||||
}
|
||||
socket.on("disconnect", function() {
|
||||
exports.clients[ip]--;
|
||||
});
|
||||
if(!(ip in exports.clients)) {
|
||||
exports.clients[ip] = 1;
|
||||
}
|
||||
else {
|
||||
exports.clients[ip]++;
|
||||
}
|
||||
if(exports.clients[ip] > Config.MAX_PER_IP) {
|
||||
socket.emit("kick", {
|
||||
reason: "Too many connections from your IP address"
|
||||
});
|
||||
socket.disconnect(true);
|
||||
return;
|
||||
}
|
||||
var user = new User(socket, ip);
|
||||
Logger.syslog.log("Accepted connection from /" + user.ip);
|
||||
});
|
||||
|
||||
app.get("/nws/:hash/:str", function(req, res, next) {
|
||||
NWS.msgReceived(req, res);
|
||||
});
|
||||
|
||||
app.get("/:thing(*)", function(req, res, next) {
|
||||
res.sendfile(__dirname + "/www/" + req.params.thing);
|
||||
});
|
||||
|
|
12
user.js
12
user.js
|
@ -146,6 +146,12 @@ User.prototype.initCallbacks = function() {
|
|||
}
|
||||
}.bind(this));
|
||||
|
||||
this.socket.on("setChannelRank", function(data) {
|
||||
if(this.channel != null) {
|
||||
this.channel.trySetRank(this, data);
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
this.socket.on("banName", function(data) {
|
||||
if(this.channel != null) {
|
||||
this.channel.banName(this, data.name || "");
|
||||
|
@ -521,11 +527,7 @@ User.prototype.login = function(name, pw, session) {
|
|||
if(this.channel != null && name != "") {
|
||||
for(var i = 0; i < this.channel.users.length; i++) {
|
||||
if(this.channel.users[i].name == name) {
|
||||
this.socket.emit("login", {
|
||||
success: false,
|
||||
error: "The username " + name + " is already in use on this channel"
|
||||
});
|
||||
return false;
|
||||
this.channel.kick(this.channel.users[i], "Duplicate login");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,12 +77,21 @@ html, body {
|
|||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
#usercount, #currenttitle {
|
||||
#usercountcontainer, #currenttitle {
|
||||
border: 1px solid #aaaaaa;
|
||||
border-bottom: none;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
#usercount {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
#ulistchevron {
|
||||
cursor: pointer;
|
||||
float: left;
|
||||
}
|
||||
|
||||
#plmeta {
|
||||
border: 1px solid #aaaaaa;
|
||||
background-color: #ffffff;
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
/*
|
||||
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 uname = readCookie("sync_uname") || "";
|
||||
var session = readCookie("sync_session") || "";
|
||||
var api = WEB_URL + "/api/json/";
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
Callbacks = {
|
||||
|
||||
connect: function() {
|
||||
|
@ -193,9 +204,9 @@ Callbacks = {
|
|||
$("#opt_customjs").val(opts.customjs);
|
||||
$("#opt_chat_antiflood").prop("checked", opts.chat_antiflood);
|
||||
$("#opt_show_public").prop("checked", opts.show_public);
|
||||
$("#opt_enable_link_regex").prop("checked", opts.enable_link_regex);
|
||||
$("#customCss").remove();
|
||||
if(opts.customcss.trim() != "") {
|
||||
$("#usertheme").remove();
|
||||
$("<link/>")
|
||||
.attr("rel", "stylesheet")
|
||||
.attr("href", opts.customcss)
|
||||
|
@ -242,7 +253,6 @@ Callbacks = {
|
|||
$("#jstext").val(data.js);
|
||||
|
||||
if(data.css) {
|
||||
$("#usertheme").remove();
|
||||
$("<style/>").attr("type", "text/css")
|
||||
.attr("id", "chancss")
|
||||
.text(data.css)
|
||||
|
@ -352,40 +362,18 @@ Callbacks = {
|
|||
}
|
||||
}
|
||||
loadACLPage(0);
|
||||
return;
|
||||
for(var i = 0; i < entries.length; i++) {
|
||||
var tr = $("<tr/>").appendTo(tbl);
|
||||
var name = $("<td/>").text(entries[i].name).appendTo(tr);
|
||||
name.addClass(getNameColor(entries[i].rank));
|
||||
var rank = $("<td/>").text(entries[i].rank).appendTo(tr);
|
||||
var control = $("<td/>").appendTo(tr);
|
||||
var up = $("<button/>").addClass("btn btn-mini btn-success")
|
||||
.appendTo(control);
|
||||
$("<i/>").addClass("icon-plus").appendTo(up);
|
||||
var down = $("<button/>").addClass("btn btn-mini btn-danger")
|
||||
.appendTo(control);
|
||||
$("<i/>").addClass("icon-minus").appendTo(down);
|
||||
if(entries[i].rank + 1 >= RANK) {
|
||||
up.attr("disabled", true);
|
||||
}
|
||||
else {
|
||||
up.click(function(name) { return function() {
|
||||
socket.emit("promote", {
|
||||
name: name
|
||||
});
|
||||
}}(entries[i].name));
|
||||
}
|
||||
if(entries[i].rank >= RANK) {
|
||||
down.attr("disabled", true);
|
||||
}
|
||||
else {
|
||||
down.click(function(name) { return function() {
|
||||
socket.emit("demote", {
|
||||
name: name
|
||||
});
|
||||
}}(entries[i].name));
|
||||
},
|
||||
|
||||
setChannelRank: function(data) {
|
||||
var ents = $("#channelranks").data("entries");
|
||||
for(var i = 0; i < ents.length; i++) {
|
||||
if(ents[i].name == data.user) {
|
||||
ents[i].rank = data.rank;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$("#channelranks").data("entries", ents);
|
||||
loadACLPage($("#channelranks").data("page"));
|
||||
},
|
||||
|
||||
voteskip: function(data) {
|
||||
|
@ -506,6 +494,7 @@ Callbacks = {
|
|||
formatUserlistItem(users[i], data);
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
userLeave: function(data) {
|
||||
|
@ -572,8 +561,11 @@ Callbacks = {
|
|||
$(li).show("blind");
|
||||
},
|
||||
|
||||
queueFail: function() {
|
||||
makeAlert("Error", "Queue failed. Check your link to make sure it is valid.", "alert-error")
|
||||
queueFail: function(data) {
|
||||
if(!data) {
|
||||
data = "Queue failed. Check your link to make sure it is valid.";
|
||||
}
|
||||
makeAlert("Error", data, "alert-error")
|
||||
.insertAfter($("#playlist_controls"));
|
||||
},
|
||||
|
||||
|
@ -846,3 +838,9 @@ $.getScript(IO_URL+"/socket.io/socket.io.js", function() {
|
|||
Callbacks.disconnect();
|
||||
}
|
||||
});
|
||||
|
||||
window.setupNewSocket = function() {
|
||||
for(var key in Callbacks) {
|
||||
socket.on(key, Callbacks[key]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,25 +53,33 @@ function parseBool(x) {
|
|||
else return Boolean(x);
|
||||
}
|
||||
|
||||
function getOrDefault(cookie, def) {
|
||||
var cook = readCookie(cookie);
|
||||
if(cook === null) {
|
||||
getOrDefault = function(k, def) {
|
||||
var v = localStorage.getItem(k);
|
||||
if(v === null)
|
||||
return def;
|
||||
}
|
||||
return cook;
|
||||
if(v === "true")
|
||||
return true;
|
||||
if(v === "false")
|
||||
return false;
|
||||
if(v.match(/[0-9]+/))
|
||||
return parseInt(v);
|
||||
if(v.match(/[0-9\.]+/))
|
||||
return parseFloat(v);
|
||||
return v;
|
||||
}
|
||||
|
||||
var USEROPTS = {
|
||||
theme : getOrDefault("cytube_theme", "default"),
|
||||
css : getOrDefault("cytube_css", ""),
|
||||
layout : getOrDefault("cytube_layout", "default"),
|
||||
synch : parseBool(getOrDefault("cytube_synch", true)),
|
||||
hidevid : parseBool(getOrDefault("cytube_hidevid", false)),
|
||||
show_timestamps : parseBool(getOrDefault("cytube_show_timestamps", false)),
|
||||
modhat : parseBool(getOrDefault("cytube_modhat", false)),
|
||||
blink_title : parseBool(getOrDefault("cytube_blink_title", false)),
|
||||
sync_accuracy : parseFloat(getOrDefault("cytube_sync_accuracy", 2)) || 2,
|
||||
chatbtn : parseBool(getOrDefault("cytube_chatbtn", false))
|
||||
theme : getOrDefault("theme", "default"),
|
||||
css : getOrDefault("css", ""),
|
||||
layout : getOrDefault("layout", "default"),
|
||||
synch : getOrDefault("synch", true),
|
||||
hidevid : getOrDefault("hidevid", false),
|
||||
show_timestamps : getOrDefault("show_timestamps", true),
|
||||
modhat : getOrDefault("modhat", false),
|
||||
blink_title : getOrDefault("blink_title", false),
|
||||
sync_accuracy : getOrDefault("sync_accuracy", 2),
|
||||
chatbtn : getOrDefault("chatbtn", false),
|
||||
altsocket : getOrDefault("altsocket", false)
|
||||
};
|
||||
applyOpts();
|
||||
$("#optlink").click(showUserOpts);
|
||||
|
@ -141,6 +149,18 @@ if(!USEROPTS.hidevid) {
|
|||
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
|
||||
}
|
||||
|
||||
$("#ulistchevron").click(function() {
|
||||
var state = $("#userlist").css("display");
|
||||
if(state == "none") {
|
||||
$("#userlist").show();
|
||||
$("#ulistchevron").removeClass().addClass("icon-chevron-up");
|
||||
}
|
||||
else {
|
||||
$("#userlist").hide();
|
||||
$("#ulistchevron").removeClass().addClass("icon-chevron-down");
|
||||
}
|
||||
});
|
||||
|
||||
var sendVideoUpdate = function() { }
|
||||
setInterval(function() {
|
||||
sendVideoUpdate();
|
||||
|
@ -365,7 +385,8 @@ $("#opt_submit").click(function() {
|
|||
customcss: css,
|
||||
customjs: $("#opt_customjs").val(),
|
||||
chat_antiflood: $("#opt_chat_antiflood").prop("checked"),
|
||||
show_public: $("#opt_show_public").prop("checked")
|
||||
show_public: $("#opt_show_public").prop("checked"),
|
||||
enable_link_regex: $("#opt_enable_link_regex").prop("checked")
|
||||
};
|
||||
socket.emit("channelOpts", opts);
|
||||
});
|
||||
|
|
|
@ -130,7 +130,7 @@ function addUserDropdown(entry, name) {
|
|||
a.text("IP Ban");
|
||||
a.click(function() {
|
||||
socket.emit("chatMsg", {
|
||||
msg: "/ban " + name
|
||||
msg: "/ipban " + name
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -499,7 +499,6 @@ function loadLoginlogPage(page) {
|
|||
.text("Ban IP Range")
|
||||
.appendTo(bantd);
|
||||
var callback = (function(id, name) { return function() {
|
||||
console.log(id, name);
|
||||
socket.emit("banIP", {
|
||||
id: id,
|
||||
name: name,
|
||||
|
@ -509,7 +508,6 @@ function loadLoginlogPage(page) {
|
|||
} })(entries[i].id, entries[i].names[0]);
|
||||
ban.click(callback);
|
||||
var callback2 = (function(id, name) { return function() {
|
||||
console.log(id, name);
|
||||
socket.emit("banIP", {
|
||||
id: id,
|
||||
name: name,
|
||||
|
@ -561,6 +559,7 @@ function loadLoginlogPage(page) {
|
|||
|
||||
function loadACLPage(page) {
|
||||
var entries = $("#channelranks").data("entries");
|
||||
$("#channelranks").data("page", page);
|
||||
var start = page * 20;
|
||||
var tbl = $("#channelranks table");
|
||||
if(tbl.children().length > 1) {
|
||||
|
@ -570,34 +569,42 @@ function loadACLPage(page) {
|
|||
var tr = $("<tr/>").appendTo(tbl);
|
||||
var name = $("<td/>").text(entries[i].name).appendTo(tr);
|
||||
name.addClass(getNameColor(entries[i].rank));
|
||||
var rank = $("<td/>").text(entries[i].rank).appendTo(tr);
|
||||
var control = $("<td/>").appendTo(tr);
|
||||
var up = $("<button/>").addClass("btn btn-mini btn-success")
|
||||
.appendTo(control);
|
||||
$("<i/>").addClass("icon-plus").appendTo(up);
|
||||
var down = $("<button/>").addClass("btn btn-mini btn-danger")
|
||||
.appendTo(control);
|
||||
$("<i/>").addClass("icon-minus").appendTo(down);
|
||||
if(entries[i].rank + 1 >= RANK) {
|
||||
up.attr("disabled", true);
|
||||
}
|
||||
else {
|
||||
up.click(function(name) { return function() {
|
||||
socket.emit("promote", {
|
||||
name: name
|
||||
var rank = $("<td/>").text(entries[i].rank)
|
||||
.css("min-width", "220px")
|
||||
.appendTo(tr);
|
||||
(function(name) {
|
||||
rank.click(function() {
|
||||
if(this.find(".rank-edit").length > 0)
|
||||
return;
|
||||
var r = this.text();
|
||||
this.text("");
|
||||
var edit = $("<input/>").attr("type", "text")
|
||||
.attr("placeholder", r)
|
||||
.addClass("rank-edit")
|
||||
.appendTo(this)
|
||||
.focus();
|
||||
if(parseInt(r) >= RANK) {
|
||||
edit.attr("disabled", true);
|
||||
}
|
||||
function save() {
|
||||
var r = this.val();
|
||||
var r2 = r;
|
||||
if(r.trim() == "" || parseInt(r) >= RANK || parseInt(r) < 1)
|
||||
r = this.attr("placeholder");
|
||||
r = parseInt(r) + "";
|
||||
this.parent().text(r);
|
||||
socket.emit("setChannelRank", {
|
||||
user: name,
|
||||
rank: parseInt(r)
|
||||
});
|
||||
}}(entries[i].name));
|
||||
}
|
||||
if(entries[i].rank >= RANK) {
|
||||
down.attr("disabled", true);
|
||||
}
|
||||
else {
|
||||
down.click(function(name) { return function() {
|
||||
socket.emit("demote", {
|
||||
name: name
|
||||
});
|
||||
}}(entries[i].name));
|
||||
}
|
||||
}
|
||||
edit.blur(save.bind(edit));
|
||||
edit.keydown(function(ev) {
|
||||
if(ev.keyCode == 13)
|
||||
save.bind(edit)();
|
||||
});
|
||||
}.bind(rank));
|
||||
})(entries[i].name);
|
||||
}
|
||||
if($("#acl_pagination").length > 0) {
|
||||
$("#acl_pagination").find("li").each(function() {
|
||||
|
@ -669,6 +676,8 @@ function parseVideoURL(url){
|
|||
return [parseVimeo(url), "vi"];
|
||||
else if(url.indexOf("dailymotion.com") != -1)
|
||||
return [parseDailymotion(url), "dm"];
|
||||
else if(url.indexOf("imgur.com") != -1)
|
||||
return [parseImgur(url), "im"];
|
||||
}
|
||||
|
||||
function parseYTURL(url) {
|
||||
|
@ -743,6 +752,14 @@ function parseDailymotion(url) {
|
|||
return null;
|
||||
}
|
||||
|
||||
function parseImgur(url) {
|
||||
var m = url.match(/imgur\.com\/a\/([a-zA-Z0-9]+)/);
|
||||
if(m) {
|
||||
return m[1];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function closePoll() {
|
||||
if($("#pollcontainer .active").length != 0) {
|
||||
var poll = $("#pollcontainer .active");
|
||||
|
@ -1070,6 +1087,13 @@ function showUserOpts() {
|
|||
sendbtn.prop("checked", USEROPTS.chatbtn);
|
||||
addOption("Send Button", sendbtncontainer);
|
||||
|
||||
var altsocketcontainer = $("<label/>").addClass("checkbox")
|
||||
.text("Use alternative socket connection");
|
||||
var altsocket = $("<input/>").attr("type", "checkbox")
|
||||
.appendTo(altsocketcontainer);
|
||||
altsocket.prop("checked", USEROPTS.altsocket);
|
||||
addOption("Alternate Socket", altsocketcontainer);
|
||||
|
||||
var profile = $("<a/>").attr("target", "_blank")
|
||||
.addClass("btn")
|
||||
.attr("href", "./account.html")
|
||||
|
@ -1100,6 +1124,7 @@ function showUserOpts() {
|
|||
USEROPTS.show_timestamps = showts.prop("checked");
|
||||
USEROPTS.blink_title = blink.prop("checked");
|
||||
USEROPTS.chatbtn = sendbtn.prop("checked");
|
||||
USEROPTS.altsocket = altsocket.prop("checked");
|
||||
if(RANK >= Rank.Moderator) {
|
||||
USEROPTS.modhat = modhat.prop("checked");
|
||||
}
|
||||
|
@ -1117,10 +1142,13 @@ function showUserOpts() {
|
|||
|
||||
function saveOpts() {
|
||||
for(var key in USEROPTS) {
|
||||
createCookie("cytube_"+key, USEROPTS[key], 100);
|
||||
localStorage.setItem(key, USEROPTS[key]);
|
||||
}
|
||||
}
|
||||
|
||||
// To be overridden in callbacks.js
|
||||
function setupNewSocket() { }
|
||||
|
||||
function applyOpts() {
|
||||
$("#usertheme").remove();
|
||||
if(USEROPTS.theme != "default") {
|
||||
|
@ -1179,6 +1207,22 @@ function applyOpts() {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
if(USEROPTS.altsocket) {
|
||||
if(socket)
|
||||
socket.disconnect();
|
||||
socket = new NotWebsocket();
|
||||
setupNewSocket();
|
||||
}
|
||||
// Switch from NotWebsocket => Socket.io
|
||||
else if(socket && typeof socket.poll !== "undefined") {
|
||||
try {
|
||||
socket = io.connect(IO_URL);
|
||||
setupNewSocket();
|
||||
}
|
||||
catch(e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function idToURL(data) {
|
||||
|
@ -1277,6 +1321,7 @@ function genPermissionsEditor() {
|
|||
makeOption("Delete playlist items", "playlistdelete", standard, CHANPERMS.playlistdelete+"");
|
||||
makeOption("Jump to video", "playlistjump", standard, CHANPERMS.playlistjump+"");
|
||||
makeOption("Queue playlist", "playlistaddlist", standard, CHANPERMS.playlistaddlist+"");
|
||||
makeOption("Queue livestream", "playlistaddlive", standard, CHANPERMS.playlistaddlive+"");
|
||||
makeOption("Add nontemporary media", "addnontemp", standard, CHANPERMS.addnontemp+"");
|
||||
makeOption("Temp/untemp playlist item", "settemp", standard, CHANPERMS.settemp+"");
|
||||
makeOption("Retrieve playlist URLs", "playlistgeturl", standard, CHANPERMS.playlistgeturl+"");
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
/*
|
||||
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 Media = function(data) {
|
||||
if(!data) {
|
||||
data = {
|
||||
|
@ -40,6 +51,9 @@ var Media = function(data) {
|
|||
case "us":
|
||||
this.initUstream();
|
||||
break;
|
||||
case "im":
|
||||
this.initImgur();
|
||||
break;
|
||||
default:
|
||||
this.nullPlayer();
|
||||
break;
|
||||
|
@ -456,6 +470,31 @@ Media.prototype.initUstream = function() {
|
|||
this.seek = function() { }
|
||||
}
|
||||
|
||||
Media.prototype.initImgur = function() {
|
||||
var iframe = $("<iframe/>").insertBefore($("#ytapiplayer"));
|
||||
$("#ytapiplayer").remove();
|
||||
iframe.attr("id", "ytapiplayer");
|
||||
iframe.attr("width", VWIDTH);
|
||||
iframe.attr("height", VHEIGHT);
|
||||
iframe.attr("src", "http://imgur.com/a/"+this.id+"/embed");
|
||||
iframe.attr("frameborder", "0");
|
||||
iframe.attr("scrolling", "no");
|
||||
iframe.css("border", "none");
|
||||
|
||||
this.load = function(data) {
|
||||
this.id = data.id;
|
||||
this.initImgur()
|
||||
}
|
||||
|
||||
this.pause = function() { }
|
||||
|
||||
this.play = function() { }
|
||||
|
||||
this.getTime = function() { }
|
||||
|
||||
this.seek = function() { }
|
||||
}
|
||||
|
||||
Media.prototype.update = function(data) {
|
||||
if(data.id && data.id != this.id) {
|
||||
if(data.currentTime < 0) {
|
||||
|
|
|
@ -0,0 +1,132 @@
|
|||
/*
|
||||
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 NotWebsocket = function() {
|
||||
this.connected = false;
|
||||
this.polltmr = false;
|
||||
$.getJSON(WEB_URL + "/nws/connect", function(data) {
|
||||
this.hash = data;
|
||||
this.connected = true;
|
||||
this.recv(["connect", undefined]);
|
||||
this.pollint = 100;
|
||||
this.pollonce();
|
||||
}.bind(this));
|
||||
|
||||
this.handlers = {};
|
||||
}
|
||||
|
||||
NotWebsocket.prototype.pollonce = function() {
|
||||
if(this.polltmr !== false)
|
||||
clearTimeout(this.polltmr);
|
||||
if(!this.connected)
|
||||
return;
|
||||
this.poll();
|
||||
this.polltmr = setTimeout(function() {
|
||||
this.pollonce();
|
||||
}.bind(this), this.pollint);
|
||||
}
|
||||
|
||||
NotWebsocket.prototype.poll = function() {
|
||||
if(!this.connected)
|
||||
return;
|
||||
if(this.polling)
|
||||
return;
|
||||
$.getJSON(WEB_URL+"/nws/"+this.hash+"/poll?callback=?", function(data) {
|
||||
this.polling = true;
|
||||
// Adaptive polling rate
|
||||
// Poll every 1000ms if no activity
|
||||
// every 500ms if minor activity
|
||||
// every 100ms is very active
|
||||
if(data.length == 0) {
|
||||
this.pollint = 1000;
|
||||
}
|
||||
else if(data.length < 10 && this.pollint < 500) {
|
||||
this.pollint += 100;
|
||||
}
|
||||
else if(data.length > 10) {
|
||||
this.pollint = 100;
|
||||
}
|
||||
for(var i = 0; i < data.length; i++) {
|
||||
try {
|
||||
this.recv(data[i]);
|
||||
}
|
||||
catch(e) { }
|
||||
}
|
||||
this.polling = false;
|
||||
}.bind(this))
|
||||
.fail(function() {
|
||||
this.disconnect();
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
NotWebsocket.prototype.emit = function(msg, data) {
|
||||
if(!this.connected) {
|
||||
setTimeout(function() {
|
||||
this.emit(msg, data);
|
||||
}.bind(this), 100);
|
||||
return;
|
||||
}
|
||||
var pkt = [msg, data];
|
||||
var str = escape(JSON.stringify(pkt)).replace(/\//g, "%2F");
|
||||
$.getJSON(WEB_URL+"/nws/"+this.hash+"/"+str, function() {
|
||||
// Poll more quickly because sending a packet usually means
|
||||
// expecting some data to come back
|
||||
this.pollint = 100;
|
||||
this.pollonce();
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
NotWebsocket.prototype.reconnect = function() {
|
||||
$.getJSON(WEB_URL + "/nws/connect", function(data) {
|
||||
this.hash = data;
|
||||
this.connected = true;
|
||||
this.recv(["connect", undefined]);
|
||||
this.pollint = setInterval(function() {
|
||||
this.poll();
|
||||
}.bind(this), 100);
|
||||
}.bind(this))
|
||||
.fail(function() {
|
||||
if(this.reconndelay < 10000)
|
||||
this.reconndelay += 500;
|
||||
setTimeout(function() {
|
||||
this.reconnect();
|
||||
}.bind(this), this.reconndelay);
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
NotWebsocket.prototype.on = function(msg, callback) {
|
||||
if(!(msg in this.handlers))
|
||||
this.handlers[msg] = [];
|
||||
this.handlers[msg].push(callback);
|
||||
}
|
||||
|
||||
NotWebsocket.prototype.recv = function(pkt) {
|
||||
var msg = pkt[0], data = pkt[1];
|
||||
if(!(msg in this.handlers)) {
|
||||
return;
|
||||
}
|
||||
for(var i = 0; i < this.handlers[msg].length; i++) {
|
||||
this.handlers[msg][i](data);
|
||||
}
|
||||
}
|
||||
|
||||
NotWebsocket.prototype.disconnect = function() {
|
||||
this.recv(["disconnect", undefined]);
|
||||
if(this.polltmr !== false)
|
||||
clearTimeout(this.polltmr);
|
||||
this.polltmr = false;
|
||||
this.connected = false;
|
||||
this.reconndelay = 1000;
|
||||
setTimeout(function() {
|
||||
this.reconnect();
|
||||
}.bind(this), this.reconndelay);
|
||||
}
|
||||
|
|
@ -58,7 +58,10 @@
|
|||
</div>
|
||||
<div class="row" id="main" style="margin-top: 20px;">
|
||||
<div class="span5" id="chatdiv">
|
||||
<p id="usercount"></p>
|
||||
<div id="usercountcontainer">
|
||||
<i class="icon-chevron-up" id="ulistchevron" title="Show/Hide Userlist"></i>
|
||||
<p id="usercount"></p>
|
||||
</div>
|
||||
<div id="userlist">
|
||||
</div>
|
||||
<div id="messagebuffer">
|
||||
|
@ -209,6 +212,11 @@
|
|||
<input type="checkbox" id="opt_show_public">
|
||||
Show channel publicly
|
||||
</label>
|
||||
<br>
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" id="opt_enable_link_regex">
|
||||
Convert URLs to links in chat messages
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="span10">
|
||||
|
@ -288,8 +296,7 @@
|
|||
<table class="table table-striped">
|
||||
<thead>
|
||||
<th>Name</th>
|
||||
<th>Rank</th>
|
||||
<th>Control</th>
|
||||
<th>Rank (Click to edit)</th>
|
||||
</thead>
|
||||
</table>
|
||||
</div>
|
||||
|
@ -310,6 +317,7 @@
|
|||
<script src="./assets/js/jquery.js"></script>
|
||||
<!-- My Javascript -->
|
||||
<script src="./assets/js/iourl.js"></script>
|
||||
<script src="./assets/js/notwebsocket.js"></script>
|
||||
<script src="./assets/js/media.js"></script>
|
||||
<script src="./assets/js/functions.js"></script>
|
||||
<script src="./assets/js/client.js"></script>
|
||||
|
|
Loading…
Reference in New Issue