From 3791dedb5bb2fc669878d9152bc64f18b648e310 Mon Sep 17 00:00:00 2001 From: janis Date: Thu, 23 Nov 2023 13:04:03 +0100 Subject: [PATCH] some work on blur / visibility detection --- frontend/src/client/showcase.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/frontend/src/client/showcase.js b/frontend/src/client/showcase.js index b2a8cd4..5058967 100644 --- a/frontend/src/client/showcase.js +++ b/frontend/src/client/showcase.js @@ -288,10 +288,30 @@ createApp( { } return flux; + }, + notifier() { + console.log( 'notifier enabled' ); + // Detect if window is currently in focus + window.onblur = () => { + console.log( 'left browser or page' ); + } + + // Detect key events + window.addEventListener( 'keypress', keyEvent => { + console.log( keyEvent.key ); + } ); + + // Detect if browser window becomes hidden (also with blur event) + document.addEventListener( 'visibilitychange', visibilityEvent => { + if ( document.visibilityState === 'hidden' ) { + console.log( 'left page' ); + } + } ); } }, mounted() { this.connect(); + this.notifier(); // if ( this.visualizationSettings === 'mic' ) { // this.micAudioHandler(); // }