Skip to content

Commit

Permalink
Revert "use focus blur eventlisteners for tab switch"
Browse files Browse the repository at this point in the history
This reverts commit 4bea1a3.
  • Loading branch information
vdvibhu20 committed Apr 25, 2024
1 parent 6fa04ae commit ce312d2
Showing 1 changed file with 8 additions and 30 deletions.
38 changes: 8 additions & 30 deletions app/services/monitorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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()
},
Expand Down Expand Up @@ -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
Expand All @@ -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')
Expand Down

0 comments on commit ce312d2

Please sign in to comment.