refactor: Migrate screen sharing media handling from direct WebRTC to Mediasoup.

This commit is contained in:
2026-02-23 16:48:05 +01:00
parent ff013b206a
commit 0f250d5c2a
19 changed files with 1925 additions and 574 deletions

View File

@@ -254,6 +254,55 @@ class PipewireHelper {
return false;
}
}
// Monitor PipeWire graph for changes (new/removed audio streams)
// Calls `onChange` whenever a relevant change is detected (debounced)
static _monitorProcess = null;
static _debounceTimer = null;
static startMonitoring(onChange) {
if (this._monitorProcess) return; // already monitoring
const { spawn } = require('child_process');
// pw-mon outputs a line for every PipeWire graph event (node added, removed, etc.)
const proc = spawn('pw-mon', ['--color=never'], {
stdio: ['ignore', 'pipe', 'ignore']
});
this._monitorProcess = proc;
proc.stdout.on('data', (data) => {
const text = data.toString();
// Only react to node add/remove events that are likely audio-related
if (text.includes('added') || text.includes('removed')) {
// Debounce: multiple events fire in quick succession when an app starts/stops
clearTimeout(this._debounceTimer);
this._debounceTimer = setTimeout(() => {
onChange();
}, 500);
}
});
proc.on('error', (err) => {
console.error('pw-mon failed to start:', err.message);
this._monitorProcess = null;
});
proc.on('exit', () => {
this._monitorProcess = null;
});
console.log('Started PipeWire graph monitoring (pw-mon)');
}
static stopMonitoring() {
if (this._monitorProcess) {
this._monitorProcess.kill();
this._monitorProcess = null;
}
clearTimeout(this._debounceTimer);
this._debounceTimer = null;
console.log('Stopped PipeWire graph monitoring');
}
}
module.exports = PipewireHelper;