Limit requestPlaylist to once per 60 seconds

If clients call it quickly in succession with large playlists, it can
cause node to get stuck stringifying socket.io frames and cause an out
of memory crash.
This commit is contained in:
calzoneman 2016-02-06 19:40:50 -08:00
parent 65d4ea9496
commit b3c85e8534
4 changed files with 46 additions and 7 deletions

View file

@ -490,9 +490,14 @@ $("#voteskip").click(function() {
$("#getplaylist").click(function() {
var callback = function(data) {
hidePlayer();
socket.listeners("playlist").splice(
socket.listeners("playlist").indexOf(callback)
);
var idx = socket.listeners("errorMsg").indexOf(errCallback);
if (idx >= 0) {
socket.listeners("errorMsg").splice(idx);
}
idx = socket.listeners("playlist").indexOf(callback);
if (idx >= 0) {
socket.listeners("playlist").splice(idx);
}
var list = [];
for(var i = 0; i < data.length; i++) {
var entry = formatURL(data[i].media);
@ -524,6 +529,22 @@ $("#getplaylist").click(function() {
outer.modal();
};
socket.on("playlist", callback);
var errCallback = function(data) {
if (data.code !== "REQ_PLAYLIST_LIMIT_REACHED") {
return;
}
var idx = socket.listeners("errorMsg").indexOf(errCallback);
if (idx >= 0) {
socket.listeners("errorMsg").splice(idx);
}
idx = socket.listeners("playlist").indexOf(callback);
if (idx >= 0) {
socket.listeners("playlist").splice(idx);
}
};
socket.on("errorMsg", errCallback);
socket.emit("requestPlaylist");
});