Skip to content

Commit

Permalink
fix: Fix exiting fullscreen on Safari (shaka-project#5439)
Browse files Browse the repository at this point in the history
`screen.orientation.unlock` is not defined on Safari, even though `screen.orientation` is.
This changes our orientation polyfill to add that method to `screen.orientation`.

Fixes shaka-project#5437
  • Loading branch information
theodab committed Jul 26, 2023
1 parent d6d5b15 commit ed93a0c
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions lib/polyfill/orientation.js
Expand Up @@ -6,6 +6,7 @@

goog.provide('shaka.polyfill.Orientation');

goog.require('shaka.log');
goog.require('shaka.util.FakeEvent');
goog.require('shaka.util.FakeEventTarget');
goog.require('shaka.polyfill');
Expand All @@ -23,21 +24,47 @@ shaka.polyfill.Orientation = class {
* @export
*/
static install() {
if (screen.orientation) {
if (screen.orientation && screen.orientation.unlock) {
// Not needed.
shaka.log.info('Using native screen.orientation');
return;
}

// There is no way to check to see if the 'orientationchange' event exists
// on window, which could theoretically lead to this making a
// screen.orientation object that doesn't actually work.
// However, it looks like all platforms that support the deprecated
// window.orientation feature also support that event.
if (window.orientation != undefined) {
if (screen.orientation != undefined) {
// There are some platforms where screen.orientation is defined but
// incomplete (e.g. Safari).
// Install a very simple polyfill in that case.
shaka.polyfill.Orientation.installBasedOnScreenMethods_();
} else if (window.orientation != undefined) {
// There is no way to check to see if the 'orientationchange' event exists
// on window, which could theoretically lead to this making a
// screen.orientation object that doesn't actually work.
// However, it looks like all platforms that support the deprecated
// window.orientation feature also support that event.
shaka.polyfill.Orientation.installBasedOnWindowMethods_();
}
}

/**
* Modifies screen.orientation to add no-ops for missing methods.
* Meant for cases where screen.orientation is defined, but has missing
* methods that cannot be properly polyfilled.
* @private
*/
static installBasedOnScreenMethods_() {
if (screen.orientation.lock === undefined) {
screen.orientation.lock = (orientation) => {
shaka.log.info('screen.orientation.lock is a no-op');
return Promise.resolve();
};
}
if (screen.orientation.unlock === undefined) {
screen.orientation.unlock = () => {
shaka.log.info('screen.orientation.unlock is a no-op');
};
}
}

/**
* Makes a polyfill for orientation, based on window methods.
* Note that some of the features this is based on are deprecated, so this
Expand Down

0 comments on commit ed93a0c

Please sign in to comment.