Don't delay when not in focus

This commit is contained in:
Cohee 2024-04-02 16:21:55 +03:00
parent ca047034b7
commit 2859ae54ab
1 changed files with 2 additions and 1 deletions

View File

@ -238,6 +238,7 @@ export class SmoothEventSourceStream extends EventSourceStream {
const event = chunk;
const data = event.data;
try {
const hasFocus = document.hasFocus();
const json = JSON.parse(data);
if (!json) {
@ -251,7 +252,7 @@ export class SmoothEventSourceStream extends EventSourceStream {
return controller.enqueue(event);
}
await delay(getDelay(lastStr));
hasFocus && await delay(getDelay(lastStr));
controller.enqueue(new MessageEvent(event.type, { data: JSON.stringify(parsed.data) }));
lastStr = parsed.chunk;
}