From 047a2b3d175cd836d2abc2c5e80371b13bb0a6cc Mon Sep 17 00:00:00 2001 From: RblSb Date: Thu, 10 Apr 2025 01:02:32 +0300 Subject: Do not send play/pause events without page focus for better requestLeaderOnPause/unpauseWithoutLeader options --- src/client/Main.hx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/client') diff --git a/src/client/Main.hx b/src/client/Main.hx index 729658c..9a4c809 100644 --- a/src/client/Main.hx +++ b/src/client/Main.hx @@ -65,6 +65,8 @@ class Main { var onBlinkTab:Null; var gotFirstPageInteraction = false; var msgBuf = getEl("#messagebuffer"); + var isPageUnloading = false; + var isPageVisible = true; static function main():Void { new Main(); @@ -114,6 +116,12 @@ class Main { JsApi.init(this, player); document.addEventListener("click", onFirstInteraction); + window.addEventListener("beforeunload", () -> isPageUnloading = true); + window.addEventListener("blur", () -> isPageVisible = false); + window.addEventListener("focus", () -> isPageVisible = true); + document.addEventListener("visibilitychange", () -> { + isPageVisible = document.visibilityState == VISIBLE; + }); } function onFirstInteraction():Void { @@ -1463,11 +1471,13 @@ class Main { } public function hasLeaderOnPauseRequest():Bool { - return config.requestLeaderOnPause; + final hasAccess = isPageVisible && !isPageUnloading; + return config.requestLeaderOnPause && hasAccess; } public function hasUnpauseWithoutLeader():Bool { - return config.unpauseWithoutLeader; + final hasAccess = isPageVisible && !isPageUnloading; + return config.unpauseWithoutLeader && hasAccess; } public function getTemplateUrl():String { -- cgit v1.2.3