1
0
mirror of https://github.com/videojs/video.js.git synced 2025-11-06 09:19:15 +02:00

perf(live-tracker): disable live tracker on IE11 when document is hidden (#5896)

Disable the live tracker on IE11 when the document is hidden to fix the slow down and eventual crashing of web pages on IE11.

After #5879 was completed, we noticed that live streams still have an issue. This is because the live tracker we have also uses setInterval. Unfortunately, just disabling setInterval in the live tracker was not enough. Instead, we decided the best course of action is to just disable the live tracker altogether.
This commit is contained in:
Brandon Casey
2019-03-28 18:19:07 -04:00
committed by Gary Katsevman
parent 6c644feaa0
commit 511f729b7a

View File

@@ -1,5 +1,7 @@
import Component from './component.js'; import Component from './component.js';
import mergeOptions from './utils/merge-options.js'; import mergeOptions from './utils/merge-options.js';
import document from 'global/document';
import * as browser from './utils/browser.js';
/* track when we are at the live edge, and other helpers for live playback */ /* track when we are at the live edge, and other helpers for live playback */
class LiveTracker extends Component { class LiveTracker extends Component {
@@ -13,6 +15,25 @@ class LiveTracker extends Component {
this.reset_(); this.reset_();
this.on(this.player_, 'durationchange', this.handleDurationchange); this.on(this.player_, 'durationchange', this.handleDurationchange);
// we don't need to track live playback if the document is hidden,
// also, tracking when the document is hidden can
// cause the CPU to spike and eventually crash the page on IE11.
if (browser.IE_VERSION && 'hidden' in document && 'visibilityState' in document) {
this.on(document, 'visibilitychange', this.handleVisibilityChange);
}
}
handleVisibilityChange() {
if (this.player_.duration() !== Infinity) {
return;
}
if (document.hidden) {
this.stopTracking();
} else {
this.startTracking();
}
} }
isBehind_() { isBehind_() {