🎥 Make videos programmatically with React
`@remotion/studio-protocol`: Document the Studio Protocol (#9881)
Igor Samokhovets611cb9027b6c
diff --git a/packages/docs/components/TableOfContents/api.tsx b/packages/docs/components/TableOfContents/api.tsxindex ef698675d8..17920dff19 100644--- a/packages/docs/components/TableOfContents/api.tsx+++ b/packages/docs/components/TableOfContents/api.tsx@@ -33,6 +33,7 @@ import {TableOfContents as ShapesTableOfContents} from '../../docs/shapes/table-import {TableOfContents as SkiaTableOfContents} from '../../docs/skia/TableOfContents';import {TableOfContents as StarburstTableOfContents} from '../../docs/starburst/table-of-contents';import {TableOfContents as StudioTableOfContents} from '../../docs/studio/TableOfContents';+import {TableOfContents as StudioProtocolTableOfContents} from '../../docs/studio-protocol/table-of-contents';import {TableOfContents as TailwindV4TableOfContents} from '../../docs/tailwind-v4/TableOfContents';import {TableOfContents as TailwindTableOfContents} from '../../docs/tailwind/TableOfContents';import {TableOfContents as ThreeTableOfContents} from '../../docs/three/TableOfContents';@@ -168,6 +169,9 @@ export const TableOfContents: React.FC = () => {<h2>@remotion/studio</h2><p>APIs for controlling theRemotion Studio</p><StudioTableOfContents />+ <h2>@remotion/studio-protocol</h2>+ <p>Create Element payloads and send them into Remotion Studio</p>+ <StudioProtocolTableOfContents /><h2>@remotion/tailwind</h2><p>Bundler override for using TailwindCSS v3</p><TailwindTableOfContents />diff --git a/packages/docs/docs/studio-protocol/create-element-payload.mdx b/packages/docs/docs/studio-protocol/create-element-payload.mdxnew file mode 100644index 0000000000..aa536c7fa7--- /dev/null+++ b/packages/docs/docs/studio-protocol/create-element-payload.mdx@@ -0,0 +1,65 @@+---+image: /generated/articles-docs-studio-protocol-create-element-payload.png+title: 'createElementPayload()'+crumb: '@remotion/studio-protocol'+---++# createElementPayload()<AvailableFrom v="4.0.502" />++Creates a validated, versioned Element payload for [`setStudioDragData()`](/docs/studio-protocol/set-studio-drag-data) and [`installInStudio()`](/docs/studio-protocol/install-in-studio).++```ts twoslash title="element-payload.ts"+import {createElementPayload} from '@remotion/studio-protocol';++const payload = createElementPayload({+ displayName: 'Lower Third',+ slug: 'lower-third',+ sourceCode: 'export const LowerThird = () => null;',+ dependencies: ['remotion'],+ dimensions: {width: 900, height: 260},+ durationInFrames: 90,+});+```++## Arguments++Pass an object with the following properties.++### displayName++The name shown in the Studio confirmation dialog. It must be a non-empty string shorter than 120 characters.++### slug++A lowercase Element identifier. Its final path segment is used to create the `.element.tsx` filename. Directory traversal and unsafe filename characters are rejected.++### sourceCode++The complete Element source code. It must contain exactly one exported named component.++### dependencies++An array of npm package names needed by the Element. Duplicate names are removed.++### dimensions++The preferred width and height, or `null` for an Element without fixed dimensions. Both values must be positive finite numbers.++### durationInFrames++The preferred duration shown while dragging. It must be a positive integer.++## Return value++A `StudioElementPayload` with payload version `1`. Pass the returned object unchanged to a transport API instead of serializing it manually.++Invalid input throws a `TypeError`.++## Compatibility++<CompatibilityTable chrome firefox safari nodejs="" bun="" serverlessFunctions="" clientSideRendering={false} serverSideRendering={false} player={false} studio={false} hideServers />++## See also++- [`setStudioDragData()`](/docs/studio-protocol/set-studio-drag-data)+- [`installInStudio()`](/docs/studio-protocol/install-in-studio)diff --git a/packages/docs/docs/studio-protocol/index.mdx b/packages/docs/docs/studio-protocol/index.mdxnew file mode 100644index 0000000000..fbf320f692--- /dev/null+++ b/packages/docs/docs/studio-protocol/index.mdx@@ -0,0 +1,63 @@+---+image: /generated/articles-docs-studio-protocol-index.png+title: 'Remotion Studio Protocol'+crumb: '@remotion/studio-protocol'+---++# Remotion Studio Protocol<AvailableFrom v="4.0.502" />++A versioned protocol for bringing reusable content into Remotion Studio.++Protocol v1 supports [Remotion Elements](/elements) from the official Remotion Elements library. It provides one Element payload that can be delivered by dragging it into Studio or by requesting installation into the active composition.++<Installation pkg="@remotion/studio-protocol" />++## Usage++```ts twoslash title="element.ts"+import {+ createElementPayload,+ installInStudio,+} from '@remotion/studio-protocol';++const payload = createElementPayload({+ displayName: 'Lower Third',+ slug: 'lower-third',+ sourceCode: 'export const LowerThird = () => null;',+ dependencies: [],+ dimensions: {width: 900, height: 260},+ durationInFrames: 90,+});++const result = await installInStudio({payload});+if (result.success) {+ console.log(result.status); // "awaiting-confirmation"+}+```++A successful request means Studio received the Element and is awaiting confirmation. It does not mean dependencies or source files were installed.++## APIs++import {TableOfContents} from './table-of-contents';++<TableOfContents />++## Supported origins++Install requests are accepted from:++- `https://remotion.dev`+- `https://www.remotion.dev`+- HTTP `localhost`+- HTTP `127.0.0.1`++Protocol v1 is supported by the official Remotion Elements library. Other hosted websites are not currently authorized to send installation requests.++## Compatibility++Remotion Studio 4.0.502 or newer is required. Browser Studio is not supported in protocol v1.++## License++[Remotion License](/docs/license)diff --git a/packages/docs/docs/studio-protocol/install-in-studio.mdx b/packages/docs/docs/studio-protocol/install-in-studio.mdxnew file mode 100644index 0000000000..987d002704--- /dev/null+++ b/packages/docs/docs/studio-protocol/install-in-studio.mdx@@ -0,0 +1,92 @@+---+image: /generated/articles-docs-studio-protocol-install-in-studio.png+title: 'installInStudio()'+crumb: '@remotion/studio-protocol'+---++# installInStudio()<AvailableFrom v="4.0.502" />++Discovers a recently focused Remotion Studio and sends it an Element payload.++```ts twoslash title="install-element.ts"+import {+ createElementPayload,+ installInStudio,+} from '@remotion/studio-protocol';++const payload = createElementPayload({+ displayName: 'Lower Third',+ slug: 'lower-third',+ sourceCode: 'export const LowerThird = () => null;',+ dependencies: [],+ dimensions: {width: 900, height: 260},+ durationInFrames: 90,+});++const result = await installInStudio({payload});+if (!result.success) {+ console.error(result.code, result.message);+} else {+ console.log(result.status); // "awaiting-confirmation"+}+```++## Arguments++### payload++The value returned by [`createElementPayload()`](/docs/studio-protocol/create-element-payload).++## Return value++Returns a promise with a discriminated union.++### success++Indicates whether the request reached the exact selected Studio tab and composition.++### status++On success, the value is `"awaiting-confirmation"`. Studio is showing or queuing a confirmation dialog. No dependency or source-file installation is guaranteed yet.++### target++On success, contains the project name, composition ID, Studio origin, and Studio version.++### code++On failure, one of:++- `unsupported-origin`+- `no-compatible-studio`+- `studio-upgrade-required`+- `no-installable-target`+- `unsupported-protocol`+- `invalid-response`+- `target-expired`+- `request-rejected`+- `request-timed-out`+- `network-error`++### message++A human-readable failure message. Use `code` for application logic.++## Discovery++Ports 3000 through 3009 are probed in parallel. The most recently focused compatible target is selected. Discovery returns a short-lived, single-use token bound to that Studio tab and composition.++Studios older than 4.0.502 are detected and return `studio-upgrade-required`. The Element is not sent through the legacy endpoint.++## Supported origins++The function supports `https://remotion.dev`, `https://www.remotion.dev`, HTTP `localhost`, and HTTP `127.0.0.1`.++## Compatibility++<CompatibilityTable chrome firefox safari nodejs="" bun="" serverlessFunctions="" clientSideRendering={false} serverSideRendering={false} player={false} studio={false} hideServers />++## See also++- [Protocol reference](/docs/studio-protocol/protocol)+- [Security](/docs/studio-protocol/security)diff --git a/packages/docs/docs/studio-protocol/protocol.mdx b/packages/docs/docs/studio-protocol/protocol.mdxnew file mode 100644index 0000000000..418af2aac8--- /dev/null+++ b/packages/docs/docs/studio-protocol/protocol.mdx@@ -0,0 +1,116 @@+---+image: /generated/articles-docs-studio-protocol-protocol.png+title: 'Studio Protocol reference'+crumb: '@remotion/studio-protocol'+---++# Studio Protocol reference<AvailableFrom v="4.0.502" />++Protocol v1 uses stable endpoints and versioned JSON envelopes. It supports official Remotion Element payloads.++## Versions++`protocolVersion` versions discovery, targeting, requests, responses, and errors. The Element `version` independently versions the payload schema.++## Discovery++```http title="Discovery request"+GET /api/studio-protocol+```++A compatible Studio responds with:++```json title="Discovery response"+{+ "protocol": "remotion-studio-protocol",+ "protocolVersion": 1,+ "studioVersion": "4.0.502",+ "capabilities": {+ "install": [+ {+ "payloadType": "remotion-element",+ "payloadVersions": [1]+ }+ ]+ },+ "projectName": "My video",+ "installTarget": {+ "id": "opaque-target-token",+ "expiresAt": 1780000000000,+ "compositionId": "Main",+ "lastFocusedAt": 1779999999000+ }+}+```++`installTarget` is `null` when Studio is compatible but no writable, recently focused composition is available.++## Installation request++```http title="Installation request"+POST /api/studio-protocol/install+Content-Type: application/json+```++```json title="Installation request body"+{+ "protocol": "remotion-studio-protocol",+ "protocolVersion": 1,+ "targetId": "opaque-target-token",+ "payload": {+ "type": "remotion-element",+ "version": 1,+ "durationInFrames": 90,+ "element": {+ "displayName": "Lower Third",+ "slug": "lower-third",+ "sourceCode": "export const LowerThird = () => null;",+ "dependencies": [],+ "dimensions": {"width": 900, "height": 260}+ }+ }+}+```++Create this object with [`createElementPayload()`](/docs/studio-protocol/create-element-payload) instead of serializing it manually.++## Success response++```json title="Installation response"+{+ "protocol": "remotion-studio-protocol",+ "protocolVersion": 1,+ "status": "awaiting-confirmation"+}+```++The response confirms delivery, not installation completion.++## Error response++```json title="Error response"+{+ "protocol": "remotion-studio-protocol",+ "protocolVersion": 1,+ "status": "error",+ "error": {+ "code": "target-expired",+ "message": "The selected Studio target is no longer available."+ }+}+```++Invalid requests return `400`, disallowed origins return `403`, unsupported methods return `405`, and unavailable targets return `409`.++## Target tokens++A target token is opaque, short-lived, single-use, and bound to one connected Studio client and composition snapshot. The server does not select another target during installation.++## CORS++The server returns an explicit allowed origin, never `*`. Preflight responses include support for `Content-Type` and Private Network Access.++## See also++- [`installInStudio()`](/docs/studio-protocol/install-in-studio)+- [Security](/docs/studio-protocol/security)diff --git a/packages/docs/docs/studio-protocol/security.mdx b/packages/docs/docs/studio-protocol/security.mdxnew file mode 100644index 0000000000..48de348163--- /dev/null+++ b/packages/docs/docs/studio-protocol/security.mdx@@ -0,0 +1,50 @@+---+image: /generated/articles-docs-studio-protocol-security.png+title: 'Studio Protocol security'+crumb: '@remotion/studio-protocol'+---++# Studio Protocol security<AvailableFrom v="4.0.502" />++An Element contains executable React source code and may declare npm dependencies. Studio therefore requires confirmation before applying an installation request.++## Confirmation boundary++A successful [`installInStudio()`](/docs/studio-protocol/install-in-studio) result only means the request reached Studio and is awaiting confirmation.++Before confirming, review:++- The Element name+- The target composition+- The source code+- Dependencies that need to be installed++Declining the confirmation does not install the Element.++## Allowed origins++Protocol v1 accepts requests from:++- `https://remotion.dev`+- `https://www.remotion.dev`+- HTTP `localhost`+- HTTP `127.0.0.1`++Other hosted origins receive a `403` response. Wildcard CORS is not used.++Local HTTP origins are intended for development and testing. Only run local pages you trust while Studio is open.++## Target information++Discovery exposes limited metadata needed to present the destination: project name, composition ID, Studio version, focus time, and a short-lived target token. It does not expose project source code or filesystem contents.++Target tokens are opaque, single-use, short-lived, and bound to the selected Studio tab and composition.++## Third-party websites++Protocol v1 is supported by the official Remotion Elements library. Other hosted websites are not currently authorized to send installation requests. There is no third-party integration support promise in v1.++## See also++- [Protocol reference](/docs/studio-protocol/protocol)+- [Remotion security best practices](/docs/security)diff --git a/packages/docs/docs/studio-protocol/set-studio-drag-data.mdx b/packages/docs/docs/studio-protocol/set-studio-drag-data.mdxnew file mode 100644index 0000000000..62865b4cca--- /dev/null+++ b/packages/docs/docs/studio-protocol/set-studio-drag-data.mdx@@ -0,0 +1,66 @@+---+image: /generated/articles-docs-studio-protocol-set-studio-drag-data.png+title: 'setStudioDragData()'+crumb: '@remotion/studio-protocol'+---++# setStudioDragData()<AvailableFrom v="4.0.502" />++Writes an Element payload and its preview metadata to a browser `DataTransfer` object.++```tsx title="DraggableElement.tsx"+import {+ createElementPayload,+ setStudioDragData,+} from '@remotion/studio-protocol';++const payload = createElementPayload({+ displayName: 'Lower Third',+ slug: 'lower-third',+ sourceCode: 'export const LowerThird = () => null;',+ dependencies: [],+ dimensions: {width: 900, height: 260},+ durationInFrames: 90,+});++export const DraggableElement = () => (+ <button+ draggable+ onDragStart={(event) => {+ setStudioDragData({+ dataTransfer: event.dataTransfer,+ payload,+ });+ }}+ >+ Drag into Studio+ </button>+);+```++## Arguments++Pass an object with the following properties.++### dataTransfer++The `DataTransfer` from a browser `dragstart` event. `effectAllowed` is set to `copy`.++### payload++The value returned by [`createElementPayload()`](/docs/studio-protocol/create-element-payload).++## Drag preview++The protocol MIME type contains dimensions and duration metadata so Studio can show a preview before reading the payload.++`setStudioDragData()` does not call `setDragImage()`. The website owns the visual drag image.++## Compatibility++<CompatibilityTable chrome firefox safari nodejs="" bun="" serverlessFunctions="" clientSideRendering={false} serverSideRendering={false} player={false} studio={false} hideServers />++## See also++- [`createElementPayload()`](/docs/studio-protocol/create-element-payload)+- [`installInStudio()`](/docs/studio-protocol/install-in-studio)diff --git a/packages/docs/docs/studio-protocol/table-of-contents.tsx b/packages/docs/docs/studio-protocol/table-of-contents.tsxnew file mode 100644index 0000000000..1195d9288f--- /dev/null+++ b/packages/docs/docs/studio-protocol/table-of-contents.tsx@@ -0,0 +1,30 @@+import React from 'react';+import {Grid} from '../../components/TableOfContents/Grid';+import {TOCItem} from '../../components/TableOfContents/TOCItem';++export const TableOfContents: React.FC = () => {+ return (+ <Grid>+ <TOCItem link="/docs/studio-protocol/create-element-payload">+ <strong>createElementPayload()</strong>+ <div>Create a versioned Element payload</div>+ </TOCItem>+ <TOCItem link="/docs/studio-protocol/set-studio-drag-data">+ <strong>setStudioDragData()</strong>+ <div>Put an Element payload on a drag event</div>+ </TOCItem>+ <TOCItem link="/docs/studio-protocol/install-in-studio">+ <strong>installInStudio()</strong>+ <div>Request installation into the active Studio</div>+ </TOCItem>+ <TOCItem link="/docs/studio-protocol/protocol">+ <strong>Protocol reference</strong>+ <div>Wire format, capabilities, and versioning</div>+ </TOCItem>+ <TOCItem link="/docs/studio-protocol/security">+ <strong>Security</strong>+ <div>Confirmation and origin policy</div>+ </TOCItem>+ </Grid>+ );+};diff --git a/packages/docs/elements/index.mdx b/packages/docs/elements/index.mdxindex ed50bf8766..582bf40286 100644--- a/packages/docs/elements/index.mdx+++ b/packages/docs/elements/index.mdx@@ -18,6 +18,8 @@ Remotion Elements are drop-in, HTML-first Remotion components designed to be plaThey are practical video building blocks: captions, lower thirds, overlays, callouts, transitions, data cards, audio visuals, and title cards.+Remotion Elements can be sent directly from the web to your active Studio composition. The installation flow is powered by the [Remotion Studio Protocol](/docs/studio-protocol).+Browse the library to find an Element for your project.<ElementLibrary category={null} />diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.tsindex 55fdffdf53..8caf2f13aa 100644--- a/packages/docs/sidebars.ts+++ b/packages/docs/sidebars.ts@@ -785,6 +785,21 @@ const sidebars: SidebarsConfig = {'studio/visual-control',],},+ {+ type: 'category',+ label: '@remotion/studio-protocol',+ link: {+ type: 'doc',+ id: 'studio-protocol/index',+ },+ items: [+ 'studio-protocol/create-element-payload',+ 'studio-protocol/set-studio-drag-data',+ 'studio-protocol/install-in-studio',+ 'studio-protocol/protocol',+ 'studio-protocol/security',+ ],+ },{type: 'category',label: '@remotion/tailwind',diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.tsindex 4d1e7cd93f..30642d387c 100644--- a/packages/docs/src/data/articles.ts+++ b/packages/docs/src/data/articles.ts@@ -6841,6 +6841,60 @@ export const articles = [noAi: false,slug: 'studio-into-app',},+ {+ id: 'studio-protocol/create-element-payload',+ title: 'createElementPayload()',+ relativePath: 'docs/studio-protocol/create-element-payload.mdx',+ compId: 'articles-docs-studio-protocol-create-element-payload',+ crumb: '@remotion/studio-protocol',+ noAi: false,+ slug: 'studio-protocol/create-element-payload',+ },+ {+ id: 'studio-protocol/index',+ title: 'Remotion Studio Protocol',+ relativePath: 'docs/studio-protocol/index.mdx',+ compId: 'articles-docs-studio-protocol-index',+ crumb: '@remotion/studio-protocol',+ noAi: false,+ slug: 'studio-protocol/index',+ },+ {+ id: 'studio-protocol/install-in-studio',+ title: 'installInStudio()',+ relativePath: 'docs/studio-protocol/install-in-studio.mdx',+ compId: 'articles-docs-studio-protocol-install-in-studio',+ crumb: '@remotion/studio-protocol',+ noAi: false,+ slug: 'studio-protocol/install-in-studio',+ },+ {+ id: 'studio-protocol/protocol',+ title: 'Studio Protocol reference',+ relativePath: 'docs/studio-protocol/protocol.mdx',+ compId: 'articles-docs-studio-protocol-protocol',+ crumb: '@remotion/studio-protocol',+ noAi: false,+ slug: 'studio-protocol/protocol',+ },+ {+ id: 'studio-protocol/security',+ title: 'Studio Protocol security',+ relativePath: 'docs/studio-protocol/security.mdx',+ compId: 'articles-docs-studio-protocol-security',+ crumb: '@remotion/studio-protocol',+ noAi: false,+ slug: 'studio-protocol/security',+ },+ {+ id: 'studio-protocol/set-studio-drag-data',+ title: 'setStudioDragData()',+ relativePath: 'docs/studio-protocol/set-studio-drag-data.mdx',+ compId: 'articles-docs-studio-protocol-set-studio-drag-data',+ crumb: '@remotion/studio-protocol',+ noAi: false,+ slug: 'studio-protocol/set-studio-drag-data',+ },{id: 'studio/api',title: '@remotion/studio',diff --git a/packages/docs/static/generated/articles-docs-studio-protocol-create-element-payload.png b/packages/docs/static/generated/articles-docs-studio-protocol-create-element-payload.pngnew file mode 100644index 0000000000..89c73734e9Binary files /dev/null and b/packages/docs/static/generated/articles-docs-studio-protocol-create-element-payload.png differdiff --git a/packages/docs/static/generated/articles-docs-studio-protocol-index.png b/packages/docs/static/generated/articles-docs-studio-protocol-index.pngnew file mode 100644index 0000000000..7762723239Binary files /dev/null and b/packages/docs/static/generated/articles-docs-studio-protocol-index.png differdiff --git a/packages/docs/static/generated/articles-docs-studio-protocol-install-in-studio.png b/packages/docs/static/generated/articles-docs-studio-protocol-install-in-studio.pngnew file mode 100644index 0000000000..68b8633405Binary files /dev/null and b/packages/docs/static/generated/articles-docs-studio-protocol-install-in-studio.png differdiff --git a/packages/docs/static/generated/articles-docs-studio-protocol-protocol.png b/packages/docs/static/generated/articles-docs-studio-protocol-protocol.pngnew file mode 100644index 0000000000..a192443f52Binary files /dev/null and b/packages/docs/static/generated/articles-docs-studio-protocol-protocol.png differdiff --git a/packages/docs/static/generated/articles-docs-studio-protocol-security.png b/packages/docs/static/generated/articles-docs-studio-protocol-security.pngnew file mode 100644index 0000000000..65aa132673Binary files /dev/null and b/packages/docs/static/generated/articles-docs-studio-protocol-security.png differdiff --git a/packages/docs/static/generated/articles-docs-studio-protocol-set-studio-drag-data.png b/packages/docs/static/generated/articles-docs-studio-protocol-set-studio-drag-data.pngnew file mode 100644index 0000000000..a10367e419Binary files /dev/null and b/packages/docs/static/generated/articles-docs-studio-protocol-set-studio-drag-data.png differdiff --git a/packages/studio-protocol/README.md b/packages/studio-protocol/README.mdindex 6b9f61edf5..c313f5ea02 100644--- a/packages/studio-protocol/README.md+++ b/packages/studio-protocol/README.md@@ -1,6 +1,6 @@# @remotion/studio-protocol-Create Element payloads and request installation into Remotion Studio.+The Remotion Studio Protocol lets websites and component libraries provide content that can be dragged or installed into Remotion Studio.[](https://npmcharts.com/compare/@remotion/studio-protocol?minimal=true)