mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 12:02:50 +08:00
fix: preserve audio capture across device reconfiguration
This commit is contained in:
1 parent
797fc135a9
commit
0785f82386
5 files changed
+382
-45
No files matched your search
@@ -0,0 +1,22 @@
|
||||
interface AudioSink {
|
||||
setSinkId?(deviceId: string): Promise<void>;
|
||||
}
|
||||
|
||||
// Browser sink changes cannot be cancelled once started. Serialize each
|
||||
// endpoint so an older completion cannot leave it on the wrong device.
|
||||
export function createAudioSinkRouter() {
|
||||
const pending = new WeakMap<AudioSink, Promise<void>>();
|
||||
|
||||
function set(sink: AudioSink, deviceId: string, isCurrent: () => boolean): Promise<void> {
|
||||
const previous = pending.get(sink) ?? Promise.resolve();
|
||||
const task = previous.catch(() => {}).then(async () => {
|
||||
if (isCurrent()) await sink.setSinkId?.(deviceId || "default");
|
||||
});
|
||||
pending.set(sink, task);
|
||||
const cleanup = () => { if (pending.get(sink) === task) pending.delete(sink); };
|
||||
void task.then(cleanup, cleanup);
|
||||
return task;
|
||||
}
|
||||
|
||||
return { set };
|
||||
}
|
||||
Reference in new issue
Block a user