"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.removeCompletedClientRender = exports.addCompletedClientRender = exports.getCompletedClientRenders = void 0; const file_watcher_1 = require("./file-watcher"); const resolve_output_path_1 = require("./helpers/resolve-output-path"); const live_events_1 = require("./preview-server/live-events"); let completedClientRenders = []; const cleanupFns = new Map(); const notifyClientsOfUpdate = () => { (0, live_events_1.waitForLiveEventsListener)().then((listener) => { listener.sendEventToClient({ type: 'client-renders-updated', renders: (0, exports.getCompletedClientRenders)(), }); }); }; const getCompletedClientRenders = () => { return completedClientRenders; }; exports.getCompletedClientRenders = getCompletedClientRenders; const addCompletedClientRender = ({ render, remotionRoot, }) => { if (completedClientRenders.some((r) => r.id === render.id)) { return; } completedClientRenders.push(render); const filePath = (0, resolve_output_path_1.resolveOutputPath)(remotionRoot, render.outName); const { unwatch } = (0, file_watcher_1.installFileWatcher)({ file: filePath, onChange: (type) => { if (type === 'created' || type === 'deleted') { updateCompletedClientRender(render.id, { deletedOutputLocation: type === 'deleted', }); } }, }); cleanupFns.set(render.id, unwatch); notifyClientsOfUpdate(); }; exports.addCompletedClientRender = addCompletedClientRender; const removeCompletedClientRender = (id) => { const cleanup = cleanupFns.get(id); if (cleanup) { cleanup(); cleanupFns.delete(id); } completedClientRenders = completedClientRenders.filter((r) => r.id !== id); notifyClientsOfUpdate(); }; exports.removeCompletedClientRender = removeCompletedClientRender; const updateCompletedClientRender = (id, updates) => { completedClientRenders = completedClientRenders.map((r) => { if (r.id === id) { return { ...r, ...updates }; } return r; }); notifyClientsOfUpdate(); };