Skip to content

🎥 Make videos programmatically with React

Send default-props SSE events only to subscribed clients

Jonny Burgerdcf6bcccbcdd
diff --git a/packages/studio-server/src/preview-server/default-props-watchers.ts b/packages/studio-server/src/preview-server/default-props-watchers.ts
index 146cfe8c11..15b82d75ca 100644
--- a/packages/studio-server/src/preview-server/default-props-watchers.ts
+++ b/packages/studio-server/src/preview-server/default-props-watchers.ts
@@ -42,17 +42,21 @@ const ensureGlobalWatcher = (rootFile: string) => {
continue;
}
+ const clientIds = [...subscriptions[compositionId]];
computeCanUpdateDefaultProps({
compositionId,
remotionRoot: watcherConfig.remotionRoot,
entryPoint: watcherConfig.entryPoint,
}).then(({result: newResult}) => {
waitForLiveEventsListener().then((listener) => {
- listener.sendEventToClient({
- type: 'default-props-updatable-changed',
+ const event = {
+ type: 'default-props-updatable-changed' as const,
compositionId,
result: newResult,
- });
+ };
+ for (const cId of clientIds) {
+ listener.sendEventToClientId(cId, event);
+ }
});
});
}
diff --git a/packages/studio-server/src/preview-server/live-events.ts b/packages/studio-server/src/preview-server/live-events.ts
index aca2fa0b33..6b516725fe 100644
--- a/packages/studio-server/src/preview-server/live-events.ts
+++ b/packages/studio-server/src/preview-server/live-events.ts
@@ -17,6 +17,7 @@ type Client = {
export type LiveEventsServer = {
sendEventToClient: (event: EventSourceEvent) => void;
+ sendEventToClientId: (clientId: string, event: EventSourceEvent) => void;
router: (request: IncomingMessage, response: ServerResponse) => Promise<void>;
closeConnections: () => Promise<void>;
};
@@ -86,8 +87,16 @@ export const makeLiveEventsRouter = (logLevel: LogLevel): LiveEventsServer => {
});
};
+ const sendEventToClientId = (clientId: string, event: EventSourceEvent) => {
+ const client = clients.find((c) => c.id === clientId);
+ if (client) {
+ client.response.write(serializeMessage(event));
+ }
+ };
+
return {
sendEventToClient,
+ sendEventToClientId,
router,
closeConnections: () => {
return Promise.all(