Skip to content

Commit 80b7bfc

Browse files
committed
fix(stream): keep visible clients foreground
1 parent 252d2c0 commit 80b7bfc

2 files changed

Lines changed: 8 additions & 10 deletions

File tree

client/src/features/stream/useLiveStream.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ function currentClientBundle(): string {
100100
}
101101

102102
function isDocumentForeground(): boolean {
103-
return document.visibilityState === "visible" && document.hasFocus();
103+
return document.visibilityState === "visible";
104104
}
105105

106106
export function useLiveStream({
@@ -371,17 +371,13 @@ export function useLiveStream({
371371

372372
sendCurrentForegroundState();
373373
document.addEventListener("visibilitychange", sendCurrentForegroundState);
374-
window.addEventListener("focus", sendCurrentForegroundState);
375-
window.addEventListener("blur", sendCurrentForegroundState);
376374
window.addEventListener("pageshow", sendCurrentForegroundState);
377375
window.addEventListener("pagehide", sendBackgroundState);
378376
return () => {
379377
document.removeEventListener(
380378
"visibilitychange",
381379
sendCurrentForegroundState,
382380
);
383-
window.removeEventListener("focus", sendCurrentForegroundState);
384-
window.removeEventListener("blur", sendCurrentForegroundState);
385381
window.removeEventListener("pageshow", sendCurrentForegroundState);
386382
window.removeEventListener("pagehide", sendBackgroundState);
387383
};

server/src/api/routes.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,9 +1408,7 @@ fn client_stats_foreground(stats: &ClientStreamStats) -> Option<bool> {
14081408
if stats.kind != "page" {
14091409
return None;
14101410
}
1411-
let visible = stats.visibility_state.as_deref() == Some("visible");
1412-
let focused = stats.focused?;
1413-
Some(visible && focused)
1411+
Some(stats.visibility_state.as_deref()? == "visible")
14141412
}
14151413

14161414
async fn native_inspector_connect(
@@ -6141,7 +6139,7 @@ mod tests {
61416139
}
61426140

61436141
#[test]
6144-
fn client_stats_foreground_requires_visible_and_focused_page() {
6142+
fn client_stats_foreground_uses_page_visibility() {
61456143
let page_stats =
61466144
|visibility_state: Option<&str>, focused: Option<bool>| ClientStreamStats {
61476145
client_id: "client".to_owned(),
@@ -6157,14 +6155,18 @@ mod tests {
61576155
);
61586156
assert_eq!(
61596157
client_stats_foreground(&page_stats(Some("visible"), Some(false))),
6160-
Some(false)
6158+
Some(true)
61616159
);
61626160
assert_eq!(
61636161
client_stats_foreground(&page_stats(Some("hidden"), Some(true))),
61646162
Some(false)
61656163
);
61666164
assert_eq!(
61676165
client_stats_foreground(&page_stats(Some("visible"), None)),
6166+
Some(true)
6167+
);
6168+
assert_eq!(
6169+
client_stats_foreground(&page_stats(None, Some(true))),
61686170
None
61696171
);
61706172
assert_eq!(

0 commit comments

Comments
 (0)