Merge pull request #1457 from thelounge/xpaw/requestIdleCallback

Process chat messages in requestIdleCallback if available
This commit is contained in:
Al McKinlay 2017-08-26 20:57:15 +01:00 committed by GitHub
commit 099d9219fd

View file

@ -7,6 +7,17 @@ const chat = $("#chat");
const templates = require("../../views");
socket.on("msg", function(data) {
if (window.requestIdleCallback) {
// During an idle period the user agent will run idle callbacks in FIFO order
// until either the idle period ends or there are no more idle callbacks eligible to be run.
// We set a maximum timeout of 2 seconds so that messages don't take too long to appear.
window.requestIdleCallback(() => processReceivedMessage(data), {timeout: 2000});
} else {
processReceivedMessage(data);
}
});
function processReceivedMessage(data) {
const msg = render.buildChatMessage(data);
const targetId = data.chan;
const target = "#chan-" + targetId;
@ -73,4 +84,4 @@ socket.on("msg", function(data) {
}
});
}
});
}