Skip to content

Commit

Permalink
fix: refactor fullscreen-api and state mediator to make fewer assumpt…
Browse files Browse the repository at this point in the history
…ions on env-specific divergences. Fixes bug in modern Safari iOS fullscreen.
  • Loading branch information
cjpillsbury committed Jul 25, 2024
1 parent 3301719 commit 4aca693
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 25 deletions.
5 changes: 3 additions & 2 deletions src/js/media-store/state-mediator.js
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,7 @@ export const stateMediator = {
},
mediaIsFullscreen: {
get(stateOwners) {
console.log('mediaIsFullscreen.get()');
const { media, documentElement, fullscreenElement = media } = stateOwners;

// Need a documentElement and a media StateOwner to be in fullscreen, so we're not fullscreen
Expand Down Expand Up @@ -981,9 +982,9 @@ export const stateMediator = {
media.requestFullscreen();
}
},
rootEvents: fullscreenApi.rootEvents,
rootEvents: ['fullscreenchange', 'webkitfullscreenchange'],
// iOS requires `webkitbeginfullscreen` and `webkitendfullscreen` events on the video.
mediaEvents: fullscreenApi.mediaEvents,
mediaEvents: ['webkitbeginfullscreen', 'webkitendfullscreen', 'webkitpresentationmodechanged']
},
mediaIsCasting: {
// Note this relies on a customized castable-video element.
Expand Down
55 changes: 32 additions & 23 deletions src/js/utils/fullscreen-api.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
import { document } from './server-safe-globals.js';

export const fullscreenApi = {
enter: 'requestFullscreen',
exit: 'exitFullscreen',
rootEvents: ['fullscreenchange'],
mediaEvents: [],
element: 'fullscreenElement',
error: 'fullscreenerror',
enabled: 'fullscreenEnabled',
};

if (document.fullscreenElement === undefined) {
fullscreenApi.enter = 'webkitRequestFullScreen';
fullscreenApi.exit =
document.webkitExitFullscreen != null
enter:
'requestFullscreen' in document
? 'requestFullscreen'
: 'webkitRequestFullScreen' in document
? 'webkitRequestFullScreen'
: undefined,
exit:
'exitFullscreen' in document
? 'exitFullscreen'
: 'webkitExitFullscreen' in document
? 'webkitExitFullscreen'
: 'webkitCancelFullScreen';
fullscreenApi.rootEvents = ['webkitfullscreenchange'];
(fullscreenApi.mediaEvents = [
'webkitbeginfullscreen',
'webkitendfullscreen',
]),
(fullscreenApi.element = 'webkitFullscreenElement');
fullscreenApi.error = 'webkitfullscreenerror';
fullscreenApi.enabled = 'webkitFullscreenEnabled';
}
: 'webkitCancelFullScreen' in document
? 'webkitCancelFullScreen'
: undefined,
element:
'fullscreenElement' in document
? 'fullscreenElement'
: 'webkitFullscreenElement' in document
? 'webkitFullscreenElement'
: undefined,
error:
'fullscreenerror' in document
? 'fullscreenerror'
: 'webkitfullscreenerror' in document
? 'webkitfullscreenerror'
: undefined,
enabled:
'fullscreenEnabled' in document
? 'fullscreenEnabled'
: 'webkitFullscreenEnabled' in document
? 'webkitFullscreenEnabled'
: undefined,
};

0 comments on commit 4aca693

Please sign in to comment.