Implement recursive setTimeout polling for better inactive tab performance

parent 8a0d8dcb
No preview for this file type
...@@ -8,7 +8,7 @@ unsigned char image_jpg[] = { ...@@ -8,7 +8,7 @@ unsigned char image_jpg[] = {
0x70, 0x9c, 0xba, 0x51, 0x3c, 0x00, 0x00, 0x00, 0x06, 0x62, 0x4b, 0x47, 0x70, 0x9c, 0xba, 0x51, 0x3c, 0x00, 0x00, 0x00, 0x06, 0x62, 0x4b, 0x47,
0x44, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0xa0, 0xbd, 0xa7, 0x93, 0x00, 0x44, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0xa0, 0xbd, 0xa7, 0x93, 0x00,
0x00, 0x00, 0x07, 0x74, 0x49, 0x4d, 0x45, 0x07, 0xe9, 0x09, 0x16, 0x0f, 0x00, 0x00, 0x07, 0x74, 0x49, 0x4d, 0x45, 0x07, 0xe9, 0x09, 0x16, 0x0f,
0x22, 0x20, 0x12, 0x7d, 0xab, 0x0d, 0x00, 0x00, 0x05, 0xd4, 0x7a, 0x54, 0x24, 0x39, 0x20, 0x4c, 0xa4, 0x4b, 0x00, 0x00, 0x05, 0xd4, 0x7a, 0x54,
0x58, 0x74, 0x52, 0x61, 0x77, 0x20, 0x70, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x58, 0x74, 0x52, 0x61, 0x77, 0x20, 0x70, 0x72, 0x6f, 0x66, 0x69, 0x6c,
0x65, 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x61, 0x70, 0x70, 0x31, 0x00, 0x65, 0x20, 0x74, 0x79, 0x70, 0x65, 0x20, 0x61, 0x70, 0x70, 0x31, 0x00,
0x00, 0x48, 0x89, 0x85, 0x96, 0x59, 0x92, 0xdc, 0x38, 0x10, 0x43, 0xff, 0x00, 0x48, 0x89, 0x85, 0x96, 0x59, 0x92, 0xdc, 0x38, 0x10, 0x43, 0xff,
......
...@@ -402,7 +402,7 @@ function disconnect() { ...@@ -402,7 +402,7 @@ function disconnect() {
document.getElementById('sshUsername').disabled = false; document.getElementById('sshUsername').disabled = false;
if (pollInterval) { if (pollInterval) {
clearInterval(pollInterval); clearTimeout(pollInterval);
pollInterval = null; pollInterval = null;
} }
...@@ -444,28 +444,33 @@ function pollData() { ...@@ -444,28 +444,33 @@ function pollData() {
if (data.ended !== undefined) { if (data.ended !== undefined) {
console.log('Session ended, reloading page'); console.log('Session ended, reloading page');
if (pollInterval) { if (pollInterval) {
clearInterval(pollInterval); clearTimeout(pollInterval);
pollInterval = null; pollInterval = null;
} }
location.reload(); location.reload();
} else if (data) { } else {
console.log('Received data:', data.byteLength || data.length, 'bytes/characters'); if (data) {
// Write data to terminal console.log('Received data:', data.byteLength || data.length, 'bytes/characters');
if (data.byteLength !== undefined) { // Write data to terminal
// Binary data if (data.byteLength !== undefined) {
term.write(new Uint8Array(data)); // Binary data
} else { term.write(new Uint8Array(data));
// Text data } else {
term.write(data); // Text data
term.write(data);
}
}
// Schedule next poll
if (pollInterval) {
pollInterval = setTimeout(pollData, 100);
} }
} }
}) })
.catch(error => { .catch(error => {
console.error('Polling error:', error); console.error('Polling error:', error);
// Stop polling on error // Continue polling even on error
if (pollInterval) { if (pollInterval) {
clearInterval(pollInterval); pollInterval = setTimeout(pollData, 100);
pollInterval = null;
} }
}); });
} }
......
No preview for this file type
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment