aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRblSb <msrblsb@gmail.com>2025-04-10 01:02:32 +0300
committerRblSb <msrblsb@gmail.com>2025-04-10 01:02:32 +0300
commit047a2b3d175cd836d2abc2c5e80371b13bb0a6cc (patch)
treed543df41a4c0694a39a19e131f6a42b7d07644d2 /src
parent7cc0b485f2eed746ff638e14e137eabaebaf9312 (diff)
Do not send play/pause events without page focus
for better requestLeaderOnPause/unpauseWithoutLeader options
Diffstat (limited to 'src')
-rw-r--r--src/client/Main.hx14
1 files changed, 12 insertions, 2 deletions
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<Timer>;
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 {
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage