Spaces:
Running
Running
Commit ·
791ae61
1
Parent(s): fcebca2
Fix to child presse
Browse files- proxy-renderer.js +10 -10
proxy-renderer.js
CHANGED
|
@@ -49,7 +49,7 @@ export const renderProxy = async (outFile, options) => {
|
|
| 49 |
Script,
|
| 50 |
} = GenerateScript(ScriptInput)
|
| 51 |
const composition = ScriptInput?.meta?.renderComposition;
|
| 52 |
-
return new Promise((resolve, reject) => {
|
| 53 |
const renderOptions = {
|
| 54 |
compositionId: composition,
|
| 55 |
startFrame: options?.startFrame ?? 0,
|
|
@@ -108,16 +108,16 @@ export const renderProxy = async (outFile, options) => {
|
|
| 108 |
|
| 109 |
let settled = false;
|
| 110 |
|
| 111 |
-
const cleanupHandlers = () => {
|
| 112 |
try {
|
| 113 |
if (proc && proc.stdout && stdoutHandler) proc.stdout.removeListener('data', stdoutHandler);
|
| 114 |
} catch (e) { }
|
| 115 |
try {
|
| 116 |
if (proc && proc.stderr && stderrHandler) proc.stderr.removeListener('data', stderrHandler);
|
| 117 |
} catch (e) { }
|
| 118 |
-
};
|
| 119 |
|
| 120 |
-
const stdoutHandler = (chunk) => {
|
| 121 |
const data = String(chunk);
|
| 122 |
console.log(data);
|
| 123 |
if (data.includes('Cleanup: Closing browser instance')) {
|
|
@@ -126,9 +126,9 @@ export const renderProxy = async (outFile, options) => {
|
|
| 126 |
cleanupHandlers();
|
| 127 |
resolve(outFile);
|
| 128 |
}
|
| 129 |
-
};
|
| 130 |
|
| 131 |
-
const stderrHandler = (chunk) => {
|
| 132 |
const data = String(chunk);
|
| 133 |
console.error(data);
|
| 134 |
if (data.includes('Failed to render')) {
|
|
@@ -137,21 +137,21 @@ export const renderProxy = async (outFile, options) => {
|
|
| 137 |
cleanupHandlers();
|
| 138 |
reject(new Error(data));
|
| 139 |
}
|
| 140 |
-
};
|
| 141 |
|
| 142 |
if (proc && proc.stdout) proc.stdout.on('data', stdoutHandler);
|
| 143 |
if (proc && proc.stderr) proc.stderr.on('data', stderrHandler);
|
| 144 |
|
| 145 |
// safety: if proc exits before we resolve, clean up and let the caller retry
|
| 146 |
-
const onProcClose = () => {
|
| 147 |
if (settled) return;
|
| 148 |
settled = true;
|
| 149 |
cleanupHandlers();
|
| 150 |
reject(new Error('Preview process exited before render finished'));
|
| 151 |
-
};
|
| 152 |
|
| 153 |
proc.once('close', onProcClose);
|
| 154 |
|
| 155 |
}).catch(reject)
|
| 156 |
-
})
|
| 157 |
}
|
|
|
|
| 49 |
Script,
|
| 50 |
} = GenerateScript(ScriptInput)
|
| 51 |
const composition = ScriptInput?.meta?.renderComposition;
|
| 52 |
+
return new Promise(((resolve, reject) => {
|
| 53 |
const renderOptions = {
|
| 54 |
compositionId: composition,
|
| 55 |
startFrame: options?.startFrame ?? 0,
|
|
|
|
| 108 |
|
| 109 |
let settled = false;
|
| 110 |
|
| 111 |
+
const cleanupHandlers = (() => {
|
| 112 |
try {
|
| 113 |
if (proc && proc.stdout && stdoutHandler) proc.stdout.removeListener('data', stdoutHandler);
|
| 114 |
} catch (e) { }
|
| 115 |
try {
|
| 116 |
if (proc && proc.stderr && stderrHandler) proc.stderr.removeListener('data', stderrHandler);
|
| 117 |
} catch (e) { }
|
| 118 |
+
}).bind(this);
|
| 119 |
|
| 120 |
+
const stdoutHandler = ((chunk) => {
|
| 121 |
const data = String(chunk);
|
| 122 |
console.log(data);
|
| 123 |
if (data.includes('Cleanup: Closing browser instance')) {
|
|
|
|
| 126 |
cleanupHandlers();
|
| 127 |
resolve(outFile);
|
| 128 |
}
|
| 129 |
+
}).bind(this);
|
| 130 |
|
| 131 |
+
const stderrHandler = ((chunk) => {
|
| 132 |
const data = String(chunk);
|
| 133 |
console.error(data);
|
| 134 |
if (data.includes('Failed to render')) {
|
|
|
|
| 137 |
cleanupHandlers();
|
| 138 |
reject(new Error(data));
|
| 139 |
}
|
| 140 |
+
}).bind(this);
|
| 141 |
|
| 142 |
if (proc && proc.stdout) proc.stdout.on('data', stdoutHandler);
|
| 143 |
if (proc && proc.stderr) proc.stderr.on('data', stderrHandler);
|
| 144 |
|
| 145 |
// safety: if proc exits before we resolve, clean up and let the caller retry
|
| 146 |
+
const onProcClose = (() => {
|
| 147 |
if (settled) return;
|
| 148 |
settled = true;
|
| 149 |
cleanupHandlers();
|
| 150 |
reject(new Error('Preview process exited before render finished'));
|
| 151 |
+
}).bind(this);
|
| 152 |
|
| 153 |
proc.once('close', onProcClose);
|
| 154 |
|
| 155 |
}).catch(reject)
|
| 156 |
+
}).bind(this))
|
| 157 |
}
|