Skip to content

Commit

Permalink
Fix issue where audio context is closed twice on FF (#412)
Browse files Browse the repository at this point in the history
  • Loading branch information
glharper authored and BrianMouncer committed Aug 4, 2021
1 parent c06200e commit 7cf1726
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/common.browser/MicAudioSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export class MicAudioSource implements IAudioSource {

private privOutputChunkSize: number;

private privIsClosing: boolean;

public constructor(
private readonly privRecorder: IRecorder,
private readonly deviceId?: string,
Expand All @@ -72,6 +74,7 @@ export class MicAudioSource implements IAudioSource {
this.privId = audioSourceId ? audioSourceId : createNoDashGuid();
this.privEvents = new EventSource<AudioSourceEvent>();
this.privMediaStream = mediaStream || null;
this.privIsClosing = false;
}

public get format(): Promise<AudioStreamFormatImpl> {
Expand Down Expand Up @@ -327,8 +330,13 @@ export class MicAudioSource implements IAudioSource {
}

if (hasClose) {
await this.privContext.close();
this.privContext = null;
if (!this.privIsClosing) {
// The audio context close may take enough time that the close is called twice
this.privIsClosing = true;
await this.privContext.close();
this.privContext = null;
this.privIsClosing = false;
}
} else if (null !== this.privContext && this.privContext.state === "running") {
// Suspend actually takes a callback, but analogous to the
// resume method, it'll be only fired if suspend is called
Expand Down

0 comments on commit 7cf1726

Please sign in to comment.