From 1cb6c3f3cfcd0e9a5c54efed4586bb48ff15cdc5 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 8 Mar 2019 10:23:18 +0000 Subject: [PATCH 1/3] Fix erroneously sending RRs, pt1. Firefox fires the blur event on both document and window. Chrome only fires it on window, so on chrome we were not seeing the window being un-focused. window seems to be the standard so just use that. This isn't the end of the story though since wer can get mousemove events without the window ever having gained focus, in which case we'll continue to think the user is active for another 2 mins when in fact all they did was pass their cursor over the window. https://github.com/vector-im/riot-web/issues/9023 --- src/UserActivity.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/UserActivity.js b/src/UserActivity.js index 145b23e36e..9e1d4f6a13 100644 --- a/src/UserActivity.js +++ b/src/UserActivity.js @@ -33,7 +33,7 @@ class UserActivity { this._attachedTimers = []; this._activityTimeout = new Timer(CURRENTLY_ACTIVE_THRESHOLD_MS); this._onUserActivity = this._onUserActivity.bind(this); - this._onDocumentBlurred = this._onDocumentBlurred.bind(this); + this._onWindowBlurred = this._onWindowBlurred.bind(this); this._onPageVisibilityChanged = this._onPageVisibilityChanged.bind(this); this.lastScreenX = 0; this.lastScreenY = 0; @@ -74,8 +74,8 @@ class UserActivity { document.onmousemove = this._onUserActivity; document.onkeydown = this._onUserActivity; document.addEventListener("visibilitychange", this._onPageVisibilityChanged); - document.addEventListener("blur", this._onDocumentBlurred); - document.addEventListener("focus", this._onUserActivity); + window.addEventListener("blur", this._onWindowBlurred); + window.addEventListener("focus", this._onUserActivity); // can't use document.scroll here because that's only the document // itself being scrolled. Need to use addEventListener's useCapture. // also this needs to be the wheel event, not scroll, as scroll is @@ -110,13 +110,14 @@ class UserActivity { _onPageVisibilityChanged(e) { if (document.visibilityState === "hidden") { + console.log("page hidden"); this._activityTimeout.abort(); } else { this._onUserActivity(e); } } - _onDocumentBlurred() { + _onWindowBlurred() { this._activityTimeout.abort(); } From 89eb321ace422905765cb1829c7e5f45a0f1fa4f Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 8 Mar 2019 10:31:30 +0000 Subject: [PATCH 2/3] copyright --- src/UserActivity.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/UserActivity.js b/src/UserActivity.js index 9e1d4f6a13..3f30686406 100644 --- a/src/UserActivity.js +++ b/src/UserActivity.js @@ -1,5 +1,6 @@ /* Copyright 2015, 2016 OpenMarket Ltd +Copyright 2019 New Vector Ltd Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. From de1ec06110f1e1fab3827795da58bd9e4807a84b Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 8 Mar 2019 10:44:48 +0000 Subject: [PATCH 3/3] oops, didn't mean to leave this in --- src/UserActivity.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/UserActivity.js b/src/UserActivity.js index 3f30686406..b49bcf1a91 100644 --- a/src/UserActivity.js +++ b/src/UserActivity.js @@ -111,7 +111,6 @@ class UserActivity { _onPageVisibilityChanged(e) { if (document.visibilityState === "hidden") { - console.log("page hidden"); this._activityTimeout.abort(); } else { this._onUserActivity(e);