1
0
mirror of https://github.com/videojs/video.js.git synced 2024-12-10 11:10:19 +02:00

fix: explicitly remove all document-level listeners on player dispose (#5929)

This commit is contained in:
Pat O'Neill 2019-04-11 13:52:36 -04:00 committed by GitHub
parent 55b37524a3
commit 458a5ead44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -351,6 +351,11 @@ class Player extends Component {
// Run base component initializing with new options
super(null, options, ready);
// Create bound methods for document listeners.
this.boundDocumentFullscreenChange_ = Fn.bind(this, this.documentFullscreenChange_);
this.boundFullWindowOnEscKey_ = Fn.bind(this, this.fullWindowOnEscKey);
this.boundHandleKeyPress_ = Fn.bind(this, this.handleKeyPress);
// create logger
this.log = createLogger(this.id_);
@ -554,6 +559,11 @@ class Player extends Component {
// prevent dispose from being called twice
this.off('dispose');
// Make sure all player-specific document listeners are unbound. This is
Events.off(document, FullscreenApi.fullscreenchange, this.boundDocumentFullscreenChange_);
Events.off(document, 'keydown', this.boundFullWindowOnEscKey_);
Events.off(document, 'keydown', this.boundHandleKeyPress_);
if (this.styleEl_ && this.styleEl_.parentNode) {
this.styleEl_.parentNode.removeChild(this.styleEl_);
this.styleEl_ = null;
@ -1983,7 +1993,7 @@ class Player extends Component {
// If cancelling fullscreen, remove event listener.
if (this.isFullscreen() === false) {
Events.off(document, fsApi.fullscreenchange, Fn.bind(this, this.documentFullscreenChange_));
Events.off(document, fsApi.fullscreenchange, this.boundDocumentFullscreenChange_);
}
if (!prefixedFS) {
@ -2643,7 +2653,7 @@ class Player extends Component {
// when canceling fullscreen. Otherwise if there's multiple
// players on a page, they would all be reacting to the same fullscreen
// events
Events.on(document, fsApi.fullscreenchange, Fn.bind(this, this.documentFullscreenChange_));
Events.on(document, fsApi.fullscreenchange, this.boundDocumentFullscreenChange_);
this.el_[fsApi.requestFullscreen]();
@ -2701,7 +2711,7 @@ class Player extends Component {
this.docOrigOverflow = document.documentElement.style.overflow;
// Add listener for esc key to exit fullscreen
Events.on(document, 'keydown', Fn.bind(this, this.fullWindowOnEscKey));
Events.on(document, 'keydown', this.boundFullWindowOnEscKey_);
// Hide any scroll bars
document.documentElement.style.overflow = 'hidden';
@ -2740,7 +2750,7 @@ class Player extends Component {
*/
exitFullWindow() {
this.isFullWindow = false;
Events.off(document, 'keydown', this.fullWindowOnEscKey);
Events.off(document, 'keydown', this.boundFullWindowOnEscKey_);
// Unhide scroll bars.
document.documentElement.style.overflow = this.docOrigOverflow;
@ -2769,8 +2779,8 @@ class Player extends Component {
*/
handleFocus(event) {
// call off first to make sure we don't keep adding keydown handlers
Events.off(document, 'keydown', Fn.bind(this, this.handleKeyPress));
Events.on(document, 'keydown', Fn.bind(this, this.handleKeyPress));
Events.off(document, 'keydown', this.boundHandleKeyPress_);
Events.on(document, 'keydown', this.boundHandleKeyPress_);
}
/**
@ -2783,7 +2793,7 @@ class Player extends Component {
* @listens blur
*/
handleBlur(event) {
Events.off(document, 'keydown', Fn.bind(this, this.handleKeyPress));
Events.off(document, 'keydown', this.boundHandleKeyPress_);
}
/**