mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 20:12:52 +08:00
fix: consolidate audited dev updates
This commit is contained in:
1 parent
568b8fd8be
commit
0a552f7ee8
58 files changed
+1930
-132
No files matched your search
@@ -0,0 +1,20 @@
|
||||
/** Start microphone permission synchronously before resuming a suspended context. */
|
||||
export function requestMediaBeforeAudioResume<T>(
|
||||
requestMedia: () => Promise<T>,
|
||||
resumeAudio: () => Promise<unknown>,
|
||||
): Promise<T> {
|
||||
let mediaRequest: Promise<T>;
|
||||
try {
|
||||
// Keep this call synchronous with the user action so browsers can show
|
||||
// their permission prompt before AudioContext.resume() waits on activation.
|
||||
mediaRequest = requestMedia();
|
||||
} catch (error) {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
try {
|
||||
void Promise.resolve(resumeAudio()).catch(() => undefined);
|
||||
} catch {
|
||||
// Audio playback can resume on the next user gesture.
|
||||
}
|
||||
return mediaRequest;
|
||||
}
|
||||
Reference in new issue
Block a user