mirror of
https://github.com/thelounge/thelounge
synced 2024-11-26 05:50:22 +00:00
Merge pull request #1457 from thelounge/xpaw/requestIdleCallback
Process chat messages in requestIdleCallback if available
This commit is contained in:
commit
099d9219fd
1 changed files with 12 additions and 1 deletions
|
@ -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) {
|
|||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue