1
0
Fork 0

Fix CanvasImage: task running, pausing for 15 seconds by remote MCDU

The Canvas screenshot code doesn't like multiple concurrent screenshot requests,
so schedule the next load for after a currently running one is done.
This commit is contained in:
Stefan Seifert 2021-03-10 18:42:32 +01:00
parent b33dd172d7
commit 9f1bab9bb6

View file

@ -6,8 +6,16 @@
<script>
let screen;
let screen_src;
let loading = 0;
let scheduled_load = 0;
function refresh_screen() {
screen.src = screen_src + '&random=' + (new Date).getTime()
if (loading) {
scheduled_load = 1;
}
else {
loading = 1;
screen.src = screen_src + '&random=' + (new Date).getTime()
}
}
function press_button(type, text) {
let request = new XMLHttpRequest;
@ -57,6 +65,13 @@
}, true);
}
screen = document.querySelector('img');
screen.addEventListener('load', function() {
loading = 0;
if (scheduled_load) {
scheduled_load = 0;
refresh_screen();
}
});
screen_src = screen.src;
window.setInterval(refresh_screen, 1000);
}, true);