Skip to content

Commit e479f8c

Browse files
authored
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.
1 parent 6878c21 commit e479f8c

File tree

1 file changed

+33
-10
lines changed

1 file changed

+33
-10
lines changed

src/js/tech/html5.js

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ class Html5 extends Tech {
133133
this.setControls(true);
134134
}
135135

136+
// on iOS, we want to proxy `webkitbeginfullscreen` and `webkitendfullscreen`
137+
// into a `fullscreenchange` event
138+
this.proxyWebkitFullscreen_();
139+
136140
this.triggerReady();
137141
}
138142

@@ -445,6 +449,35 @@ class Html5 extends Tech {
445449
return this.el_.offsetHeight;
446450
}
447451

452+
/**
453+
* Proxy iOS `webkitbeginfullscreen` and `webkitendfullscreen` into
454+
* `fullscreenchange` event
455+
*
456+
* @private
457+
* @method proxyWebkitFullscreen_
458+
*/
459+
proxyWebkitFullscreen_() {
460+
if (!('webkitDisplayingFullscreen' in this.el_)) {
461+
return;
462+
}
463+
464+
const endFn = function() {
465+
this.trigger('fullscreenchange', { isFullscreen: false });
466+
};
467+
468+
const beginFn = function() {
469+
this.one('webkitendfullscreen', endFn);
470+
471+
this.trigger('fullscreenchange', { isFullscreen: true });
472+
};
473+
474+
this.on('webkitbeginfullscreen', beginFn);
475+
this.on('dispose', () => {
476+
this.off('webkitbeginfullscreen', beginFn);
477+
this.off('webkitendfullscreen', endFn);
478+
});
479+
}
480+
448481
/**
449482
* Get if there is fullscreen support
450483
*
@@ -468,16 +501,6 @@ class Html5 extends Tech {
468501
enterFullScreen() {
469502
const video = this.el_;
470503

471-
if ('webkitDisplayingFullscreen' in video) {
472-
this.one('webkitbeginfullscreen', function() {
473-
this.one('webkitendfullscreen', function() {
474-
this.trigger('fullscreenchange', { isFullscreen: false });
475-
});
476-
477-
this.trigger('fullscreenchange', { isFullscreen: true });
478-
});
479-
}
480-
481504
if (video.paused && video.networkState <= video.HAVE_METADATA) {
482505
// attempt to prime the video element for programmatic access
483506
// this isn't necessary on the desktop but shouldn't hurt

0 commit comments

Comments
 (0)