Remove the event listener for processing audio at the same time that we disconnect the script node. At this point we are closing the web socket and do not want to process more of the microphone data even if it is already in flight. Also add it back when we resume listening instead of just at init time.

This commit is contained in:
picklesrus 2018-05-09 11:57:14 -07:00
parent e8ce37e776
commit d2cff42a99

View file

@ -319,6 +319,7 @@ class Scratch3SpeechBlocks {
// This is called on green flag to reset things that may never have existed // This is called on green flag to reset things that may never have existed
// in the first place. Do a bunch of checks. // in the first place. Do a bunch of checks.
if (this._scriptNode) { if (this._scriptNode) {
this._scriptNode.removeEventListener('audioprocess', this._processAudioCallback);
this._scriptNode.disconnect(); this._scriptNode.disconnect();
} }
if (this._sourceNode) { if (this._sourceNode) {
@ -522,6 +523,7 @@ class Scratch3SpeechBlocks {
*/ */
_resumeListening () { _resumeListening () {
this._context.resume.bind(this._context); this._context.resume.bind(this._context);
this._scriptNode.addEventListener('audioprocess', this._processAudioCallback);
this._newWebsocket(); this._newWebsocket();
} }