Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure we clean up fullscreen document listeners on dispose. #1476

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ vjs.Player = vjs.Component.extend({
// Cache for video property values.
this.cache_ = {};

// Holds bounded event handlers
this.boundEvents = {};
this.boundEvents['keydown'] = vjs.bind(this, this.fullWindowOnEscKey);

// Set poster
this.poster_ = options['poster'];
// Set controls
Expand Down Expand Up @@ -158,6 +162,11 @@ vjs.Player.prototype.dispose = function(){
// prevent dispose from being called twice
this.off('dispose');

// remove document bounded events
for (var e in this.boundEvents) {
vjs.off(document, e, this.boundEvents[e]);
}

// Kill reference to this player
vjs.players[this.id_] = null;
if (this.tag && this.tag['player']) { this.tag['player'] = null; }
Expand Down Expand Up @@ -930,19 +939,22 @@ vjs.Player.prototype.requestFullscreen = function(){
// when cancelling fullscreen. Otherwise if there's multiple
// players on a page, they would all be reacting to the same fullscreen
// events
vjs.on(document, fsApi['fullscreenchange'], vjs.bind(this, function(e){
this.isFullscreen(document[fsApi.fullscreenElement]);

// If cancelling fullscreen, remove event listener.
if (this.isFullscreen() === false) {
vjs.off(document, fsApi['fullscreenchange'], arguments.callee);
}
if (this.boundEvents[fsApi['fullscreenchange']] == null) {
this.boundEvents[fsApi['fullscreenchange']] = vjs.bind(this, function(e) {
this.isFullscreen(document[fsApi.fullscreenElement]);

this.trigger('fullscreenchange');
}));
// If cancelling fullscreen, remove event listener.
if (this.isFullscreen() === false) {
vjs.off(document, fsApi['fullscreenchange'], this.boundEvents[fsApi['fullscreenchange']]);
}

this.el_[fsApi.requestFullscreen]();
this.trigger('fullscreenchange');
});
}

vjs.on(document, fsApi['fullscreenchange'], this.boundEvents[fsApi['fullscreenchange']]);
this.el_[fsApi.requestFullscreen]();
} else if (this.tech.supportsFullScreen()) {
// we can't take the video.js controls fullscreen but we can go fullscreen
// with native controls
Expand Down