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

web: Support fullScreenAspectRatio (part of #4258) #19080

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
20 changes: 20 additions & 0 deletions web/packages/core/src/internal/player/inner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ declare global {
interface AudioSession {
type?: string;
}
// See https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/1615
type OrientationLockType = "any" | "landscape" | "landscape-primary" | "landscape-secondary" | "natural" | "portrait" | "portrait-primary" | "portrait-secondary";
interface ScreenOrientation extends EventTarget {
lock(orientation: OrientationLockType): Promise<void>;
}
}

/**
Expand Down Expand Up @@ -1005,6 +1010,17 @@ export class InnerPlayer {
* Called when entering / leaving fullscreen.
*/
private fullScreenChange(): void {
// If fullScreenAspectRatio is specified, lock orientation in fullscreen mode if supported
if (this.isFullscreen) {
const fullScreenAspectRatio = this.loadedConfig?.fullScreenAspectRatio?.toLowerCase() ?? "";
if (fullScreenAspectRatio === "portrait" || fullScreenAspectRatio === "landscape") {
screen.orientation.lock(fullScreenAspectRatio).catch(() => {});
}
} else {
try {
screen.orientation.unlock();
} catch { }
}
this.instance?.set_fullscreen(this.isFullscreen);
}

Expand Down Expand Up @@ -2088,6 +2104,10 @@ export function getPolyfillOptions(
if (wmode !== null) {
options.wmode = wmode as WindowMode;
}
const fullScreenAspectRatio = getOptionString("fullScreenAspectRatio");
if (fullScreenAspectRatio !== null) {
options.fullScreenAspectRatio = fullScreenAspectRatio;
}

return options;
}
Expand Down
1 change: 1 addition & 0 deletions web/packages/core/src/public/config/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const DEFAULT_CONFIG: Required<BaseLoadOptions> = {
menu: true,
allowFullscreen: false,
salign: "",
fullScreenAspectRatio: "",
forceAlign: false,
quality: "high",
scale: "showAll",
Expand Down
7 changes: 7 additions & 0 deletions web/packages/core/src/public/config/load-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,13 @@ export interface BaseLoadOptions {
*/
salign?: string;

/**
* Controls orientation on mobile in fullscreen mode.
*
* @default ""
*/
fullScreenAspectRatio?: string;

/**
* If set to true, movies are prevented from changing the stage alignment.
*
Expand Down