Skip to content

Commit

Permalink
web: Support fullScreenAspectRatio (part of #4258)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhjacobs committed Dec 28, 2024
1 parent 333cebe commit 4c317ab
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
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

0 comments on commit 4c317ab

Please sign in to comment.