Skip to content

🎥 Make videos programmatically with React

Wait for local network permission during Studio discovery

Igor Samokhovets784e9b08f07e
diff --git a/packages/studio-protocol/src/studio-discovery.ts b/packages/studio-protocol/src/studio-discovery.ts
index a0f2cb372d..ed3a01f69c 100644
--- a/packages/studio-protocol/src/studio-discovery.ts
+++ b/packages/studio-protocol/src/studio-discovery.ts
@@ -211,10 +211,8 @@ export const discoverStudios = async (
const origin = `http://localhost:${port}`;
let response: Response;
try {
- response = await fetchWithTimeout({
- fetchFn: dependencies.fetchFn,
- options: {cache: 'no-store'},
- url: `${origin}/api/studio-protocol`,
+ response = await dependencies.fetchFn(`${origin}/api/studio-protocol`, {
+ cache: 'no-store',
});
} catch {
return null;
diff --git a/packages/studio-protocol/src/test/install-in-studio.test.ts b/packages/studio-protocol/src/test/install-in-studio.test.ts
index c8b53a5902..3a29e10002 100644
--- a/packages/studio-protocol/src/test/install-in-studio.test.ts
+++ b/packages/studio-protocol/src/test/install-in-studio.test.ts
@@ -186,6 +186,65 @@ test('returns an actionable result when no Studio is running', async () => {
});
});
+test('waits for Studio discovery while local network permission is pending', async () => {
+ const fetchFn = (input: string | URL | Request, options?: RequestInit) => {
+ const url = String(input);
+ if (url === 'http://localhost:3000/api/studio-protocol') {
+ return new Promise<Response>((resolve, reject) => {
+ const timeout = setTimeout(() => {
+ resolve(
+ jsonResponse(
+ descriptor({
+ compositionId: 'Main',
+ lastFocusedAt: 950_000,
+ projectName: 'Project',
+ targetId: 'target',
+ }),
+ ),
+ );
+ }, 2100);
+ options?.signal?.addEventListener(
+ 'abort',
+ () => {
+ clearTimeout(timeout);
+ reject(options.signal?.reason);
+ },
+ {once: true},
+ );
+ });
+ }
+
+ if (url === 'http://localhost:3000/api/studio-protocol/install') {
+ return Promise.resolve(
+ jsonResponse({
+ protocol: 'remotion-studio-protocol',
+ protocolVersion: 1,
+ status: 'awaiting-confirmation',
+ }),
+ );
+ }
+
+ return Promise.resolve(new Response(null, {status: 404}));
+ };
+
+ expect(
+ await installInStudioWithDependencies(elementPayload, {
+ ...dependencies,
+ ports: [3000],
+ fetchFn,
+ }),
+ ).toEqual({
+ success: true,
+ status: 'awaiting-confirmation',
+ target: {
+ projectName: 'Project',
+ compositionId: 'Main',
+ studioOrigin: 'http://localhost:3000',
+ studioVersion: '4.0.502',
+ },
+ });
+});
+
test('reports malformed discovery JSON as an invalid response', async () => {
const fetchFn = (input: string | URL | Request) => {
if (String(input) === 'http://localhost:3000/api/studio-protocol') {