Fix ram leak caused by not destroying Wavesurfers on reload.
This commit is contained in:
parent
d2db42fab7
commit
d72032f3fd
2 changed files with 17 additions and 1 deletions
|
@ -149,6 +149,11 @@ class Player extends ((PlayerEmitter as unknown) as { new (): EventEmitter }) {
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
// Let wavesurfer remove the old media, otherwise ram leak!
|
||||||
|
this.wavesurfer.destroy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type LevelsSource = "mic-precomp" | "mic-final" | "master";
|
export type LevelsSource = "mic-precomp" | "mic-final" | "master";
|
||||||
|
@ -270,6 +275,16 @@ export class AudioEngine extends ((EngineEmitter as unknown) as {
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wavesurfer needs cleanup to remove the old audio mediaelements. Memory leak!
|
||||||
|
public destroyPlayer(number: number) {
|
||||||
|
const existingPlayer = this.players[number];
|
||||||
|
if (existingPlayer != null) {
|
||||||
|
// already a player setup. Clean it.
|
||||||
|
existingPlayer.cleanup()
|
||||||
|
}
|
||||||
|
this.players[number] = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
async openMic(deviceId: string) {
|
async openMic(deviceId: string) {
|
||||||
if (this.micSource !== null && this.micMedia !== null) {
|
if (this.micSource !== null && this.micMedia !== null) {
|
||||||
this.micMedia.getAudioTracks()[0].stop();
|
this.micMedia.getAudioTracks()[0].stop();
|
||||||
|
|
|
@ -298,7 +298,8 @@ export const load = (
|
||||||
if (waveform == null) {
|
if (waveform == null) {
|
||||||
throw new Error();
|
throw new Error();
|
||||||
}
|
}
|
||||||
waveform.innerHTML = ""; // clear previous (ghost) wavesurfer
|
audioEngine.destroyPlayer(player);// clear previous (ghost) wavesurfer and it's media elements.
|
||||||
|
//waveform.innerHTML = "";
|
||||||
// wavesurfer also sets the background white, remove for progress bar to work.
|
// wavesurfer also sets the background white, remove for progress bar to work.
|
||||||
waveform.style.removeProperty("background");
|
waveform.style.removeProperty("background");
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue