fix cases where timeouts fire after expected event

This commit is contained in:
Josh de Leeuw 2021-11-27 16:39:38 -05:00
parent 308a791a8a
commit e8f1bd6d08

View File

@ -96,9 +96,10 @@ class HtmlAudioResponsePlugin implements JsPsychPlugin<Info> {
} }
private hideStimulus(display_element: HTMLElement) { private hideStimulus(display_element: HTMLElement) {
display_element.querySelector<HTMLElement>( const el: HTMLElement = display_element.querySelector("#jspsych-html-audio-response-stimulus");
"#jspsych-html-audio-response-stimulus" if (el) {
).style.visibility = "hidden"; el.style.visibility = "hidden";
}
} }
private addButtonEvent(display_element, trial) { private addButtonEvent(display_element, trial) {
@ -155,13 +156,17 @@ class HtmlAudioResponsePlugin implements JsPsychPlugin<Info> {
// setup timer for ending the trial // setup timer for ending the trial
if (trial.recording_duration !== null) { if (trial.recording_duration !== null) {
this.jsPsych.pluginAPI.setTimeout(() => { this.jsPsych.pluginAPI.setTimeout(() => {
this.stopRecording().then(() => { // this check is necessary for cases where the
if (trial.allow_playback) { // done_button is clicked before the timer expires
this.showPlaybackControls(display_element, trial); if (this.recorder.state !== "inactive") {
} else { this.stopRecording().then(() => {
this.endTrial(display_element, trial); if (trial.allow_playback) {
} this.showPlaybackControls(display_element, trial);
}); } else {
this.endTrial(display_element, trial);
}
});
}
}, trial.recording_duration); }, trial.recording_duration);
} }
}; };