Skip to content

Commit 86256f4

Browse files
ocipapjoeyparrish
andauthored
fix(ui): Fix iOS fullscreen on rotation (#4679)
This refactors and cleans up fullscreen functionality in the UI so that all triggers are consistent and work correctly on all platforms. See also #4669 Co-authored-by: Joey Parrish <joeyparrish@users.noreply.github.com>
1 parent ad6c085 commit 86256f4

File tree

1 file changed

+44
-35
lines changed

1 file changed

+44
-35
lines changed

ui/controls.js

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -587,48 +587,57 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
587587
return false;
588588
}
589589

590-
/** @export */
591-
async toggleFullScreen() {
592-
if (document.fullscreenEnabled) {
593-
if (document.fullscreenElement) {
594-
if (screen.orientation) {
595-
screen.orientation.unlock();
590+
/** @private */
591+
async enterFullScreen_() {
592+
try {
593+
if (document.fullscreenEnabled) {
594+
if (document.pictureInPictureElement) {
595+
await document.exitPictureInPicture();
596+
}
597+
await this.videoContainer_.requestFullscreen({navigationUI: 'hide'});
598+
599+
if (this.config_.forceLandscapeOnFullscreen && screen.orientation) {
600+
// Locking to 'landscape' should let it be either
601+
// 'landscape-primary' or 'landscape-secondary' as appropriate.
602+
await screen.orientation.lock('landscape');
596603
}
597-
await document.exitFullscreen();
598604
} else {
599-
// If we are in PiP mode, leave PiP mode first.
600-
try {
601-
if (document.pictureInPictureElement) {
602-
await document.exitPictureInPicture();
603-
}
604-
await this.videoContainer_.requestFullscreen({navigationUI: 'hide'});
605-
if (this.config_.forceLandscapeOnFullscreen && screen.orientation) {
606-
try {
607-
// Locking to 'landscape' should let it be either
608-
// 'landscape-primary' or 'landscape-secondary' as appropriate.
609-
await screen.orientation.lock('landscape');
610-
} catch (error) {
611-
// If screen.orientation.lock does not work on a device, it will
612-
// be rejected with an error. Suppress that error.
613-
}
614-
}
615-
} catch (error) {
616-
this.dispatchEvent(new shaka.util.FakeEvent(
617-
'error', (new Map()).set('detail', error)));
605+
const video = /** @type {HTMLVideoElement} */(this.localVideo_);
606+
if (video.webkitSupportsFullscreen) {
607+
video.webkitEnterFullscreen();
618608
}
619609
}
610+
} catch (error) {
611+
// Entering fullscreen can fail without user interaction.
612+
this.dispatchEvent(new shaka.util.FakeEvent(
613+
'error', (new Map()).set('detail', error)));
614+
}
615+
}
616+
617+
/** @private */
618+
async exitFullScreen_() {
619+
if (document.fullscreenEnabled) {
620+
if (screen.orientation) {
621+
screen.orientation.unlock();
622+
}
623+
await document.exitFullscreen();
620624
} else {
621625
const video = /** @type {HTMLVideoElement} */(this.localVideo_);
622626
if (video.webkitSupportsFullscreen) {
623-
if (video.webkitDisplayingFullscreen) {
624-
video.webkitExitFullscreen();
625-
} else {
626-
video.webkitEnterFullscreen();
627-
}
627+
video.webkitExitFullscreen();
628628
}
629629
}
630630
}
631631

632+
/** @export */
633+
async toggleFullScreen() {
634+
if (this.isFullScreenEnabled()) {
635+
await this.exitFullScreen_();
636+
} else {
637+
await this.enterFullScreen_();
638+
}
639+
}
640+
632641
/** @export */
633642
showAdUI() {
634643
shaka.ui.Utils.setDisplay(this.adPanel_, true);
@@ -1030,11 +1039,11 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
10301039
}
10311040

10321041
if (screen.orientation.type.includes('landscape') &&
1033-
!document.fullscreenElement) {
1034-
await this.videoContainer_.requestFullscreen({navigationUI: 'hide'});
1042+
!this.isFullScreenEnabled()) {
1043+
await this.enterFullScreen_();
10351044
} else if (screen.orientation.type.includes('portrait') &&
1036-
document.fullscreenElement) {
1037-
await document.exitFullscreen();
1045+
this.isFullScreenEnabled()) {
1046+
await this.exitFullScreen_();
10381047
}
10391048
}
10401049

0 commit comments

Comments
 (0)