Skip to content

Commit 71da717

Browse files
committed
web: Support fullScreenAspectRatio (part of #4258)
1 parent 8bb90c0 commit 71da717

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

web/packages/core/src/internal/player/inner.tsx

+20
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ declare global {
5454
interface AudioSession {
5555
type?: string;
5656
}
57+
// See https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/1615
58+
type OrientationLockType = "any" | "landscape" | "landscape-primary" | "landscape-secondary" | "natural" | "portrait" | "portrait-primary" | "portrait-secondary";
59+
interface ScreenOrientation extends EventTarget {
60+
lock(orientation: OrientationLockType): Promise<void>;
61+
}
5762
}
5863

5964
/**
@@ -1005,6 +1010,17 @@ export class InnerPlayer {
10051010
* Called when entering / leaving fullscreen.
10061011
*/
10071012
private fullScreenChange(): void {
1013+
// If fullScreenAspectRatio is specified, lock orientation in fullscreen mode if supported
1014+
if (this.isFullscreen) {
1015+
const fullScreenAspectRatio = this.loadedConfig?.fullScreenAspectRatio?.toLowerCase() ?? "";
1016+
if (fullScreenAspectRatio === "portrait" || fullScreenAspectRatio === "landscape") {
1017+
screen.orientation.lock(fullScreenAspectRatio).catch(() => {});
1018+
}
1019+
} else {
1020+
try {
1021+
screen.orientation.unlock();
1022+
} catch { }
1023+
}
10081024
this.instance?.set_fullscreen(this.isFullscreen);
10091025
}
10101026

@@ -2088,6 +2104,10 @@ export function getPolyfillOptions(
20882104
if (wmode !== null) {
20892105
options.wmode = wmode as WindowMode;
20902106
}
2107+
const fullScreenAspectRatio = getOptionString("fullScreenAspectRatio");
2108+
if (fullScreenAspectRatio !== null) {
2109+
options.fullScreenAspectRatio = fullScreenAspectRatio;
2110+
}
20912111

20922112
return options;
20932113
}

web/packages/core/src/public/config/default.ts

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export const DEFAULT_CONFIG: Required<BaseLoadOptions> = {
3333
menu: true,
3434
allowFullscreen: false,
3535
salign: "",
36+
fullScreenAspectRatio: "",
3637
forceAlign: false,
3738
quality: "high",
3839
scale: "showAll",

web/packages/core/src/public/config/load-options.ts

+7
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,13 @@ export interface BaseLoadOptions {
492492
*/
493493
salign?: string;
494494

495+
/**
496+
* Controls orientation on mobile in fullscreen mode.
497+
*
498+
* @default ""
499+
*/
500+
fullScreenAspectRatio?: string;
501+
495502
/**
496503
* If set to true, movies are prevented from changing the stage alignment.
497504
*

0 commit comments

Comments
 (0)