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"; import { join } from "@std/path";
const CLI_DIST = join(CLI_DIR, "dist", "index.cjs"); const CLI_DIST = join(CLI_DIR, "dist", "index.cjs");
@@ -12,10 +12,9 @@ function decorateArgs(args: string[]): string[] {
async function pump( async function pump(
stream: ReadableStream<Uint8Array>, stream: ReadableStream<Uint8Array>,
sink: (text: string) => void, sink: (text: string) => void,
teeTarget: WritableStream<Uint8Array> | null teeTarget: { write: (chunk: Uint8Array) => void; close: () => void } | null
): Promise<void> { ): Promise<void> {
const reader = stream.getReader(); const reader = stream.getReader();
const writer = teeTarget?.getWriter();
const dec = new TextDecoder(); const dec = new TextDecoder();
try { try {
while (true) { while (true) {
@@ -23,12 +22,12 @@ async function pump(
if (done) break; if (done) break;
if (!value) continue; if (!value) continue;
sink(dec.decode(value, { stream: true })); sink(dec.decode(value, { stream: true }));
if (writer) { if (teeTarget) {
await writer.write(value); teeTarget.write(value);
} }
} }
} finally { } finally {
if (writer) writer.releaseLock(); if (teeTarget) teeTarget.close();
reader.releaseLock(); reader.releaseLock();
} }
} }
@@ -43,19 +42,20 @@ export class BackgroundCliProcess {
readonly child: Deno.ChildProcess, readonly child: Deno.ChildProcess,
readonly args: string[] readonly args: string[]
) { ) {
const cliArgs = decorateArgs(args);
this.#stdoutDone = pump( this.#stdoutDone = pump(
child.stdout, child.stdout,
(text) => { (text) => {
this.#stdout += text; this.#stdout += text;
}, },
null TEE_ENABLED ? createLineTeeWriter(child.pid, "stdout", (chunk) => Deno.stdout.writeSync(chunk)) : null
); );
this.#stderrDone = pump( this.#stderrDone = pump(
child.stderr, child.stderr,
(text) => { (text) => {
this.#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 { export function startCliInBackground(...args: string[]): BackgroundCliProcess {
const cliArgs = decorateArgs(args);
const child = new Deno.Command("node", { const child = new Deno.Command("node", {
args: [CLI_DIST, ...decorateArgs(args)], args: [CLI_DIST, ...cliArgs],
cwd: CLI_DIR, cwd: CLI_DIR,
stdin: "null", stdin: "null",
stdout: "piped", stdout: "piped",
stderr: "piped", stderr: "piped",
}).spawn(); }).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); return new BackgroundCliProcess(child, args);
} }
+3 -3
View File
@@ -20,7 +20,7 @@ export interface CliResult {
code: number; 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 VERBOSE_ENABLED = Deno.env.get("LIVESYNC_CLI_VERBOSE") === "1";
const DEBUG_ENABLED = Deno.env.get("LIVESYNC_CLI_DEBUG") === "1"; const DEBUG_ENABLED = Deno.env.get("LIVESYNC_CLI_DEBUG") === "1";
@@ -39,11 +39,11 @@ function concatChunks(chunks: Uint8Array[]): Uint8Array {
return out; return out;
} }
function formatTeeCommand(args: string[]): string { export function formatTeeCommand(args: string[]): string {
return ["node", CLI_DIST, ...args].map((part) => JSON.stringify(part)).join(" "); return ["node", CLI_DIST, ...args].map((part) => JSON.stringify(part)).join(" ");
} }
function createLineTeeWriter( export function createLineTeeWriter(
pid: number, pid: number,
streamName: "stdout" | "stderr", streamName: "stdout" | "stderr",
writer: (chunk: Uint8Array) => void writer: (chunk: Uint8Array) => void
@@ -184,6 +184,7 @@ export async function applyP2pSettings(
data.P2P_relays = relays; data.P2P_relays = relays;
data.P2P_AutoAcceptingPeers = autoAccept; data.P2P_AutoAcceptingPeers = autoAccept;
data.P2P_AutoDenyingPeers = ""; data.P2P_AutoDenyingPeers = "";
data.P2P_turnServers = "none";
data.P2P_IsHeadless = true; data.P2P_IsHeadless = true;
data.isConfigured = true; data.isConfigured = true;
await Deno.writeTextFile(settingsFile, JSON.stringify(data, null, 2)); await Deno.writeTextFile(settingsFile, JSON.stringify(data, null, 2));
+1 -1
Submodule src/lib updated: 76d91674c2...808efe19c8