Skip to content

Commit

Permalink
feat(FEC-10486): Lock orientation according to screenLockOrientionMod…
Browse files Browse the repository at this point in the history
…e config when switching to full screen (#499)

add screenLockOrientionMode config to be able to lock the screen mode in fullscreen.
new enum with possible values for this config:
`"none"
"any"
"natural"
"landscape"
"portrait"
"portrait-primary"
"portrait-secondary"
"landscape-primary"
"landscape-secondary"`

Solves FEC-10486
  • Loading branch information
Yuvalke authored Nov 25, 2020
1 parent 6583361 commit 21d7227
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 7 deletions.
18 changes: 17 additions & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,8 @@ var config = {
> streamPriority: Array<PKStreamPriorityObject>,
> preferNative: PKPreferNativeConfigObject,
> inBrowserFullscreen: boolean,
> playAdsWithMSE: boolean
> playAdsWithMSE: boolean,
> screenLockOrientionMode: string
> }
> ```
>
Expand All @@ -511,6 +512,7 @@ var config = {
> muted: false,
> pictureInPicture: true,
> playAdsWithMSE: false,
> screenLockOrientionMode: ScreenOrientationType.NONE,
> options: {
> html5: {
> hls: {},
Expand Down Expand Up @@ -886,6 +888,20 @@ var config = {
>
> ##
>
> > ### config.playback.screenLockOrientionMode
> >
> > ##### Type: `string` - value list option in ScreenOrientationType
> >
> > ##### Default: `none` - ScreenOrientationType.NONE
> >
> > ```js
> > screenLockOrientionMode: string;
> > ```
> >
> > > ##### Description: Gives the ability to lock the screen orientation in fullscreen
>
> ##
>
> > ### config.playback.streamPriority
> >
> > ##### Type: `Array<PKStreamPriorityObject`
Expand Down
3 changes: 2 additions & 1 deletion flow-typed/types/playback-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ declare type PKPlaybackConfigObject = {
streamPriority: Array<PKStreamPriorityObject>,
preferNative: PKPreferNativeConfigObject,
inBrowserFullscreen: boolean,
playAdsWithMSE: boolean
playAdsWithMSE: boolean,
screenLockOrientionMode: string
};
2 changes: 2 additions & 0 deletions flow-typed/types/screen-orientation-type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// @flow
declare type PKOrientationType = {[type: string]: string};
28 changes: 26 additions & 2 deletions src/fullscreen/fullscreen-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import EventManager from '../event/event-manager';
import Player from '../player';
import FakeEvent from '../event/fake-event';
import * as Utils from '../utils/util';
import {ScreenOrientationType} from '../screen-orientation-type';

/**
* The IOS fullscreen class name.
Expand All @@ -22,6 +23,10 @@ class FullscreenController {
// Flag to indicate that player is in fullscreen(when different element on fullscreen - api return correct state).
_isInFullscreen: boolean = false;
_isInBrowserFullscreen: boolean;
_isScreenLocked: boolean = false;
_isScreenOrientationSupport: boolean =
// $FlowFixMe
!!screen && !!screen.orientation && typeof screen.orientation.unlock === 'function' && typeof screen.orientation.lock === 'function';
_eventManager: EventManager;
// Flag to overcome browsers which supports more than one fullscreenchange event
_isFullscreenEventDispatched: boolean = false;
Expand Down Expand Up @@ -164,7 +169,19 @@ class FullscreenController {
this._player.exitPictureInPicture();
}
Promise.resolve(this._nativeEnterFullScreen(fullScreenElement)).then(
() => (this._isInFullscreen = true),
() => {
this._isInFullscreen = true;
const screenLockOrientionMode = Utils.Object.getPropertyPath(this._player, 'config.playback.screenLockOrientionMode');
const validOrientation =
screenLockOrientionMode !== ScreenOrientationType.NONE && Object.values(ScreenOrientationType).includes(screenLockOrientionMode);
if (this._isScreenOrientationSupport && validOrientation) {
screen.orientation
// $FlowFixMe
.lock(screenLockOrientionMode)
.then(() => (this._isScreenLocked = true))
.catch(() => (this._isScreenLocked = false));
}
},
() => {}
);
}
Expand Down Expand Up @@ -195,7 +212,14 @@ class FullscreenController {
*/
_requestExitFullscreen(): void {
Promise.resolve(this._nativeExitFullScreen()).then(
() => (this._isInFullscreen = false),
() => {
this._isInFullscreen = false;
if (this._isScreenOrientationSupport && this._isScreenLocked) {
// $FlowFixMe
screen.orientation.unlock();
this._isScreenLocked = false;
}
},
() => {}
);
}
Expand Down
3 changes: 3 additions & 0 deletions src/player-config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {ScreenOrientationType} from './screen-orientation-type';

const DefaultConfig = {
log: {
level: 'ERROR'
Expand Down Expand Up @@ -37,6 +39,7 @@ const DefaultConfig = {
dash: false
},
inBrowserFullscreen: false,
screenLockOrientionMode: ScreenOrientationType.NONE,
playAdsWithMSE: false,
streamPriority: [
{
Expand Down
2 changes: 0 additions & 2 deletions src/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import {ResizeWatcher} from './utils/resize-watcher';
import {FullscreenController} from './fullscreen/fullscreen-controller';
import {EngineDecorator} from './engines/engine-decorator';
import {LabelOptions} from './track/label-options';

/**
* The black cover class name.
* @type {string}
Expand Down Expand Up @@ -2506,6 +2505,5 @@ export default class Player extends FakeEventTarget {
get Error(): typeof PKError {
return PKError;
}

// </editor-fold>
}
4 changes: 3 additions & 1 deletion src/playkit.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {RequestType} from './request-type';
import {AdBreakType} from './ads/ad-break-type';
import {AdTagType} from './ads/ad-tag-type';
import {AdEventType} from './ads/ad-event-type';
import {ScreenOrientationType} from './screen-orientation-type';

declare var __VERSION__: string;
declare var __NAME__: string;
Expand Down Expand Up @@ -107,7 +108,8 @@ export {
CorsType,
DrmScheme,
MimeType,
RequestType
RequestType,
ScreenOrientationType
};

// Export logger utils
Expand Down
14 changes: 14 additions & 0 deletions src/screen-orientation-type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// @flow
const ScreenOrientationType: PKOrientationType = {
NONE: 'none',
ANY: 'any',
NATURAL: 'natural',
LANDSCAPE: 'landscape',
PORTRAIT: 'portrait',
PORTRAIT_PRIMARY: 'portrait-primary',
PORTRAIT_SECONDARY: 'portrait-secondary',
LANDSCAPE_PRIMARY: 'landscape-primary',
LANDSCAPE_SECONDARY: 'landscape-secondary'
};

export {ScreenOrientationType};

0 comments on commit 21d7227

Please sign in to comment.