refactor: Migrate screen sharing media handling from direct WebRTC to Mediasoup.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user