Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(FEC-10486): Lock orientation according to screenLockOrientionMode config when switching to full screen #499

Merged
merged 17 commits into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: '',
Yuvalke marked this conversation as resolved.
Show resolved Hide resolved
> options: {
> html5: {
> hls: {},
Expand Down Expand Up @@ -886,6 +888,20 @@ var config = {
>
> ##
>
> > ### config.playback.screenLockOrientionMode
> >
> > ##### Type: `string` - value list option in ScreenOrientationType
> >
> > ##### Default: ``
Yuvalke marked this conversation as resolved.
Show resolved Hide resolved
> >
> > ```js
> > screenLockOrientionMode: string;
> > ```
> >
> > > ##### Description: Gives the ability to lock the screen on fullscreen
Yuvalke marked this conversation as resolved.
Show resolved Hide resolved
>
> ##
>
> > ### 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 @@ -2505,6 +2504,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};