🎥 Make videos programmatically with React
Studio Protocol: Deprecate contextual composition ID (#11752)
Igor Samokhovetsb41a8cd2b509
diff --git a/packages/docs/docs/studio-protocol/install-in-studio.mdx b/packages/docs/docs/studio-protocol/install-in-studio.mdxindex 85db9df13a..8ccf76b131 100644--- a/packages/docs/docs/studio-protocol/install-in-studio.mdx+++ b/packages/docs/docs/studio-protocol/install-in-studio.mdx@@ -11,10 +11,7 @@ Sends an Element payload to the containing Remotion Studio, or discovers a recen## Example```ts twoslash title="install-element.ts"-import {- createElementPayload,- installInStudio,-} from '@remotion/studio-protocol';+import {createElementPayload, installInStudio} from '@remotion/studio-protocol';const elementSourceCode = `export const MyElement = () => {@@ -45,6 +42,10 @@ An installation request provides a one-click flow and shows the requesting websiWhen [the library](/docs/studio-protocol/component-library-integration) is embedded in Studio, the containing Studio is selected. Otherwise, local Studio ports are probed and the most recently focused compatible Studio is used. Also offer drag-and-drop with [`setStudioDragData()`](/docs/studio-protocol/set-studio-drag-data) when possible so the user can choose a specific Studio tab, timeline position, and canvas position.+### Installing without a selected composition<AvailableFrom v="4.0.530" />++A writable Studio can receive installation requests without a selected composition. The confirmation dialog defaults to New composition. This works both from an embedded Element Library and from an external website.+## Arguments### payload@@ -57,7 +58,7 @@ Returns a promise with a discriminated union.### success-Indicates whether the request reached the exact selected Studio tab. The returned composition is the context for the request; the final destination is chosen in Studio.+Indicates whether the request reached the exact selected Studio tab. The installation destination is chosen in Studio.### status@@ -65,7 +66,27 @@ On success, the value is `"awaiting-confirmation"`. Studio is showing or queuing### target-On success, contains the project name, contextual composition ID, Studio origin, and Studio version.+On success, identifies the Studio that received the request.++#### projectName++The project name, or `null` if unavailable.++#### studioOrigin++The origin of the Studio that received the request.++#### studioVersion++The Remotion version running in that Studio.++#### ~~compositionId~~++:::info Deprecated+Deprecated since <AvailableFrom v="4.0.530" inline />. Use `projectName` or `studioOrigin` to identify the receiving Studio. The installation destination is chosen in Studio.+:::++Retained for compatibility. Contains the composition ID at the time of the request, or `null` when no composition is selected. It does not identify the final installation destination.### code@@ -89,7 +110,7 @@ A human-readable failure message. Use `code` for application logic.## Discovery-When called outside Studio, 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 contextual composition.+When called outside Studio, ports 3000 through 3009 are probed in parallel. The most recently focused compatible target is selected. Discovery returns a short-lived, single-use token for that Studio tab.## Supported originsdiff --git a/packages/docs/docs/studio-protocol/security.mdx b/packages/docs/docs/studio-protocol/security.mdxindex 14d1d3f321..a35fa3b29c 100644--- a/packages/docs/docs/studio-protocol/security.mdx+++ b/packages/docs/docs/studio-protocol/security.mdx@@ -31,7 +31,7 @@ Declining or closing the Element Library confirmation does not change the configDiscovery exposes limited metadata needed to present the destination: project name, composition ID when applicable, Studio version, focus time, and a short-lived target token. It does not expose project source code, config contents, or filesystem paths.-Target tokens are opaque, single-use, short-lived, and bound to the requesting origin, selected Studio tab, and operation. Element installation tokens are also bound to the composition.+Target tokens are opaque, single-use, short-lived, and bound to the requesting origin, selected Studio tab, and operation. Changing the selected composition invalidates an Element installation token.## See alsodiff --git a/packages/studio-protocol/src/install-in-studio.ts b/packages/studio-protocol/src/install-in-studio.tsindex 04dd2f4c6a..5e42f5f48a 100644--- a/packages/studio-protocol/src/install-in-studio.ts+++ b/packages/studio-protocol/src/install-in-studio.ts@@ -35,6 +35,9 @@ export type InstallInStudioResult =readonly status: 'awaiting-confirmation';readonly target: {readonly projectName: string | null;+ /**+ * @deprecated The installation destination is chosen in Studio. Use projectName or studioOrigin to identify the receiving Studio instead.+ */readonly compositionId: string | null;readonly studioOrigin: string;readonly studioVersion: string;diff --git a/packages/studio-protocol/src/studio-discovery.ts b/packages/studio-protocol/src/studio-discovery.tsindex 2c33ceef43..044d4a8479 100644--- a/packages/studio-protocol/src/studio-discovery.ts+++ b/packages/studio-protocol/src/studio-discovery.ts@@ -7,6 +7,9 @@ export type StudioProtocolTarget = {};export type StudioProtocolInstallTarget = StudioProtocolTarget & {+ /**+ * @deprecated The installation destination is chosen in Studio. Use the opaque target id to request installation instead.+ */readonly compositionId: string | null;};diff --git a/packages/studio-protocol/src/test/install-in-studio.test.ts b/packages/studio-protocol/src/test/install-in-studio.test.tsindex 614dc38a4b..d786e634ce 100644--- a/packages/studio-protocol/src/test/install-in-studio.test.ts+++ b/packages/studio-protocol/src/test/install-in-studio.test.ts@@ -17,7 +17,7 @@ const descriptor = ({projectName,targetId,}: {- readonly compositionId: string;+ readonly compositionId: string | null;readonly lastFocusedAt: number;readonly projectName: string;readonly targetId: string;@@ -57,7 +57,7 @@ const dependencies = {test('delivers the payload when a newer Studio advertises an unknown capability', async () => {const requests: Array<{url: string; options?: RequestInit}> = [];const newestStudio = descriptor({- compositionId: 'Main',+ compositionId: null,lastFocusedAt: 400_000,projectName: 'Newest project',targetId: 'newest-target',@@ -113,7 +113,7 @@ test('delivers the payload when a newer Studio advertises an unknown capability'status: 'awaiting-confirmation',target: {projectName: 'Newest project',- compositionId: 'Main',+ compositionId: null,studioOrigin: 'http://localhost:3001',studioVersion: '4.0.502',},diff --git a/packages/studio-server/src/preview-server/studio-protocol/handle-discovery.ts b/packages/studio-server/src/preview-server/studio-protocol/handle-discovery.tsindex 05e54ce9cd..6963ebdbc0 100644--- a/packages/studio-server/src/preview-server/studio-protocol/handle-discovery.ts+++ b/packages/studio-server/src/preview-server/studio-protocol/handle-discovery.ts@@ -3,7 +3,6 @@ import path from 'node:path';import type {GitSource} from '@remotion/studio-shared';import {getProjectName} from '@remotion/studio-shared';import {VERSION} from 'remotion/version';-import type {ElementInstallTarget} from '../element-install-state';import {ELEMENT_INSTALL_TARGET_MAX_AGE,getElementInstallTarget,@@ -46,12 +45,6 @@ const getLiveStudioTarget = (requestId: string) => {return target;};-const isElementRequestTarget = (- target: ElementInstallTarget | null,-): target is ElementInstallTarget & {- readonly lastFocusedAt: number;-} => target !== null && target.lastFocusedAt !== null;-const getProject = ({gitSource,remotionRoot,@@ -105,7 +98,7 @@ export const handleStudioProtocolDiscovery = ({setTimeout(() => {const now = Date.now();const target = getLiveStudioTarget(requestId);- const installTarget = isElementRequestTarget(target) ? target : null;+ const installTarget = target;const issuedInstallTarget =installTarget === null? nulldiff --git a/packages/studio-server/src/test/studio-protocol-routes.test.ts b/packages/studio-server/src/test/studio-protocol-routes.test.tsindex 6e574a3554..0fffb638a0 100644--- a/packages/studio-server/src/test/studio-protocol-routes.test.ts+++ b/packages/studio-server/src/test/studio-protocol-routes.test.ts@@ -103,7 +103,7 @@ const sendUnfinishedOversizedInstallRequest = (});};-test('discovers an exact Studio target and delivers one install request over HTTP', async () => {+test('discovers a focused Studio without a composition and delivers one install request over HTTP', async () => {clearElementInstallStateForTests();const deliveredEvents: EventSourceEvent[] = [];const liveEventsServer: LiveEventsServer = {@@ -118,11 +118,11 @@ test('discovers an exact Studio target and delivers one install request over HTTupdateElementInstallTarget({requestId: event.requestId,clientId: 'focused-studio-tab',- compositionFile: '/tmp/protocol-project/src/Composition.tsx',- compositionId: 'Main',+ compositionFile: null,+ compositionId: null,lastFocusedAt: Date.now() - 10 * 60 * 1000,readOnly: false,- studioUrl: 'http://localhost:3000/Main',+ studioUrl: 'http://localhost:3000',});},sendEventToClientId: (clientId, event) => {@@ -203,13 +203,13 @@ test('discovers an exact Studio target and delivers one install request over HTTtype: 'install-element';target: {id: string;- compositionId: string;+ compositionId: string | null;};},];};const installTarget = descriptor.capabilities[0].target;- expect(installTarget.compositionId).toBe('Main');+ expect(installTarget.compositionId).toBe(null);const installBody = {operation: 'install-element',@@ -314,8 +314,8 @@ test('discovers an exact Studio target and delivers one install request over HTTtype: 'element-install-request',request: {clientId: 'focused-studio-tab',- compositionFile: '/tmp/protocol-project/src/Composition.tsx',- compositionId: 'Main',+ compositionFile: null,+ compositionId: null,element: {displayName: 'Lower Third'},source: {type: 'studio-protocol',