Improved: we can set empty for turnServer explicitly.

This commit is contained in:
vorotamoroz
2026-06-05 09:27:19 +01:00
parent 37593bbee6
commit 369e62ee8d
4 changed files with 22 additions and 13 deletions
+17 -9
View File
@@ -1,4 +1,4 @@
import { CLI_DIR } from "./cli.ts";
import { CLI_DIR, TEE_ENABLED, formatTeeCommand, createLineTeeWriter } from "./cli.ts";
import { join } from "@std/path";
const CLI_DIST = join(CLI_DIR, "dist", "index.cjs");
@@ -12,10 +12,9 @@ function decorateArgs(args: string[]): string[] {
async function pump(
stream: ReadableStream<Uint8Array>,
sink: (text: string) => void,
teeTarget: WritableStream<Uint8Array> | null
teeTarget: { write: (chunk: Uint8Array) => void; close: () => void } | null
): Promise<void> {
const reader = stream.getReader();
const writer = teeTarget?.getWriter();
const dec = new TextDecoder();
try {
while (true) {
@@ -23,12 +22,12 @@ async function pump(
if (done) break;
if (!value) continue;
sink(dec.decode(value, { stream: true }));
if (writer) {
await writer.write(value);
if (teeTarget) {
teeTarget.write(value);
}
}
} finally {
if (writer) writer.releaseLock();
if (teeTarget) teeTarget.close();
reader.releaseLock();
}
}
@@ -43,19 +42,20 @@ export class BackgroundCliProcess {
readonly child: Deno.ChildProcess,
readonly args: string[]
) {
const cliArgs = decorateArgs(args);
this.#stdoutDone = pump(
child.stdout,
(text) => {
this.#stdout += text;
},
null
TEE_ENABLED ? createLineTeeWriter(child.pid, "stdout", (chunk) => Deno.stdout.writeSync(chunk)) : null
);
this.#stderrDone = pump(
child.stderr,
(text) => {
this.#stderr += text;
},
null
TEE_ENABLED ? createLineTeeWriter(child.pid, "stderr", (chunk) => Deno.stderr.writeSync(chunk)) : null
);
}
@@ -101,12 +101,20 @@ export class BackgroundCliProcess {
}
export function startCliInBackground(...args: string[]): BackgroundCliProcess {
const cliArgs = decorateArgs(args);
const child = new Deno.Command("node", {
args: [CLI_DIST, ...decorateArgs(args)],
args: [CLI_DIST, ...cliArgs],
cwd: CLI_DIR,
stdin: "null",
stdout: "piped",
stderr: "piped",
}).spawn();
if (TEE_ENABLED) {
Deno.stdout.writeSync(
new TextEncoder().encode(`[CLI tee pid=${child.pid}] process(bg): ${formatTeeCommand(cliArgs)}\n`)
);
}
return new BackgroundCliProcess(child, args);
}
+3 -3
View File
@@ -20,7 +20,7 @@ export interface CliResult {
code: number;
}
const TEE_ENABLED = Deno.env.get("LIVESYNC_TEST_TEE") === "1";
export const TEE_ENABLED = Deno.env.get("LIVESYNC_TEST_TEE") === "1";
const VERBOSE_ENABLED = Deno.env.get("LIVESYNC_CLI_VERBOSE") === "1";
const DEBUG_ENABLED = Deno.env.get("LIVESYNC_CLI_DEBUG") === "1";
@@ -39,11 +39,11 @@ function concatChunks(chunks: Uint8Array[]): Uint8Array {
return out;
}
function formatTeeCommand(args: string[]): string {
export function formatTeeCommand(args: string[]): string {
return ["node", CLI_DIST, ...args].map((part) => JSON.stringify(part)).join(" ");
}
function createLineTeeWriter(
export function createLineTeeWriter(
pid: number,
streamName: "stdout" | "stderr",
writer: (chunk: Uint8Array) => void
@@ -184,6 +184,7 @@ export async function applyP2pSettings(
data.P2P_relays = relays;
data.P2P_AutoAcceptingPeers = autoAccept;
data.P2P_AutoDenyingPeers = "";
data.P2P_turnServers = "none";
data.P2P_IsHeadless = true;
data.isConfigured = true;
await Deno.writeTextFile(settingsFile, JSON.stringify(data, null, 2));
+1 -1
Submodule src/lib updated: 76d91674c2...808efe19c8