Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

fix: Vimeo and youtube inline option fix (#5017)

Oleg Isonen014ef95e3e79
diff --git a/packages/sdk-components-react/src/vimeo.tsx b/packages/sdk-components-react/src/vimeo.tsx
index 694ae0b55a..161c043eda 100644
--- a/packages/sdk-components-react/src/vimeo.tsx
+++ b/packages/sdk-components-react/src/vimeo.tsx
@@ -14,6 +14,7 @@ import {
useContext,
createContext,
type ContextType,
+ useRef,
} from "react";
import { ReactSdkContext } from "@webstudio-is/react-sdk/runtime";
@@ -246,11 +247,20 @@ const EmptyState = () => {
);
};
+export const requestFullscreen = (element: HTMLIFrameElement) => {
+ const isTouchDevice = "ontouchstart" in window;
+ // Allows it to work on small screens on desktop too and makes it easy to test.
+ const isMobileResolution = window.matchMedia("(max-width: 1024px)").matches;
+ if (isMobileResolution || isTouchDevice) {
+ element.requestFullscreen();
+ }
+};
+
type PlayerStatus = "initial" | "loading" | "ready";
type PlayerProps = Pick<
VimeoOptions,
- "loading" | "autoplay" | "showPreview"
+ "loading" | "autoplay" | "showPreview" | "playsinline"
> & {
videoUrl: string;
title: string | undefined;
@@ -270,10 +280,12 @@ const Player = ({
autoplay,
renderer,
showPreview,
+ playsinline,
onStatusChange,
onPreviewImageUrlChange,
}: PlayerProps) => {
const [opacity, setOpacity] = useState(0);
+ const ref = useRef<HTMLIFrameElement>(null);
useEffect(() => {
if (autoplay && renderer !== "canvas" && status === "initial") {
@@ -312,6 +324,7 @@ const Player = ({
return (
<iframe
+ ref={ref}
title={title}
src={videoUrl}
loading={loading}
@@ -328,6 +341,9 @@ const Player = ({
onLoad={() => {
onStatusChange("ready");
setOpacity(1);
+ if (ref.current && !playsinline && !autoplay) {
+ requestFullscreen(ref.current);
+ }
}}
/>
);
@@ -369,7 +385,7 @@ export const Vimeo = forwardRef<Ref, Props>(
loop = false,
muted = false,
pip = false,
- playsinline = true,
+ playsinline = false,
showPortrait = true,
quality = "auto",
responsive = true,
@@ -440,6 +456,7 @@ export const Vimeo = forwardRef<Ref, Props>(
<Player
title={rest.title}
autoplay={autoplay}
+ playsinline={playsinline}
videoUrl={videoUrl}
previewImageUrl={previewImageUrl}
loading={loading}
diff --git a/packages/sdk-components-react/src/vimeo.ws.ts b/packages/sdk-components-react/src/vimeo.ws.ts
index 72cec187b7..9d05047c57 100644
--- a/packages/sdk-components-react/src/vimeo.ws.ts
+++ b/packages/sdk-components-react/src/vimeo.ws.ts
@@ -42,6 +42,7 @@ const initialProps: Array<keyof ComponentProps<typeof Vimeo>> = [
"showTitle",
"showControls",
"controlsColor",
+ "playsinline",
];
export const propsMeta: WsComponentPropsMeta = {
diff --git a/packages/sdk-components-react/src/youtube.tsx b/packages/sdk-components-react/src/youtube.tsx
index e8fc6119a1..7530462715 100644
--- a/packages/sdk-components-react/src/youtube.tsx
+++ b/packages/sdk-components-react/src/youtube.tsx
@@ -6,9 +6,10 @@ import {
type ComponentProps,
useContext,
type ContextType,
+ useRef,
} from "react";
import { ReactSdkContext } from "@webstudio-is/react-sdk/runtime";
-import { VimeoContext } from "./vimeo";
+import { VimeoContext, requestFullscreen } from "./vimeo";
/**
* Options for configuring the YouTube player parameters.
@@ -362,7 +363,7 @@ const EmptyState = () => {
type PlayerProps = Pick<
YouTubePlayerOptions,
- "loading" | "autoplay" | "showPreview"
+ "loading" | "autoplay" | "showPreview" | "inline"
> & {
videoUrl: string;
title: string | undefined;
@@ -380,12 +381,14 @@ const Player = ({
videoUrl,
previewImageUrl,
autoplay,
+ inline,
renderer,
showPreview,
onStatusChange,
onPreviewImageUrlChange,
}: PlayerProps) => {
const [opacity, setOpacity] = useState(0);
+ const ref = useRef<HTMLIFrameElement>(null);
useEffect(() => {
if (autoplay && renderer !== "canvas" && status === "initial") {
@@ -417,6 +420,7 @@ const Player = ({
return (
<iframe
+ ref={ref}
title={title}
src={videoUrl}
loading={loading}
@@ -433,6 +437,9 @@ const Player = ({
onLoad={() => {
onStatusChange("ready");
setOpacity(1);
+ if (!inline && !autoplay && ref.current) {
+ requestFullscreen(ref.current);
+ }
}}
/>
);
@@ -463,6 +470,7 @@ export const YouTube = forwardRef<Ref, Props>(
showPreview,
children,
privacyEnhancedMode,
+ inline = false,
...rest
},
ref
@@ -478,6 +486,7 @@ export const YouTube = forwardRef<Ref, Props>(
const videoUrl = getVideoUrl(
{
...rest,
+ inline,
url,
autoplay: true,
},
@@ -508,6 +517,7 @@ export const YouTube = forwardRef<Ref, Props>(
videoUrl={videoUrl}
previewImageUrl={previewImageUrl}
loading={loading}
+ inline={inline}
showPreview={showPreview}
renderer={renderer}
status={status}