| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- import { spawn } from "node:child_process";
- import { fileURLToPath } from "node:url";
- import { dirname, join } from "node:path";
- import { createJpegFramer } from "./jpeg-framer.mjs";
- const __dirname = dirname(fileURLToPath(import.meta.url));
- const SCRIPT = join(__dirname, "wayland-capture-bridge.py");
- /**
- * Portal + GStreamer in Python (OpenPipeWireRemote works with dbus-python).
- * Emits the same JPEG stream as startGstreamer on stdout.
- */
- export function startPythonWaylandBridge(opts) {
- const { fps, quality, onFrame, onSpawnError, onExit } = opts;
- const child = spawn("python3", [SCRIPT, "--fps", String(fps), "--quality", String(quality)], {
- stdio: ["ignore", "pipe", "pipe"],
- });
- if (!child.stdout) {
- onSpawnError?.(new Error("python bridge: no stdout"));
- return { child: null, stop: () => {} };
- }
- const framer = createJpegFramer(onFrame);
- child.stdout.on("data", (chunk) => framer.push(chunk));
- child.stderr?.on("data", (d) => {
- process.stderr.write(d);
- });
- child.on("error", (err) => onSpawnError?.(err));
- child.on("exit", (code, signal) => onExit?.(code, signal));
- function stop() {
- child.kill("SIGTERM");
- }
- return { child, stop };
- }
|