MCPcopy Index your code
hub / github.com/Acode-Foundation/Acode / spawnStream

Method spawnStream

src/plugins/terminal/www/Executor.js:23–37  ·  view source on GitHub ↗

* Spawns a process and exposes it as a raw WebSocket stream. * * @param {string[]} cmd - Command and arguments to execute (e.g. `["sh", "-c", "echo hi"]`). * @param {(ws: WebSocket) => void} callback - Called with the connected WebSocket once the * process is ready. Use `ws.send()` to

(cmd, callback, onError)

Source from the content-addressed store, hash-verified

21 * process is ready. Use `ws.send()` to write to stdin and `ws.onmessage` to read stdout.
22 */
23 spawnStream(cmd, callback, onError) {
24 exec((port) => {
25 const ws = new WebSocket(`ws://127.0.0.1:${port}`);
26 ws.binaryType = "arraybuffer";
27
28 ws.onopen = () => {
29 callback(ws);
30 };
31
32 ws.onerror = (e) => {
33 if (onError) onError(e);
34 };
35
36 }, (err) => { if (onError) onError(err); }, "Executor", "spawn", [cmd]);
37 }
38
39
40 /**

Callers

nothing calls this directly

Calls 3

execFunction · 0.50
callbackFunction · 0.50
onErrorFunction · 0.50

Tested by

no test coverage detected