From ce312d2e1ce006c19174b4d5ca8bc68f727fff5c Mon Sep 17 00:00:00 2001 From: Vibhu Dujari Date: Thu, 25 Apr 2024 22:24:04 +0530 Subject: [PATCH] Revert "use focus blur eventlisteners for tab switch" This reverts commit 4bea1a3b21f8a90ce21438107ecd914f0c9a68bd. --- app/services/monitorer.js | 38 ++++++++------------------------------ 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/app/services/monitorer.js b/app/services/monitorer.js index 959bcf7..c6d6881 100644 --- a/app/services/monitorer.js +++ b/app/services/monitorer.js @@ -12,7 +12,6 @@ export default Service.extend({ tabSwitchTrigger: false, windowResizeTrigger: false, isWindowResizeEventThrottled: false, - tabSwitchFaultDetected: false, isBrowserFullScreened: window.screen.availHeight === window.outerHeight && window.screen.availWidth === window.outerWidth, monitoredRoutes: [ 'contests.contest.attempt.content.problem', @@ -41,8 +40,6 @@ export default Service.extend({ this.tabSwitchEventHandler = this.tabSwitchEventHandler.bind(this) this.windowResizeEventHandler = this.windowResizeEventHandler.bind(this) this.windowResizeFaultReporter = this.windowResizeFaultReporter.bind(this) - this.windowFocusEventHandler = this.windowFocusEventHandler.bind(this) - this.windowBlurEventHandler = this.windowBlurEventHandler.bind(this) this.addObserver('isMonitoringEnabled', this, 'enableOrDisableMonitorerEvents') this.enableOrDisableMonitorerEvents() }, @@ -92,14 +89,13 @@ export default Service.extend({ const currentAttempt = await this.router.get('currentRoute.attributes.contest.currentAttempt') if(!!!currentAttempt.id) return - window.addEventListener('focus', this.windowFocusEventHandler) - window.addEventListener('blur', this.windowBlurEventHandler) - - // if('webkitHidden' in document) { - // document.addEventListener("webkitvisibilitychange", this.tabSwitchEventHandler); - // } else { - // document.addEventListener("visibilitychange", this.tabSwitchEventHandler); - // } + if('webkitHidden' in document) { + document.addEventListener("webkitvisibilitychange", this.tabSwitchEventHandler); + console.log('webkitvisibilitychange event added') + } else { + document.addEventListener("visibilitychange", this.tabSwitchEventHandler); + console.log('visibilitychange event added') + } }, async setWindowResizeEvents() {//called based on route activation @@ -116,26 +112,8 @@ export default Service.extend({ }, - async windowFocusEventHandler() { - if(this.tabSwitchFaultDetected) { - this.set('tabSwitchTrigger', true) - this.set('tabSwitchFaultDetected', false) - } - }, - - async windowBlurEventHandler() { - this.set('tabSwitchFaultDetected', true) - const currentAttempt = await this.router.get('currentRoute.attributes.contest.currentAttempt') - await this.api.request(`/contest-attempts/${currentAttempt.id}/report-monitorer-fault`, { - method: 'POST', - data: { - fault_type: 'tab_switch' - } - }) - await this.store.findRecord('contest-attempt', currentAttempt.id) - }, - async tabSwitchEventHandler() { + console.log('tabSwitchEventHandler', document.hidden, document.webkitHidden) if(!document.hidden) return this.set('tabSwitchTrigger', true) const currentAttempt = await this.router.get('currentRoute.attributes.contest.currentAttempt')