From 2098bfb3caab8ff31415f5c19d4739141b0e7b45 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 31 Aug 2016 16:10:04 -0400 Subject: [PATCH] emscripten: Be more aggressive when closing audio capture devices. Fixes exceptions being thrown on shutdown. --- src/audio/emscripten/SDL_emscriptenaudio.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/audio/emscripten/SDL_emscriptenaudio.c b/src/audio/emscripten/SDL_emscriptenaudio.c index cdef60f89..b48943c3c 100644 --- a/src/audio/emscripten/SDL_emscriptenaudio.c +++ b/src/audio/emscripten/SDL_emscriptenaudio.c @@ -203,7 +203,15 @@ EMSCRIPTENAUDIO_CloseDevice(_THIS) if (SDL2.capture.silenceTimer !== undefined) { clearTimeout(SDL2.capture.silenceTimer); } + if (SDL2.capture.stream !== undefined) { + var tracks = SDL2.capture.stream.getAudioTracks(); + for (var i = 0; i < tracks.length; i++) { + SDL2.capture.stream.removeTrack(tracks[i]); + } + SDL2.capture.stream = undefined; + } if (SDL2.capture.scriptProcessorNode !== undefined) { + SDL2.capture.scriptProcessorNode.onaudioprocess = function(audioProcessingEvent) {}; SDL2.capture.scriptProcessorNode.disconnect(); SDL2.capture.scriptProcessorNode = undefined; } @@ -344,6 +352,7 @@ EMSCRIPTENAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscaptu }; SDL2.capture.mediaStreamNode.connect(SDL2.capture.scriptProcessorNode); SDL2.capture.scriptProcessorNode.connect(SDL2.audioContext.destination); + SDL2.capture.stream = stream; }; var no_microphone = function(error) {