Fixing setInterval not freed for some volume analyzers
Also: using a 256 fftSize instead of 2048 to save on CPU cycles.
This commit is contained in:
parent
53b184e82b
commit
37e824c494
@ -57,8 +57,8 @@ export class SoundMeter {
|
||||
this.context = context;
|
||||
this.analyser = this.context.createAnalyser();
|
||||
|
||||
this.analyser.fftSize = 2048;
|
||||
const bufferLength = this.analyser.fftSize;
|
||||
this.analyser.fftSize = 256;
|
||||
const bufferLength = this.analyser.frequencyBinCount;
|
||||
this.dataArray = new Uint8Array(bufferLength);
|
||||
}
|
||||
|
||||
|
@ -545,8 +545,12 @@ export const obtainedMediaConstraintStore = derived<Readable<MediaStreamConstrai
|
||||
|
||||
export const localVolumeStore = readable<number | undefined>(undefined, (set) => {
|
||||
let timeout: ReturnType<typeof setTimeout>;
|
||||
let soundMeter: SoundMeter;
|
||||
const unsubscribe = localStreamStore.subscribe((localStreamStoreValue) => {
|
||||
clearInterval(timeout);
|
||||
if (soundMeter) {
|
||||
soundMeter.stop();
|
||||
}
|
||||
if (localStreamStoreValue.type === "error") {
|
||||
set(undefined);
|
||||
return;
|
||||
@ -557,7 +561,7 @@ export const localVolumeStore = readable<number | undefined>(undefined, (set) =>
|
||||
set(undefined);
|
||||
return;
|
||||
}
|
||||
const soundMeter = new SoundMeter(mediaStream);
|
||||
soundMeter = new SoundMeter(mediaStream);
|
||||
let error = false;
|
||||
|
||||
timeout = setInterval(() => {
|
||||
@ -575,6 +579,9 @@ export const localVolumeStore = readable<number | undefined>(undefined, (set) =>
|
||||
return () => {
|
||||
unsubscribe();
|
||||
clearInterval(timeout);
|
||||
if (soundMeter) {
|
||||
soundMeter.stop();
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
|
@ -74,12 +74,17 @@ export class VideoPeer extends Peer {
|
||||
|
||||
this.volumeStore = readable<number | undefined>(undefined, (set) => {
|
||||
let timeout: ReturnType<typeof setTimeout>;
|
||||
let soundMeter: SoundMeter;
|
||||
const unsubscribe = this.streamStore.subscribe((mediaStream) => {
|
||||
clearInterval(timeout);
|
||||
if (soundMeter) {
|
||||
soundMeter.stop();
|
||||
}
|
||||
if (mediaStream === null || mediaStream.getAudioTracks().length <= 0) {
|
||||
set(undefined);
|
||||
return;
|
||||
}
|
||||
const soundMeter = new SoundMeter(mediaStream);
|
||||
soundMeter = new SoundMeter(mediaStream);
|
||||
let error = false;
|
||||
|
||||
timeout = setInterval(() => {
|
||||
@ -97,6 +102,9 @@ export class VideoPeer extends Peer {
|
||||
return () => {
|
||||
unsubscribe();
|
||||
clearInterval(timeout);
|
||||
if (soundMeter) {
|
||||
soundMeter.stop();
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user