mirror of https://github.com/calzoneman/sync.git
Fix channels not unloading / video skipping
This commit is contained in:
parent
5a5016fd79
commit
f2b6534d0a
14
acp.js
14
acp.js
|
@ -116,8 +116,9 @@ module.exports = {
|
||||||
|
|
||||||
user.socket.on("acp-list-loaded", function() {
|
user.socket.on("acp-list-loaded", function() {
|
||||||
var chans = [];
|
var chans = [];
|
||||||
for(var c in Server.channels) {
|
var all = Server.getAllChannels();
|
||||||
var chan = Server.channels[c];
|
for(var c in all) {
|
||||||
|
var chan = all[c];
|
||||||
if(!chan)
|
if(!chan)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -135,8 +136,8 @@ module.exports = {
|
||||||
});
|
});
|
||||||
|
|
||||||
user.socket.on("acp-channel-unload", function(data) {
|
user.socket.on("acp-channel-unload", function(data) {
|
||||||
if(data.name in Server.channels) {
|
if(Server.getChannel(data.name) !== undefined) {
|
||||||
var c = Server.channels[data.name];
|
var c = Server.getChannel(data.name);
|
||||||
if(!c)
|
if(!c)
|
||||||
return;
|
return;
|
||||||
ActionLog.record(user.ip, user.name, "acp-channel-unload");
|
ActionLog.record(user.ip, user.name, "acp-channel-unload");
|
||||||
|
@ -144,6 +145,11 @@ module.exports = {
|
||||||
c.users.forEach(function(u) {
|
c.users.forEach(function(u) {
|
||||||
c.kick(u, "Channel shutting down");
|
c.kick(u, "Channel shutting down");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// At this point c should be unloaded
|
||||||
|
// if it's still loaded, kill it
|
||||||
|
c = Server.getChannel(data.name);
|
||||||
|
if(c !== undefined)
|
||||||
Server.unload(c);
|
Server.unload(c);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
16
api.js
16
api.js
|
@ -131,11 +131,11 @@ function handleChannelData(params, req, res) {
|
||||||
}
|
}
|
||||||
var d = {
|
var d = {
|
||||||
name: cname,
|
name: cname,
|
||||||
loaded: (cname in Server.channels)
|
loaded: Server.getChannel(cname) !== undefined
|
||||||
};
|
};
|
||||||
|
|
||||||
if(d.loaded) {
|
if(d.loaded) {
|
||||||
var chan = Server.channels[cname];
|
var chan = Server.getChannel(cname);
|
||||||
d.pagetitle = chan.opts.pagetitle;
|
d.pagetitle = chan.opts.pagetitle;
|
||||||
d.media = chan.playlist.current ? chan.playlist.current.media.pack() : {};
|
d.media = chan.playlist.current ? chan.playlist.current.media.pack() : {};
|
||||||
d.usercount = chan.users.length;
|
d.usercount = chan.users.length;
|
||||||
|
@ -158,9 +158,10 @@ function handleChannelData(params, req, res) {
|
||||||
|
|
||||||
function handleChannelList(params, req, res) {
|
function handleChannelList(params, req, res) {
|
||||||
if(params.filter == "public") {
|
if(params.filter == "public") {
|
||||||
|
var all = Server.getAllChannels();
|
||||||
var clist = [];
|
var clist = [];
|
||||||
for(var key in Server.channels) {
|
for(var key in all) {
|
||||||
if(Server.channels[key].opts.show_public) {
|
if(all[key].opts.show_public) {
|
||||||
clist.push(key);
|
clist.push(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -175,7 +176,7 @@ function handleChannelList(params, req, res) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var clist = [];
|
var clist = [];
|
||||||
for(var key in Server.channels) {
|
for(var key in Server.getAllChannels()) {
|
||||||
clist.push(key);
|
clist.push(key);
|
||||||
}
|
}
|
||||||
handleChannelData({channel: clist.join(",")}, req, res);
|
handleChannelData({channel: clist.join(",")}, req, res);
|
||||||
|
@ -385,8 +386,9 @@ function handleProfileChange(params, req, res) {
|
||||||
error: result ? "" : "Internal error. Contact an administrator"
|
error: result ? "" : "Internal error. Contact an administrator"
|
||||||
});
|
});
|
||||||
|
|
||||||
for(var n in Server.channels) {
|
var all = Server.getAllChannels();
|
||||||
var chan = Server.channels[n];
|
for(var n in all) {
|
||||||
|
var chan = all[n];
|
||||||
for(var i = 0; i < chan.users.length; i++) {
|
for(var i = 0; i < chan.users.length; i++) {
|
||||||
if(chan.users[i].name.toLowerCase() == name) {
|
if(chan.users[i].name.toLowerCase() == name) {
|
||||||
chan.users[i].profile = {
|
chan.users[i].profile = {
|
||||||
|
|
|
@ -650,6 +650,7 @@ Channel.prototype.userLeave = function(user) {
|
||||||
this.logger.log("--- /" + user.ip + " (" + user.name + ") left");
|
this.logger.log("--- /" + user.ip + " (" + user.name + ") left");
|
||||||
if(this.users.length == 0) {
|
if(this.users.length == 0) {
|
||||||
this.logger.log("*** Channel empty, unloading");
|
this.logger.log("*** Channel empty, unloading");
|
||||||
|
var name = this.name;
|
||||||
Server.unload(this);
|
Server.unload(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
21
playlist.js
21
playlist.js
|
@ -12,6 +12,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||||
ULList = require("./ullist").ULList;
|
ULList = require("./ullist").ULList;
|
||||||
var Media = require("./media").Media;
|
var Media = require("./media").Media;
|
||||||
var InfoGetter = require("./get-info");
|
var InfoGetter = require("./get-info");
|
||||||
|
var AllPlaylists = {};
|
||||||
|
|
||||||
function PlaylistItem(media, uid) {
|
function PlaylistItem(media, uid) {
|
||||||
this.media = media;
|
this.media = media;
|
||||||
|
@ -32,6 +33,11 @@ PlaylistItem.prototype.pack = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function Playlist(chan) {
|
function Playlist(chan) {
|
||||||
|
if(chan.name in AllPlaylists && AllPlaylists[chan.name]) {
|
||||||
|
var pl = AllPlaylists[chan.name];
|
||||||
|
if("_leadInterval" in pl)
|
||||||
|
pl.die();
|
||||||
|
}
|
||||||
this.items = new ULList();
|
this.items = new ULList();
|
||||||
this.current = null;
|
this.current = null;
|
||||||
this.next_uid = 0;
|
this.next_uid = 0;
|
||||||
|
@ -47,31 +53,20 @@ function Playlist(chan) {
|
||||||
this.lock = false;
|
this.lock = false;
|
||||||
this.action_queue = [];
|
this.action_queue = [];
|
||||||
this._qaInterval = false;
|
this._qaInterval = false;
|
||||||
|
AllPlaylists[chan.name] = this;
|
||||||
|
|
||||||
if(chan) {
|
if(chan) {
|
||||||
this.channel = chan;
|
this.channel = chan;
|
||||||
var pl = this;
|
var pl = this;
|
||||||
this.on("mediaUpdate", function(m) {
|
this.on("mediaUpdate", function(m) {
|
||||||
if(chan != pl.channel) {
|
|
||||||
pl.die();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
chan.sendAll("mediaUpdate", m.timeupdate());
|
chan.sendAll("mediaUpdate", m.timeupdate());
|
||||||
});
|
});
|
||||||
this.on("changeMedia", function(m) {
|
this.on("changeMedia", function(m) {
|
||||||
if(chan != pl.channel) {
|
|
||||||
pl.die();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
chan.onVideoChange();
|
chan.onVideoChange();
|
||||||
chan.sendAll("setCurrent", pl.current.uid);
|
chan.sendAll("setCurrent", pl.current.uid);
|
||||||
chan.sendAll("changeMedia", m.fullupdate());
|
chan.sendAll("changeMedia", m.fullupdate());
|
||||||
});
|
});
|
||||||
this.on("remove", function(item) {
|
this.on("remove", function(item) {
|
||||||
if(chan != pl.channel) {
|
|
||||||
pl.die();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
chan.broadcastPlaylistMeta();
|
chan.broadcastPlaylistMeta();
|
||||||
chan.sendAll("delete", {
|
chan.sendAll("delete", {
|
||||||
uid: item.uid
|
uid: item.uid
|
||||||
|
@ -129,6 +124,8 @@ Playlist.prototype.die = function () {
|
||||||
clearInterval(this._leadInterval);
|
clearInterval(this._leadInterval);
|
||||||
this._leadInterval = false;
|
this._leadInterval = false;
|
||||||
}
|
}
|
||||||
|
for(var key in this)
|
||||||
|
delete this[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
Playlist.prototype.load = function(data, callback) {
|
Playlist.prototype.load = function(data, callback) {
|
||||||
|
|
35
server.js
35
server.js
|
@ -106,7 +106,7 @@ var Database = require("./database.js");
|
||||||
Database.setup(Config);
|
Database.setup(Config);
|
||||||
Database.init();
|
Database.init();
|
||||||
|
|
||||||
exports.channels = {};
|
var channels = {};
|
||||||
exports.clients = {};
|
exports.clients = {};
|
||||||
|
|
||||||
fs.exists("chandump", function(exists) {
|
fs.exists("chandump", function(exists) {
|
||||||
|
@ -181,19 +181,42 @@ if(!Config.DEBUG) {
|
||||||
|
|
||||||
function shutdown() {
|
function shutdown() {
|
||||||
Logger.syslog.log("Unloading channels...");
|
Logger.syslog.log("Unloading channels...");
|
||||||
for(var name in exports.channels) {
|
for(var name in channels) {
|
||||||
if(exports.channels[name].registered)
|
if(channels[name].registered)
|
||||||
exports.channels[name].saveDump();
|
channels[name].saveDump();
|
||||||
}
|
}
|
||||||
Logger.syslog.log("Shutting Down");
|
Logger.syslog.log("Shutting Down");
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.getChannel = function (name) {
|
||||||
|
return channels[name];
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.getAllChannels = function () {
|
||||||
|
return channels;
|
||||||
|
}
|
||||||
|
|
||||||
|
var Channel = require("./channel.js").Channel;
|
||||||
|
exports.createChannel = function (name) {
|
||||||
|
var chan = new Channel(name);
|
||||||
|
channels[name] = chan;
|
||||||
|
return chan;
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.getOrCreateChannel = function (name) {
|
||||||
|
var chan = exports.getChannel(name);
|
||||||
|
if(chan !== undefined)
|
||||||
|
return chan;
|
||||||
|
return exports.createChannel(name);
|
||||||
|
}
|
||||||
|
|
||||||
exports.unload = function(chan) {
|
exports.unload = function(chan) {
|
||||||
if(chan.registered) {
|
if(chan.registered) {
|
||||||
chan.saveDump();
|
chan.saveDump();
|
||||||
}
|
}
|
||||||
chan.playlist.die();
|
chan.playlist.die();
|
||||||
exports.channels[chan.name] = null;
|
delete channels[chan.name];
|
||||||
delete exports.channels[chan.name];
|
for(var i in chan)
|
||||||
|
delete chan[i];
|
||||||
}
|
}
|
||||||
|
|
10
user.js
10
user.js
|
@ -97,15 +97,7 @@ User.prototype.initCallbacks = function() {
|
||||||
if(data.name.length > 100)
|
if(data.name.length > 100)
|
||||||
return;
|
return;
|
||||||
data.name = data.name.toLowerCase();
|
data.name = data.name.toLowerCase();
|
||||||
// Channel already loaded
|
this.channel = Server.getOrCreateChannel(data.name);
|
||||||
if(data.name in Server.channels && Server.channels[data.name] != null) {
|
|
||||||
this.channel = Server.channels[data.name];
|
|
||||||
}
|
|
||||||
// Channel not loaded
|
|
||||||
else {
|
|
||||||
Server.channels[data.name] = new Channel(data.name);
|
|
||||||
this.channel = Server.channels[data.name];
|
|
||||||
}
|
|
||||||
if(this.loggedIn) {
|
if(this.loggedIn) {
|
||||||
var chanrank = this.channel.getRank(this.name);
|
var chanrank = this.channel.getRank(this.name);
|
||||||
if(chanrank > this.rank) {
|
if(chanrank > this.rank) {
|
||||||
|
|
|
@ -211,6 +211,18 @@
|
||||||
<div class="push"></div>
|
<div class="push"></div>
|
||||||
<div id="sitefooter">
|
<div id="sitefooter">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<script type="text/javascript"><!--
|
||||||
|
google_ad_client = "ca-pub-5492049762046640";
|
||||||
|
/* CyTube */
|
||||||
|
google_ad_slot = "6580478946";
|
||||||
|
google_ad_width = 728;
|
||||||
|
google_ad_height = 90;
|
||||||
|
//-->
|
||||||
|
</script>
|
||||||
|
<script type="text/javascript"
|
||||||
|
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
|
||||||
|
</script>
|
||||||
</div>
|
</div>
|
||||||
<div id="footer">
|
<div id="footer">
|
||||||
<p class="muted">
|
<p class="muted">
|
||||||
|
|
Loading…
Reference in New Issue