From e479f8c34ce0831778c5a87b8d0537830072cdef Mon Sep 17 00:00:00 2001 From: Gary Katsevman Date: Thu, 29 Sep 2016 14:35:31 -0400 Subject: [PATCH] fix: proxy ios webkit events into fullscreenchange (#3644) iOS still doesn't have native fullscreen API access. The video element uses the old webkit fullscreen events `webkitbeginfullscreen` and `webkitendfullscreen`. This makes it so both of those trigger `fullscreenchange` on the player always as opposed to only when `requestFullscreen` was called on the player. --- src/js/tech/html5.js | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/src/js/tech/html5.js b/src/js/tech/html5.js index e5928178b5..0ef0057be2 100644 --- a/src/js/tech/html5.js +++ b/src/js/tech/html5.js @@ -133,6 +133,10 @@ class Html5 extends Tech { this.setControls(true); } + // on iOS, we want to proxy `webkitbeginfullscreen` and `webkitendfullscreen` + // into a `fullscreenchange` event + this.proxyWebkitFullscreen_(); + this.triggerReady(); } @@ -445,6 +449,35 @@ class Html5 extends Tech { return this.el_.offsetHeight; } + /** + * Proxy iOS `webkitbeginfullscreen` and `webkitendfullscreen` into + * `fullscreenchange` event + * + * @private + * @method proxyWebkitFullscreen_ + */ + proxyWebkitFullscreen_() { + if (!('webkitDisplayingFullscreen' in this.el_)) { + return; + } + + const endFn = function() { + this.trigger('fullscreenchange', { isFullscreen: false }); + }; + + const beginFn = function() { + this.one('webkitendfullscreen', endFn); + + this.trigger('fullscreenchange', { isFullscreen: true }); + }; + + this.on('webkitbeginfullscreen', beginFn); + this.on('dispose', () => { + this.off('webkitbeginfullscreen', beginFn); + this.off('webkitendfullscreen', endFn); + }); + } + /** * Get if there is fullscreen support * @@ -468,16 +501,6 @@ class Html5 extends Tech { enterFullScreen() { const video = this.el_; - if ('webkitDisplayingFullscreen' in video) { - this.one('webkitbeginfullscreen', function() { - this.one('webkitendfullscreen', function() { - this.trigger('fullscreenchange', { isFullscreen: false }); - }); - - this.trigger('fullscreenchange', { isFullscreen: true }); - }); - } - if (video.paused && video.networkState <= video.HAVE_METADATA) { // attempt to prime the video element for programmatic access // this isn't necessary on the desktop but shouldn't hurt