@jspsych/plugin-audio-slider-response 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.browser.js +5 -3
- package/dist/index.browser.js.map +1 -1
- package/dist/index.browser.min.js +2 -2
- package/dist/index.browser.min.js.map +1 -1
- package/dist/index.cjs +4 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +5 -2
package/dist/index.browser.js
CHANGED
|
@@ -51,7 +51,7 @@ var jsPsychAudioSliderResponse = (function (jspsych) {
|
|
|
51
51
|
|
|
52
52
|
var _package = {
|
|
53
53
|
name: "@jspsych/plugin-audio-slider-response",
|
|
54
|
-
version: "2.0.
|
|
54
|
+
version: "2.0.1",
|
|
55
55
|
description: "",
|
|
56
56
|
type: "module",
|
|
57
57
|
main: "dist/index.cjs",
|
|
@@ -186,7 +186,6 @@ var jsPsychAudioSliderResponse = (function (jspsych) {
|
|
|
186
186
|
half_thumb_width;
|
|
187
187
|
trial_complete;
|
|
188
188
|
async trial(display_element, trial, on_load) {
|
|
189
|
-
this.startTime;
|
|
190
189
|
this.params = trial;
|
|
191
190
|
this.display = display_element;
|
|
192
191
|
this.response;
|
|
@@ -287,6 +286,9 @@ var jsPsychAudioSliderResponse = (function (jspsych) {
|
|
|
287
286
|
}
|
|
288
287
|
});
|
|
289
288
|
this.startTime = performance.now();
|
|
289
|
+
if (this.context !== null) {
|
|
290
|
+
this.startTime = this.context.currentTime;
|
|
291
|
+
}
|
|
290
292
|
this.audio.play();
|
|
291
293
|
if (this.params.trial_duration !== null) {
|
|
292
294
|
this.jsPsych.pluginAPI.setTimeout(() => {
|
|
@@ -359,4 +361,4 @@ var jsPsychAudioSliderResponse = (function (jspsych) {
|
|
|
359
361
|
return AudioSliderResponsePlugin;
|
|
360
362
|
|
|
361
363
|
})(jsPsychModule);
|
|
362
|
-
//# sourceMappingURL=https://unpkg.com/@jspsych/plugin-audio-slider-response@2.0.
|
|
364
|
+
//# sourceMappingURL=https://unpkg.com/@jspsych/plugin-audio-slider-response@2.0.1/dist/index.browser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.browser.js","sources":["../../../node_modules/auto-bind/index.js","../src/index.ts"],"sourcesContent":["'use strict';\n\n// Gets all non-builtin properties up the prototype chain\nconst getAllProperties = object => {\n\tconst properties = new Set();\n\n\tdo {\n\t\tfor (const key of Reflect.ownKeys(object)) {\n\t\t\tproperties.add([object, key]);\n\t\t}\n\t} while ((object = Reflect.getPrototypeOf(object)) && object !== Object.prototype);\n\n\treturn properties;\n};\n\nmodule.exports = (self, {include, exclude} = {}) => {\n\tconst filter = key => {\n\t\tconst match = pattern => typeof pattern === 'string' ? key === pattern : pattern.test(key);\n\n\t\tif (include) {\n\t\t\treturn include.some(match);\n\t\t}\n\n\t\tif (exclude) {\n\t\t\treturn !exclude.some(match);\n\t\t}\n\n\t\treturn true;\n\t};\n\n\tfor (const [object, key] of getAllProperties(self.constructor.prototype)) {\n\t\tif (key === 'constructor' || !filter(key)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst descriptor = Reflect.getOwnPropertyDescriptor(object, key);\n\t\tif (descriptor && typeof descriptor.value === 'function') {\n\t\t\tself[key] = self[key].bind(self);\n\t\t}\n\t}\n\n\treturn self;\n};\n","import autoBind from \"auto-bind\";\nimport { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { AudioPlayerInterface } from \"../../jspsych/src/modules/plugin-api/AudioPlayer\";\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"audio-slider-response\",\n version: version,\n parameters: {\n /** Audio file to be played. */\n stimulus: {\n type: ParameterType.AUDIO,\n default: undefined,\n },\n /** Sets the minimum value of the slider. */\n min: {\n type: ParameterType.INT,\n default: 0,\n },\n /** Sets the maximum value of the slider */\n max: {\n type: ParameterType.INT,\n default: 100,\n },\n /** Sets the starting value of the slider */\n slider_start: {\n type: ParameterType.INT,\n default: 50,\n },\n /** Sets the step of the slider. This is the smallest amount by which the slider can change. */\n step: {\n type: ParameterType.INT,\n default: 1,\n },\n /** Labels displayed at equidistant locations on the slider. For example, two labels will be placed at the ends of the\n * slider. Three labels would place two at the ends and one in the middle. Four will place two at the ends, and the\n * other two will be at 33% and 67% of the slider width.\n */\n labels: {\n type: ParameterType.HTML_STRING,\n default: [],\n array: true,\n },\n /** Set the width of the slider in pixels. If left null, then the width will be equal to the widest element in the display. */\n slider_width: {\n type: ParameterType.INT,\n default: null,\n },\n /** Label of the button to end the trial. */\n button_label: {\n type: ParameterType.STRING,\n default: \"Continue\",\n array: false,\n },\n /** If true, the participant must move the slider before clicking the continue button. */\n require_movement: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is\n * that it can be used to provide a reminder about the action the participant is supposed to take (e.g., which key to press).\n */\n prompt: {\n type: ParameterType.HTML_STRING,\n default: null,\n },\n /** How long to wait for the participant to make a response before ending the trial in milliseconds. If\n * the participant fails to make a response before this timer is reached, the participant's response will be\n * recorded as null for the trial and the trial will end. If the value of this parameter is null, then the trial\n * will wait for a response indefinitely.\n */\n trial_duration: {\n type: ParameterType.INT,\n default: null,\n },\n /** If true, then the trial will end whenever the participant makes a response (assuming they make their response\n * before the cutoff specified by the `trial_duration` parameter). If false, then the trial will continue until the\n * value for `trial_duration` is reached. You can set this parameter to `false` to force the participant to listen to\n * the stimulus for a fixed amount of time, even if they respond before the time is complete.\n */\n response_ends_trial: {\n type: ParameterType.BOOL,\n default: true,\n },\n /** If true, then the trial will end as soon as the audio file finishes playing. */\n trial_ends_after_audio: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** If true, then responses are allowed while the audio is playing. If false, then the audio must finish playing before\n * the slider is enabled and the trial can end via the next button click. Once the audio has played all the way through,\n * the slider is enabled and a response is allowed (including while the audio is being re-played via on-screen playback controls).\n */\n response_allowed_while_playing: {\n type: ParameterType.BOOL,\n default: true,\n },\n },\n data: {\n /** The numeric value of the slider. */\n response: {\n type: ParameterType.INT,\n },\n /** The time in milliseconds for the participant to make a response. The time is measured from when the stimulus first\n * began playing until the participant's response.\n */\n rt: {\n type: ParameterType.INT,\n },\n /** The path of the audio file that was played. */\n stimulus: {\n type: ParameterType.STRING,\n },\n /** The starting value of the slider. */\n slider_start: {\n type: ParameterType.INT,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * This plugin plays an audio file and allows the participant to respond by dragging a slider.\n *\n * If the browser supports it, audio files are played using the WebAudio API. This allows for reasonably precise timing of the\n * playback. The timing of responses generated is measured against the WebAudio specific clock, improving the measurement of\n * response times. If the browser does not support the WebAudio API, then the audio file is played with HTML5 audio.\n *\n * Audio files can be automatically preloaded by jsPsych using the [`preload` plugin](preload.md). However, if you are using\n * timeline variables or another dynamic method to specify the audio stimulus, then you will need\n * to [manually preload](../overview/media-preloading.md#manual-preloading) the audio.\n *\n * The trial can end when the participant responds, or if the participant has failed to respond within a fixed length of time. You can also prevent the slider response from being made before the audio has finished playing.\n * @author Josh de Leeuw\n * @see {@link https://www.jspsych.org/latest/plugins/audio-slider-response/ audio-slider-response plugin documentation on jspsych.org}\n */\nclass AudioSliderResponsePlugin implements JsPsychPlugin<Info> {\n static info = info;\n private audio: AudioPlayerInterface;\n private context: AudioContext;\n private params: TrialType<Info>;\n private display: HTMLElement;\n private response: { rt: number; response: number } = { rt: null, response: null };\n private startTime: number;\n private half_thumb_width: number;\n private trial_complete: (trial_data: {\n rt: number;\n slider_start: number;\n response: number;\n }) => void;\n\n constructor(private jsPsych: JsPsych) {\n autoBind(this);\n }\n\n async trial(display_element: HTMLElement, trial: TrialType<Info>, on_load: () => void) {\n // record webaudio context start time\n this.startTime;\n this.params = trial;\n this.display = display_element;\n // for storing data related to response\n this.response;\n // half of the thumb width value from jspsych.css, used to adjust the label positions\n this.half_thumb_width = 7.5;\n // hold the .resolve() function from the Promise that ends the trial\n this.trial_complete;\n\n // setup stimulus\n this.context = this.jsPsych.pluginAPI.audioContext();\n\n // load audio file\n this.audio = await this.jsPsych.pluginAPI.getAudioPlayer(trial.stimulus);\n\n this.setupTrial();\n\n on_load();\n\n return new Promise((resolve) => {\n this.trial_complete = resolve;\n });\n }\n\n // to enable slider after audio ends\n private enable_slider() {\n document.querySelector<HTMLInputElement>(\"#jspsych-audio-slider-response-response\").disabled =\n false;\n if (!this.params.require_movement) {\n document.querySelector<HTMLButtonElement>(\"#jspsych-audio-slider-response-next\").disabled =\n false;\n }\n }\n\n private setupTrial = () => {\n // set up end event if trial needs it\n if (this.params.trial_ends_after_audio) {\n this.audio.addEventListener(\"ended\", this.end_trial);\n }\n\n // enable slider after audio ends if necessary\n if (!this.params.response_allowed_while_playing && !this.params.trial_ends_after_audio) {\n this.audio.addEventListener(\"ended\", this.enable_slider);\n }\n\n var html = '<div id=\"jspsych-audio-slider-response-wrapper\" style=\"margin: 100px 0px;\">';\n html +=\n '<div class=\"jspsych-audio-slider-response-container\" style=\"position:relative; margin: 0 auto 3em auto; width:';\n if (this.params.slider_width !== null) {\n html += this.params.slider_width + \"px;\";\n } else {\n html += \"auto;\";\n }\n html += '\">';\n html +=\n '<input type=\"range\" class=\"jspsych-slider\" value=\"' +\n this.params.slider_start +\n '\" min=\"' +\n this.params.min +\n '\" max=\"' +\n this.params.max +\n '\" step=\"' +\n this.params.step +\n '\" id=\"jspsych-audio-slider-response-response\"';\n if (!this.params.response_allowed_while_playing) {\n html += \" disabled\";\n }\n html += \"></input><div>\";\n for (var j = 0; j < this.params.labels.length; j++) {\n var label_width_perc = 100 / (this.params.labels.length - 1);\n var percent_of_range = j * (100 / (this.params.labels.length - 1));\n var percent_dist_from_center = ((percent_of_range - 50) / 50) * 100;\n var offset = (percent_dist_from_center * this.half_thumb_width) / 100;\n html +=\n '<div style=\"border: 1px solid transparent; display: inline-block; position: absolute; ' +\n \"left:calc(\" +\n percent_of_range +\n \"% - (\" +\n label_width_perc +\n \"% / 2) - \" +\n offset +\n \"px); text-align: center; width: \" +\n label_width_perc +\n '%;\">';\n html +=\n '<span style=\"text-align: center; font-size: 80%;\">' + this.params.labels[j] + \"</span>\";\n html += \"</div>\";\n }\n html += \"</div>\";\n html += \"</div>\";\n html += \"</div>\";\n\n if (this.params.prompt !== null) {\n html += this.params.prompt;\n }\n\n // add submit button\n var next_disabled_attribute = \"\";\n if (this.params.require_movement || !this.params.response_allowed_while_playing) {\n next_disabled_attribute = \"disabled\";\n }\n html +=\n '<button id=\"jspsych-audio-slider-response-next\" class=\"jspsych-btn\" ' +\n next_disabled_attribute +\n \">\" +\n this.params.button_label +\n \"</button>\";\n\n this.display.innerHTML = html;\n\n this.response = {\n rt: null,\n response: null,\n };\n\n if (!this.params.response_allowed_while_playing) {\n this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-response\"\n ).disabled = true;\n this.display.querySelector<HTMLInputElement>(\"#jspsych-audio-slider-response-next\").disabled =\n true;\n }\n\n if (this.params.require_movement) {\n const enable_button = () => {\n this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-next\"\n ).disabled = false;\n };\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-response\")\n .addEventListener(\"mousedown\", enable_button);\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-response\")\n .addEventListener(\"touchstart\", enable_button);\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-response\")\n .addEventListener(\"change\", enable_button);\n }\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-next\")\n .addEventListener(\"click\", () => {\n // measure response time\n var endTime = performance.now();\n var rt = Math.round(endTime - this.startTime);\n if (this.context !== null) {\n endTime = this.context.currentTime;\n rt = Math.round((endTime - this.startTime) * 1000);\n }\n this.response.rt = rt;\n this.response.response = this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-response\"\n ).valueAsNumber;\n\n if (this.params.response_ends_trial) {\n this.end_trial();\n } else {\n this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-next\"\n ).disabled = true;\n }\n });\n\n this.startTime = performance.now();\n\n // start audio\n this.audio.play();\n\n // end trial if trial_duration is set\n if (this.params.trial_duration !== null) {\n this.jsPsych.pluginAPI.setTimeout(() => {\n this.end_trial();\n }, this.params.trial_duration);\n }\n };\n\n private end_trial = () => {\n // kill any remaining setTimeout handlers\n this.jsPsych.pluginAPI.clearAllTimeouts();\n\n // stop the audio file if it is playing\n this.audio.stop();\n\n // remove end event listeners if they exist\n this.audio.removeEventListener(\"ended\", this.end_trial);\n this.audio.removeEventListener(\"ended\", this.enable_slider);\n\n // save data\n var trialdata = {\n rt: this.response.rt,\n stimulus: this.params.stimulus,\n slider_start: this.params.slider_start,\n response: this.response.response,\n };\n\n this.display.innerHTML = \"\";\n\n // next trial\n this.trial_complete(trialdata);\n };\n\n simulate(\n trial: TrialType<Info>,\n simulation_mode,\n simulation_options: any,\n load_callback: () => void\n ) {\n if (simulation_mode == \"data-only\") {\n load_callback();\n this.simulate_data_only(trial, simulation_options);\n }\n if (simulation_mode == \"visual\") {\n this.simulate_visual(trial, simulation_options, load_callback);\n }\n }\n\n private create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const default_data = {\n stimulus: trial.stimulus,\n slider_start: trial.slider_start,\n response: this.jsPsych.randomization.randomInt(trial.min, trial.max),\n rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),\n };\n\n const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);\n\n this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);\n\n return data;\n }\n\n private simulate_data_only(trial: TrialType<Info>, simulation_options) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n this.jsPsych.finishTrial(data);\n }\n\n private simulate_visual(trial: TrialType<Info>, simulation_options, load_callback: () => void) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n const display_element = this.jsPsych.getDisplayElement();\n\n const respond = () => {\n if (data.rt !== null) {\n const el = display_element.querySelector<HTMLInputElement>(\"input[type='range']\");\n\n setTimeout(() => {\n this.jsPsych.pluginAPI.clickTarget(el);\n el.valueAsNumber = data.response;\n }, data.rt / 2);\n\n this.jsPsych.pluginAPI.clickTarget(display_element.querySelector(\"button\"), data.rt);\n }\n };\n\n this.trial(display_element, trial, () => {\n load_callback();\n\n if (!trial.response_allowed_while_playing) {\n this.audio.addEventListener(\"ended\", respond);\n } else {\n respond();\n }\n });\n }\n}\n\nexport default AudioSliderResponsePlugin;\n"],"names":["version","ParameterType","autoBind"],"mappings":";;;;;;;CAEA;CACA,MAAM,gBAAgB,GAAG,MAAM,IAAI;CACnC,CAAC,MAAM,UAAU,GAAG,IAAI,GAAG,EAAE,CAAC;AAC9B;CACA,CAAC,GAAG;CACJ,EAAE,KAAK,MAAM,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;CAC7C,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;CACjC,GAAG;CACH,EAAE,QAAQ,CAAC,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,KAAK,MAAM,KAAK,MAAM,CAAC,SAAS,EAAE;AACpF;CACA,CAAC,OAAO,UAAU,CAAC;CACnB,CAAC,CAAC;AACF;KACA,QAAc,GAAG,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE,KAAK;CACpD,CAAC,MAAM,MAAM,GAAG,GAAG,IAAI;CACvB,EAAE,MAAM,KAAK,GAAG,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,GAAG,GAAG,KAAK,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC7F;CACA,EAAE,IAAI,OAAO,EAAE;CACf,GAAG,OAAO,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;CAC9B,GAAG;AACH;CACA,EAAE,IAAI,OAAO,EAAE;CAC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WAAA,CAAY,EAAE,CAAA,CAAA;CACrC,UAAA,EAAA,CAAG,gBAAgB,IAAK,CAAA,QAAA,CAAA;CAAA,SAC1B,EAAG,IAAK,CAAA,EAAA,GAAK,CAAC,CAAA,CAAA;CAEd,QAAK,IAAA,CAAA,OAAA,CAAQ,UAAU,WAAY,CAAA,eAAA,CAAgB,cAAc,QAAQ,CAAA,EAAG,KAAK,EAAE,CAAA,CAAA;CAAA,OACrF;CAAA,KACF,CAAA;CAEA,IAAK,IAAA,CAAA,KAAA,CAAM,eAAiB,EAAA,KAAA,EAAO,MAAM;CACvC,MAAc,aAAA,EAAA,CAAA;CAEd,MAAI,IAAA,CAAC,MAAM,8BAAgC,EAAA;CACzC,QAAK,IAAA,CAAA,KAAA,CAAM,gBAAiB,CAAA,OAAA,EAAS,OAAO,CAAA,CAAA;CAAA,OACvC,MAAA;CACL,QAAQ,OAAA,EAAA,CAAA;CAAA,OACV;CAAA,KACD,CAAA,CAAA;CAAA,GACH;CACF;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.browser.js","sources":["../../../node_modules/auto-bind/index.js","../src/index.ts"],"sourcesContent":["'use strict';\n\n// Gets all non-builtin properties up the prototype chain\nconst getAllProperties = object => {\n\tconst properties = new Set();\n\n\tdo {\n\t\tfor (const key of Reflect.ownKeys(object)) {\n\t\t\tproperties.add([object, key]);\n\t\t}\n\t} while ((object = Reflect.getPrototypeOf(object)) && object !== Object.prototype);\n\n\treturn properties;\n};\n\nmodule.exports = (self, {include, exclude} = {}) => {\n\tconst filter = key => {\n\t\tconst match = pattern => typeof pattern === 'string' ? key === pattern : pattern.test(key);\n\n\t\tif (include) {\n\t\t\treturn include.some(match);\n\t\t}\n\n\t\tif (exclude) {\n\t\t\treturn !exclude.some(match);\n\t\t}\n\n\t\treturn true;\n\t};\n\n\tfor (const [object, key] of getAllProperties(self.constructor.prototype)) {\n\t\tif (key === 'constructor' || !filter(key)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst descriptor = Reflect.getOwnPropertyDescriptor(object, key);\n\t\tif (descriptor && typeof descriptor.value === 'function') {\n\t\t\tself[key] = self[key].bind(self);\n\t\t}\n\t}\n\n\treturn self;\n};\n","import autoBind from \"auto-bind\";\nimport { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { AudioPlayerInterface } from \"../../jspsych/src/modules/plugin-api/AudioPlayer\";\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"audio-slider-response\",\n version: version,\n parameters: {\n /** Audio file to be played. */\n stimulus: {\n type: ParameterType.AUDIO,\n default: undefined,\n },\n /** Sets the minimum value of the slider. */\n min: {\n type: ParameterType.INT,\n default: 0,\n },\n /** Sets the maximum value of the slider */\n max: {\n type: ParameterType.INT,\n default: 100,\n },\n /** Sets the starting value of the slider */\n slider_start: {\n type: ParameterType.INT,\n default: 50,\n },\n /** Sets the step of the slider. This is the smallest amount by which the slider can change. */\n step: {\n type: ParameterType.INT,\n default: 1,\n },\n /** Labels displayed at equidistant locations on the slider. For example, two labels will be placed at the ends of the\n * slider. Three labels would place two at the ends and one in the middle. Four will place two at the ends, and the\n * other two will be at 33% and 67% of the slider width.\n */\n labels: {\n type: ParameterType.HTML_STRING,\n default: [],\n array: true,\n },\n /** Set the width of the slider in pixels. If left null, then the width will be equal to the widest element in the display. */\n slider_width: {\n type: ParameterType.INT,\n default: null,\n },\n /** Label of the button to end the trial. */\n button_label: {\n type: ParameterType.STRING,\n default: \"Continue\",\n array: false,\n },\n /** If true, the participant must move the slider before clicking the continue button. */\n require_movement: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is\n * that it can be used to provide a reminder about the action the participant is supposed to take (e.g., which key to press).\n */\n prompt: {\n type: ParameterType.HTML_STRING,\n default: null,\n },\n /** How long to wait for the participant to make a response before ending the trial in milliseconds. If\n * the participant fails to make a response before this timer is reached, the participant's response will be\n * recorded as null for the trial and the trial will end. If the value of this parameter is null, then the trial\n * will wait for a response indefinitely.\n */\n trial_duration: {\n type: ParameterType.INT,\n default: null,\n },\n /** If true, then the trial will end whenever the participant makes a response (assuming they make their response\n * before the cutoff specified by the `trial_duration` parameter). If false, then the trial will continue until the\n * value for `trial_duration` is reached. You can set this parameter to `false` to force the participant to listen to\n * the stimulus for a fixed amount of time, even if they respond before the time is complete.\n */\n response_ends_trial: {\n type: ParameterType.BOOL,\n default: true,\n },\n /** If true, then the trial will end as soon as the audio file finishes playing. */\n trial_ends_after_audio: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** If true, then responses are allowed while the audio is playing. If false, then the audio must finish playing before\n * the slider is enabled and the trial can end via the next button click. Once the audio has played all the way through,\n * the slider is enabled and a response is allowed (including while the audio is being re-played via on-screen playback controls).\n */\n response_allowed_while_playing: {\n type: ParameterType.BOOL,\n default: true,\n },\n },\n data: {\n /** The numeric value of the slider. */\n response: {\n type: ParameterType.INT,\n },\n /** The time in milliseconds for the participant to make a response. The time is measured from when the stimulus first\n * began playing until the participant's response.\n */\n rt: {\n type: ParameterType.INT,\n },\n /** The path of the audio file that was played. */\n stimulus: {\n type: ParameterType.STRING,\n },\n /** The starting value of the slider. */\n slider_start: {\n type: ParameterType.INT,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * This plugin plays an audio file and allows the participant to respond by dragging a slider.\n *\n * If the browser supports it, audio files are played using the WebAudio API. This allows for reasonably precise timing of the\n * playback. The timing of responses generated is measured against the WebAudio specific clock, improving the measurement of\n * response times. If the browser does not support the WebAudio API, then the audio file is played with HTML5 audio.\n *\n * Audio files can be automatically preloaded by jsPsych using the [`preload` plugin](preload.md). However, if you are using\n * timeline variables or another dynamic method to specify the audio stimulus, then you will need\n * to [manually preload](../overview/media-preloading.md#manual-preloading) the audio.\n *\n * The trial can end when the participant responds, or if the participant has failed to respond within a fixed length of time. You can also prevent the slider response from being made before the audio has finished playing.\n * @author Josh de Leeuw\n * @see {@link https://www.jspsych.org/latest/plugins/audio-slider-response/ audio-slider-response plugin documentation on jspsych.org}\n */\nclass AudioSliderResponsePlugin implements JsPsychPlugin<Info> {\n static info = info;\n private audio: AudioPlayerInterface;\n private context: AudioContext;\n private params: TrialType<Info>;\n private display: HTMLElement;\n private response: { rt: number; response: number } = { rt: null, response: null };\n private startTime: number;\n private half_thumb_width: number;\n private trial_complete: (trial_data: {\n rt: number;\n slider_start: number;\n response: number;\n }) => void;\n\n constructor(private jsPsych: JsPsych) {\n autoBind(this);\n }\n\n async trial(display_element: HTMLElement, trial: TrialType<Info>, on_load: () => void) {\n this.params = trial;\n this.display = display_element;\n // for storing data related to response\n this.response;\n // half of the thumb width value from jspsych.css, used to adjust the label positions\n this.half_thumb_width = 7.5;\n // hold the .resolve() function from the Promise that ends the trial\n this.trial_complete;\n\n // setup stimulus\n this.context = this.jsPsych.pluginAPI.audioContext();\n\n // load audio file\n this.audio = await this.jsPsych.pluginAPI.getAudioPlayer(trial.stimulus);\n\n this.setupTrial();\n\n on_load();\n\n return new Promise((resolve) => {\n this.trial_complete = resolve;\n });\n }\n\n // to enable slider after audio ends\n private enable_slider() {\n document.querySelector<HTMLInputElement>(\"#jspsych-audio-slider-response-response\").disabled =\n false;\n if (!this.params.require_movement) {\n document.querySelector<HTMLButtonElement>(\"#jspsych-audio-slider-response-next\").disabled =\n false;\n }\n }\n\n private setupTrial = () => {\n // set up end event if trial needs it\n if (this.params.trial_ends_after_audio) {\n this.audio.addEventListener(\"ended\", this.end_trial);\n }\n\n // enable slider after audio ends if necessary\n if (!this.params.response_allowed_while_playing && !this.params.trial_ends_after_audio) {\n this.audio.addEventListener(\"ended\", this.enable_slider);\n }\n\n var html = '<div id=\"jspsych-audio-slider-response-wrapper\" style=\"margin: 100px 0px;\">';\n html +=\n '<div class=\"jspsych-audio-slider-response-container\" style=\"position:relative; margin: 0 auto 3em auto; width:';\n if (this.params.slider_width !== null) {\n html += this.params.slider_width + \"px;\";\n } else {\n html += \"auto;\";\n }\n html += '\">';\n html +=\n '<input type=\"range\" class=\"jspsych-slider\" value=\"' +\n this.params.slider_start +\n '\" min=\"' +\n this.params.min +\n '\" max=\"' +\n this.params.max +\n '\" step=\"' +\n this.params.step +\n '\" id=\"jspsych-audio-slider-response-response\"';\n if (!this.params.response_allowed_while_playing) {\n html += \" disabled\";\n }\n html += \"></input><div>\";\n for (var j = 0; j < this.params.labels.length; j++) {\n var label_width_perc = 100 / (this.params.labels.length - 1);\n var percent_of_range = j * (100 / (this.params.labels.length - 1));\n var percent_dist_from_center = ((percent_of_range - 50) / 50) * 100;\n var offset = (percent_dist_from_center * this.half_thumb_width) / 100;\n html +=\n '<div style=\"border: 1px solid transparent; display: inline-block; position: absolute; ' +\n \"left:calc(\" +\n percent_of_range +\n \"% - (\" +\n label_width_perc +\n \"% / 2) - \" +\n offset +\n \"px); text-align: center; width: \" +\n label_width_perc +\n '%;\">';\n html +=\n '<span style=\"text-align: center; font-size: 80%;\">' + this.params.labels[j] + \"</span>\";\n html += \"</div>\";\n }\n html += \"</div>\";\n html += \"</div>\";\n html += \"</div>\";\n\n if (this.params.prompt !== null) {\n html += this.params.prompt;\n }\n\n // add submit button\n var next_disabled_attribute = \"\";\n if (this.params.require_movement || !this.params.response_allowed_while_playing) {\n next_disabled_attribute = \"disabled\";\n }\n html +=\n '<button id=\"jspsych-audio-slider-response-next\" class=\"jspsych-btn\" ' +\n next_disabled_attribute +\n \">\" +\n this.params.button_label +\n \"</button>\";\n\n this.display.innerHTML = html;\n\n this.response = {\n rt: null,\n response: null,\n };\n\n if (!this.params.response_allowed_while_playing) {\n this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-response\"\n ).disabled = true;\n this.display.querySelector<HTMLInputElement>(\"#jspsych-audio-slider-response-next\").disabled =\n true;\n }\n\n if (this.params.require_movement) {\n const enable_button = () => {\n this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-next\"\n ).disabled = false;\n };\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-response\")\n .addEventListener(\"mousedown\", enable_button);\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-response\")\n .addEventListener(\"touchstart\", enable_button);\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-response\")\n .addEventListener(\"change\", enable_button);\n }\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-next\")\n .addEventListener(\"click\", () => {\n // measure response time\n var endTime = performance.now();\n var rt = Math.round(endTime - this.startTime);\n if (this.context !== null) {\n endTime = this.context.currentTime;\n rt = Math.round((endTime - this.startTime) * 1000);\n }\n this.response.rt = rt;\n this.response.response = this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-response\"\n ).valueAsNumber;\n\n if (this.params.response_ends_trial) {\n this.end_trial();\n } else {\n this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-next\"\n ).disabled = true;\n }\n });\n\n //record start time\n this.startTime = performance.now();\n // record webaudio context start time\n if (this.context !== null) {\n this.startTime = this.context.currentTime;\n }\n\n // start audio\n this.audio.play();\n\n // end trial if trial_duration is set\n if (this.params.trial_duration !== null) {\n this.jsPsych.pluginAPI.setTimeout(() => {\n this.end_trial();\n }, this.params.trial_duration);\n }\n };\n\n private end_trial = () => {\n // kill any remaining setTimeout handlers\n this.jsPsych.pluginAPI.clearAllTimeouts();\n\n // stop the audio file if it is playing\n this.audio.stop();\n\n // remove end event listeners if they exist\n this.audio.removeEventListener(\"ended\", this.end_trial);\n this.audio.removeEventListener(\"ended\", this.enable_slider);\n\n // save data\n var trialdata = {\n rt: this.response.rt,\n stimulus: this.params.stimulus,\n slider_start: this.params.slider_start,\n response: this.response.response,\n };\n\n this.display.innerHTML = \"\";\n\n // next trial\n this.trial_complete(trialdata);\n };\n\n simulate(\n trial: TrialType<Info>,\n simulation_mode,\n simulation_options: any,\n load_callback: () => void\n ) {\n if (simulation_mode == \"data-only\") {\n load_callback();\n this.simulate_data_only(trial, simulation_options);\n }\n if (simulation_mode == \"visual\") {\n this.simulate_visual(trial, simulation_options, load_callback);\n }\n }\n\n private create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const default_data = {\n stimulus: trial.stimulus,\n slider_start: trial.slider_start,\n response: this.jsPsych.randomization.randomInt(trial.min, trial.max),\n rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),\n };\n\n const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);\n\n this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);\n\n return data;\n }\n\n private simulate_data_only(trial: TrialType<Info>, simulation_options) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n this.jsPsych.finishTrial(data);\n }\n\n private simulate_visual(trial: TrialType<Info>, simulation_options, load_callback: () => void) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n const display_element = this.jsPsych.getDisplayElement();\n\n const respond = () => {\n if (data.rt !== null) {\n const el = display_element.querySelector<HTMLInputElement>(\"input[type='range']\");\n\n setTimeout(() => {\n this.jsPsych.pluginAPI.clickTarget(el);\n el.valueAsNumber = data.response;\n }, data.rt / 2);\n\n this.jsPsych.pluginAPI.clickTarget(display_element.querySelector(\"button\"), data.rt);\n }\n };\n\n this.trial(display_element, trial, () => {\n load_callback();\n\n if (!trial.response_allowed_while_playing) {\n this.audio.addEventListener(\"ended\", respond);\n } else {\n respond();\n }\n });\n }\n}\n\nexport default AudioSliderResponsePlugin;\n"],"names":["version","ParameterType","autoBind"],"mappings":";;;;;;;CAEA;CACA,MAAM,gBAAgB,GAAG,MAAM,IAAI;CACnC,CAAC,MAAM,UAAU,GAAG,IAAI,GAAG,EAAE,CAAC;AAC9B;CACA,CAAC,GAAG;CACJ,EAAE,KAAK,MAAM,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;CAC7C,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;CACjC,GAAG;CACH,EAAE,QAAQ,CAAC,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,MAA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;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var jsPsychAudioSliderResponse=function(a){"use strict";function m(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}const c=i=>{const s=new Set;do for(const e of Reflect.ownKeys(i))s.add([i,e]);while((i=Reflect.getPrototypeOf(i))&&i!==Object.prototype);return s};var y=(i,{include:s,exclude:e}={})=>{const r=t=>{const n=l=>typeof l=="string"?t===l:l.test(t);return s?s.some(n):e?!e.some(n):!0};for(const[t,n]of c(i.constructor.prototype)){if(n==="constructor"||!r(n))continue;const l=Reflect.getOwnPropertyDescriptor(t,n);l&&typeof l.value=="function"&&(i[n]=i[n].bind(i))}return i},_=m(y),g={name:"@jspsych/plugin-audio-slider-response",version:"2.0.
|
|
2
|
-
//# sourceMappingURL=https://unpkg.com/@jspsych/plugin-audio-slider-response@2.0.
|
|
1
|
+
var jsPsychAudioSliderResponse=function(a){"use strict";function m(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}const c=i=>{const s=new Set;do for(const e of Reflect.ownKeys(i))s.add([i,e]);while((i=Reflect.getPrototypeOf(i))&&i!==Object.prototype);return s};var y=(i,{include:s,exclude:e}={})=>{const r=t=>{const n=l=>typeof l=="string"?t===l:l.test(t);return s?s.some(n):e?!e.some(n):!0};for(const[t,n]of c(i.constructor.prototype)){if(n==="constructor"||!r(n))continue;const l=Reflect.getOwnPropertyDescriptor(t,n);l&&typeof l.value=="function"&&(i[n]=i[n].bind(i))}return i},_=m(y),g={name:"@jspsych/plugin-audio-slider-response",version:"2.0.1",description:"",type:"module",main:"dist/index.cjs",exports:{import:"./dist/index.js",require:"./dist/index.cjs"},typings:"dist/index.d.ts",unpkg:"dist/index.browser.min.js",files:["src","dist"],source:"src/index.ts",scripts:{test:"jest --passWithNoTests","test:watch":"npm test -- --watch",tsc:"tsc",build:"rollup --config","build:watch":"npm run build -- --watch"},repository:{type:"git",url:"git+https://github.com/jspsych/jsPsych.git",directory:"packages/plugin-audio-slider-response"},author:"Josh de Leeuw",license:"MIT",bugs:{url:"https://github.com/jspsych/jsPsych/issues"},homepage:"https://www.jspsych.org/latest/plugins/audio-slider-response",peerDependencies:{jspsych:">=7.1.0"},devDependencies:{"@jspsych/config":"^3.0.0","@jspsych/test-utils":"^1.2.0"}},v=(i,s,e)=>new Promise((r,t)=>{var n=p=>{try{d(e.next(p))}catch(o){t(o)}},l=p=>{try{d(e.throw(p))}catch(o){t(o)}},d=p=>p.done?r(p.value):Promise.resolve(p.value).then(n,l);d((e=e.apply(i,s)).next())});const P={name:"audio-slider-response",version:g.version,parameters:{stimulus:{type:a.ParameterType.AUDIO,default:void 0},min:{type:a.ParameterType.INT,default:0},max:{type:a.ParameterType.INT,default:100},slider_start:{type:a.ParameterType.INT,default:50},step:{type:a.ParameterType.INT,default:1},labels:{type:a.ParameterType.HTML_STRING,default:[],array:!0},slider_width:{type:a.ParameterType.INT,default:null},button_label:{type:a.ParameterType.STRING,default:"Continue",array:!1},require_movement:{type:a.ParameterType.BOOL,default:!1},prompt:{type:a.ParameterType.HTML_STRING,default:null},trial_duration:{type:a.ParameterType.INT,default:null},response_ends_trial:{type:a.ParameterType.BOOL,default:!0},trial_ends_after_audio:{type:a.ParameterType.BOOL,default:!1},response_allowed_while_playing:{type:a.ParameterType.BOOL,default:!0}},data:{response:{type:a.ParameterType.INT},rt:{type:a.ParameterType.INT},stimulus:{type:a.ParameterType.STRING},slider_start:{type:a.ParameterType.INT}}};class u{constructor(s){this.jsPsych=s,this.response={rt:null,response:null},this.setupTrial=()=>{this.params.trial_ends_after_audio&&this.audio.addEventListener("ended",this.end_trial),!this.params.response_allowed_while_playing&&!this.params.trial_ends_after_audio&&this.audio.addEventListener("ended",this.enable_slider);var e='<div id="jspsych-audio-slider-response-wrapper" style="margin: 100px 0px;">';e+='<div class="jspsych-audio-slider-response-container" style="position:relative; margin: 0 auto 3em auto; width:',this.params.slider_width!==null?e+=this.params.slider_width+"px;":e+="auto;",e+='">',e+='<input type="range" class="jspsych-slider" value="'+this.params.slider_start+'" min="'+this.params.min+'" max="'+this.params.max+'" step="'+this.params.step+'" id="jspsych-audio-slider-response-response"',this.params.response_allowed_while_playing||(e+=" disabled"),e+="></input><div>";for(var r=0;r<this.params.labels.length;r++){var t=100/(this.params.labels.length-1),n=r*(100/(this.params.labels.length-1)),l=(n-50)/50*100,d=l*this.half_thumb_width/100;e+='<div style="border: 1px solid transparent; display: inline-block; position: absolute; left:calc('+n+"% - ("+t+"% / 2) - "+d+"px); text-align: center; width: "+t+'%;">',e+='<span style="text-align: center; font-size: 80%;">'+this.params.labels[r]+"</span>",e+="</div>"}e+="</div>",e+="</div>",e+="</div>",this.params.prompt!==null&&(e+=this.params.prompt);var p="";if((this.params.require_movement||!this.params.response_allowed_while_playing)&&(p="disabled"),e+='<button id="jspsych-audio-slider-response-next" class="jspsych-btn" '+p+">"+this.params.button_label+"</button>",this.display.innerHTML=e,this.response={rt:null,response:null},this.params.response_allowed_while_playing||(this.display.querySelector("#jspsych-audio-slider-response-response").disabled=!0,this.display.querySelector("#jspsych-audio-slider-response-next").disabled=!0),this.params.require_movement){const o=()=>{this.display.querySelector("#jspsych-audio-slider-response-next").disabled=!1};this.display.querySelector("#jspsych-audio-slider-response-response").addEventListener("mousedown",o),this.display.querySelector("#jspsych-audio-slider-response-response").addEventListener("touchstart",o),this.display.querySelector("#jspsych-audio-slider-response-response").addEventListener("change",o)}this.display.querySelector("#jspsych-audio-slider-response-next").addEventListener("click",()=>{var o=performance.now(),h=Math.round(o-this.startTime);this.context!==null&&(o=this.context.currentTime,h=Math.round((o-this.startTime)*1e3)),this.response.rt=h,this.response.response=this.display.querySelector("#jspsych-audio-slider-response-response").valueAsNumber,this.params.response_ends_trial?this.end_trial():this.display.querySelector("#jspsych-audio-slider-response-next").disabled=!0}),this.startTime=performance.now(),this.context!==null&&(this.startTime=this.context.currentTime),this.audio.play(),this.params.trial_duration!==null&&this.jsPsych.pluginAPI.setTimeout(()=>{this.end_trial()},this.params.trial_duration)},this.end_trial=()=>{this.jsPsych.pluginAPI.clearAllTimeouts(),this.audio.stop(),this.audio.removeEventListener("ended",this.end_trial),this.audio.removeEventListener("ended",this.enable_slider);var e={rt:this.response.rt,stimulus:this.params.stimulus,slider_start:this.params.slider_start,response:this.response.response};this.display.innerHTML="",this.trial_complete(e)},_(this)}trial(s,e,r){return v(this,null,function*(){return this.params=e,this.display=s,this.response,this.half_thumb_width=7.5,this.trial_complete,this.context=this.jsPsych.pluginAPI.audioContext(),this.audio=yield this.jsPsych.pluginAPI.getAudioPlayer(e.stimulus),this.setupTrial(),r(),new Promise(t=>{this.trial_complete=t})})}enable_slider(){document.querySelector("#jspsych-audio-slider-response-response").disabled=!1,this.params.require_movement||(document.querySelector("#jspsych-audio-slider-response-next").disabled=!1)}simulate(s,e,r,t){e=="data-only"&&(t(),this.simulate_data_only(s,r)),e=="visual"&&this.simulate_visual(s,r,t)}create_simulation_data(s,e){const r={stimulus:s.stimulus,slider_start:s.slider_start,response:this.jsPsych.randomization.randomInt(s.min,s.max),rt:this.jsPsych.randomization.sampleExGaussian(500,50,.006666666666666667,!0)},t=this.jsPsych.pluginAPI.mergeSimulationData(r,e);return this.jsPsych.pluginAPI.ensureSimulationDataConsistency(s,t),t}simulate_data_only(s,e){const r=this.create_simulation_data(s,e);this.jsPsych.finishTrial(r)}simulate_visual(s,e,r){const t=this.create_simulation_data(s,e),n=this.jsPsych.getDisplayElement(),l=()=>{if(t.rt!==null){const d=n.querySelector("input[type='range']");setTimeout(()=>{this.jsPsych.pluginAPI.clickTarget(d),d.valueAsNumber=t.response},t.rt/2),this.jsPsych.pluginAPI.clickTarget(n.querySelector("button"),t.rt)}};this.trial(n,s,()=>{r(),s.response_allowed_while_playing?l():this.audio.addEventListener("ended",l)})}}return u.info=P,u}(jsPsychModule);
|
|
2
|
+
//# sourceMappingURL=https://unpkg.com/@jspsych/plugin-audio-slider-response@2.0.1/dist/index.browser.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.browser.min.js","sources":["../../../node_modules/auto-bind/index.js","../src/index.ts"],"sourcesContent":["'use strict';\n\n// Gets all non-builtin properties up the prototype chain\nconst getAllProperties = object => {\n\tconst properties = new Set();\n\n\tdo {\n\t\tfor (const key of Reflect.ownKeys(object)) {\n\t\t\tproperties.add([object, key]);\n\t\t}\n\t} while ((object = Reflect.getPrototypeOf(object)) && object !== Object.prototype);\n\n\treturn properties;\n};\n\nmodule.exports = (self, {include, exclude} = {}) => {\n\tconst filter = key => {\n\t\tconst match = pattern => typeof pattern === 'string' ? key === pattern : pattern.test(key);\n\n\t\tif (include) {\n\t\t\treturn include.some(match);\n\t\t}\n\n\t\tif (exclude) {\n\t\t\treturn !exclude.some(match);\n\t\t}\n\n\t\treturn true;\n\t};\n\n\tfor (const [object, key] of getAllProperties(self.constructor.prototype)) {\n\t\tif (key === 'constructor' || !filter(key)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst descriptor = Reflect.getOwnPropertyDescriptor(object, key);\n\t\tif (descriptor && typeof descriptor.value === 'function') {\n\t\t\tself[key] = self[key].bind(self);\n\t\t}\n\t}\n\n\treturn self;\n};\n","import autoBind from \"auto-bind\";\nimport { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { AudioPlayerInterface } from \"../../jspsych/src/modules/plugin-api/AudioPlayer\";\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"audio-slider-response\",\n version: version,\n parameters: {\n /** Audio file to be played. */\n stimulus: {\n type: ParameterType.AUDIO,\n default: undefined,\n },\n /** Sets the minimum value of the slider. */\n min: {\n type: ParameterType.INT,\n default: 0,\n },\n /** Sets the maximum value of the slider */\n max: {\n type: ParameterType.INT,\n default: 100,\n },\n /** Sets the starting value of the slider */\n slider_start: {\n type: ParameterType.INT,\n default: 50,\n },\n /** Sets the step of the slider. This is the smallest amount by which the slider can change. */\n step: {\n type: ParameterType.INT,\n default: 1,\n },\n /** Labels displayed at equidistant locations on the slider. For example, two labels will be placed at the ends of the\n * slider. Three labels would place two at the ends and one in the middle. Four will place two at the ends, and the\n * other two will be at 33% and 67% of the slider width.\n */\n labels: {\n type: ParameterType.HTML_STRING,\n default: [],\n array: true,\n },\n /** Set the width of the slider in pixels. If left null, then the width will be equal to the widest element in the display. */\n slider_width: {\n type: ParameterType.INT,\n default: null,\n },\n /** Label of the button to end the trial. */\n button_label: {\n type: ParameterType.STRING,\n default: \"Continue\",\n array: false,\n },\n /** If true, the participant must move the slider before clicking the continue button. */\n require_movement: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is\n * that it can be used to provide a reminder about the action the participant is supposed to take (e.g., which key to press).\n */\n prompt: {\n type: ParameterType.HTML_STRING,\n default: null,\n },\n /** How long to wait for the participant to make a response before ending the trial in milliseconds. If\n * the participant fails to make a response before this timer is reached, the participant's response will be\n * recorded as null for the trial and the trial will end. If the value of this parameter is null, then the trial\n * will wait for a response indefinitely.\n */\n trial_duration: {\n type: ParameterType.INT,\n default: null,\n },\n /** If true, then the trial will end whenever the participant makes a response (assuming they make their response\n * before the cutoff specified by the `trial_duration` parameter). If false, then the trial will continue until the\n * value for `trial_duration` is reached. You can set this parameter to `false` to force the participant to listen to\n * the stimulus for a fixed amount of time, even if they respond before the time is complete.\n */\n response_ends_trial: {\n type: ParameterType.BOOL,\n default: true,\n },\n /** If true, then the trial will end as soon as the audio file finishes playing. */\n trial_ends_after_audio: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** If true, then responses are allowed while the audio is playing. If false, then the audio must finish playing before\n * the slider is enabled and the trial can end via the next button click. Once the audio has played all the way through,\n * the slider is enabled and a response is allowed (including while the audio is being re-played via on-screen playback controls).\n */\n response_allowed_while_playing: {\n type: ParameterType.BOOL,\n default: true,\n },\n },\n data: {\n /** The numeric value of the slider. */\n response: {\n type: ParameterType.INT,\n },\n /** The time in milliseconds for the participant to make a response. The time is measured from when the stimulus first\n * began playing until the participant's response.\n */\n rt: {\n type: ParameterType.INT,\n },\n /** The path of the audio file that was played. */\n stimulus: {\n type: ParameterType.STRING,\n },\n /** The starting value of the slider. */\n slider_start: {\n type: ParameterType.INT,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * This plugin plays an audio file and allows the participant to respond by dragging a slider.\n *\n * If the browser supports it, audio files are played using the WebAudio API. This allows for reasonably precise timing of the\n * playback. The timing of responses generated is measured against the WebAudio specific clock, improving the measurement of\n * response times. If the browser does not support the WebAudio API, then the audio file is played with HTML5 audio.\n *\n * Audio files can be automatically preloaded by jsPsych using the [`preload` plugin](preload.md). However, if you are using\n * timeline variables or another dynamic method to specify the audio stimulus, then you will need\n * to [manually preload](../overview/media-preloading.md#manual-preloading) the audio.\n *\n * The trial can end when the participant responds, or if the participant has failed to respond within a fixed length of time. You can also prevent the slider response from being made before the audio has finished playing.\n * @author Josh de Leeuw\n * @see {@link https://www.jspsych.org/latest/plugins/audio-slider-response/ audio-slider-response plugin documentation on jspsych.org}\n */\nclass AudioSliderResponsePlugin implements JsPsychPlugin<Info> {\n static info = info;\n private audio: AudioPlayerInterface;\n private context: AudioContext;\n private params: TrialType<Info>;\n private display: HTMLElement;\n private response: { rt: number; response: number } = { rt: null, response: null };\n private startTime: number;\n private half_thumb_width: number;\n private trial_complete: (trial_data: {\n rt: number;\n slider_start: number;\n response: number;\n }) => void;\n\n constructor(private jsPsych: JsPsych) {\n autoBind(this);\n }\n\n async trial(display_element: HTMLElement, trial: TrialType<Info>, on_load: () => void) {\n // record webaudio context start time\n this.startTime;\n this.params = trial;\n this.display = display_element;\n // for storing data related to response\n this.response;\n // half of the thumb width value from jspsych.css, used to adjust the label positions\n this.half_thumb_width = 7.5;\n // hold the .resolve() function from the Promise that ends the trial\n this.trial_complete;\n\n // setup stimulus\n this.context = this.jsPsych.pluginAPI.audioContext();\n\n // load audio file\n this.audio = await this.jsPsych.pluginAPI.getAudioPlayer(trial.stimulus);\n\n this.setupTrial();\n\n on_load();\n\n return new Promise((resolve) => {\n this.trial_complete = resolve;\n });\n }\n\n // to enable slider after audio ends\n private enable_slider() {\n document.querySelector<HTMLInputElement>(\"#jspsych-audio-slider-response-response\").disabled =\n false;\n if (!this.params.require_movement) {\n document.querySelector<HTMLButtonElement>(\"#jspsych-audio-slider-response-next\").disabled =\n false;\n }\n }\n\n private setupTrial = () => {\n // set up end event if trial needs it\n if (this.params.trial_ends_after_audio) {\n this.audio.addEventListener(\"ended\", this.end_trial);\n }\n\n // enable slider after audio ends if necessary\n if (!this.params.response_allowed_while_playing && !this.params.trial_ends_after_audio) {\n this.audio.addEventListener(\"ended\", this.enable_slider);\n }\n\n var html = '<div id=\"jspsych-audio-slider-response-wrapper\" style=\"margin: 100px 0px;\">';\n html +=\n '<div class=\"jspsych-audio-slider-response-container\" style=\"position:relative; margin: 0 auto 3em auto; width:';\n if (this.params.slider_width !== null) {\n html += this.params.slider_width + \"px;\";\n } else {\n html += \"auto;\";\n }\n html += '\">';\n html +=\n '<input type=\"range\" class=\"jspsych-slider\" value=\"' +\n this.params.slider_start +\n '\" min=\"' +\n this.params.min +\n '\" max=\"' +\n this.params.max +\n '\" step=\"' +\n this.params.step +\n '\" id=\"jspsych-audio-slider-response-response\"';\n if (!this.params.response_allowed_while_playing) {\n html += \" disabled\";\n }\n html += \"></input><div>\";\n for (var j = 0; j < this.params.labels.length; j++) {\n var label_width_perc = 100 / (this.params.labels.length - 1);\n var percent_of_range = j * (100 / (this.params.labels.length - 1));\n var percent_dist_from_center = ((percent_of_range - 50) / 50) * 100;\n var offset = (percent_dist_from_center * this.half_thumb_width) / 100;\n html +=\n '<div style=\"border: 1px solid transparent; display: inline-block; position: absolute; ' +\n \"left:calc(\" +\n percent_of_range +\n \"% - (\" +\n label_width_perc +\n \"% / 2) - \" +\n offset +\n \"px); text-align: center; width: \" +\n label_width_perc +\n '%;\">';\n html +=\n '<span style=\"text-align: center; font-size: 80%;\">' + this.params.labels[j] + \"</span>\";\n html += \"</div>\";\n }\n html += \"</div>\";\n html += \"</div>\";\n html += \"</div>\";\n\n if (this.params.prompt !== null) {\n html += this.params.prompt;\n }\n\n // add submit button\n var next_disabled_attribute = \"\";\n if (this.params.require_movement || !this.params.response_allowed_while_playing) {\n next_disabled_attribute = \"disabled\";\n }\n html +=\n '<button id=\"jspsych-audio-slider-response-next\" class=\"jspsych-btn\" ' +\n next_disabled_attribute +\n \">\" +\n this.params.button_label +\n \"</button>\";\n\n this.display.innerHTML = html;\n\n this.response = {\n rt: null,\n response: null,\n };\n\n if (!this.params.response_allowed_while_playing) {\n this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-response\"\n ).disabled = true;\n this.display.querySelector<HTMLInputElement>(\"#jspsych-audio-slider-response-next\").disabled =\n true;\n }\n\n if (this.params.require_movement) {\n const enable_button = () => {\n this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-next\"\n ).disabled = false;\n };\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-response\")\n .addEventListener(\"mousedown\", enable_button);\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-response\")\n .addEventListener(\"touchstart\", enable_button);\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-response\")\n .addEventListener(\"change\", enable_button);\n }\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-next\")\n .addEventListener(\"click\", () => {\n // measure response time\n var endTime = performance.now();\n var rt = Math.round(endTime - this.startTime);\n if (this.context !== null) {\n endTime = this.context.currentTime;\n rt = Math.round((endTime - this.startTime) * 1000);\n }\n this.response.rt = rt;\n this.response.response = this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-response\"\n ).valueAsNumber;\n\n if (this.params.response_ends_trial) {\n this.end_trial();\n } else {\n this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-next\"\n ).disabled = true;\n }\n });\n\n this.startTime = performance.now();\n\n // start audio\n this.audio.play();\n\n // end trial if trial_duration is set\n if (this.params.trial_duration !== null) {\n this.jsPsych.pluginAPI.setTimeout(() => {\n this.end_trial();\n }, this.params.trial_duration);\n }\n };\n\n private end_trial = () => {\n // kill any remaining setTimeout handlers\n this.jsPsych.pluginAPI.clearAllTimeouts();\n\n // stop the audio file if it is playing\n this.audio.stop();\n\n // remove end event listeners if they exist\n this.audio.removeEventListener(\"ended\", this.end_trial);\n this.audio.removeEventListener(\"ended\", this.enable_slider);\n\n // save data\n var trialdata = {\n rt: this.response.rt,\n stimulus: this.params.stimulus,\n slider_start: this.params.slider_start,\n response: this.response.response,\n };\n\n this.display.innerHTML = \"\";\n\n // next trial\n this.trial_complete(trialdata);\n };\n\n simulate(\n trial: TrialType<Info>,\n simulation_mode,\n simulation_options: any,\n load_callback: () => void\n ) {\n if (simulation_mode == \"data-only\") {\n load_callback();\n this.simulate_data_only(trial, simulation_options);\n }\n if (simulation_mode == \"visual\") {\n this.simulate_visual(trial, simulation_options, load_callback);\n }\n }\n\n private create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const default_data = {\n stimulus: trial.stimulus,\n slider_start: trial.slider_start,\n response: this.jsPsych.randomization.randomInt(trial.min, trial.max),\n rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),\n };\n\n const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);\n\n this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);\n\n return data;\n }\n\n private simulate_data_only(trial: TrialType<Info>, simulation_options) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n this.jsPsych.finishTrial(data);\n }\n\n private simulate_visual(trial: TrialType<Info>, simulation_options, load_callback: () => void) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n const display_element = this.jsPsych.getDisplayElement();\n\n const respond = () => {\n if (data.rt !== null) {\n const el = display_element.querySelector<HTMLInputElement>(\"input[type='range']\");\n\n setTimeout(() => {\n this.jsPsych.pluginAPI.clickTarget(el);\n el.valueAsNumber = data.response;\n }, data.rt / 2);\n\n this.jsPsych.pluginAPI.clickTarget(display_element.querySelector(\"button\"), data.rt);\n }\n };\n\n this.trial(display_element, trial, () => {\n load_callback();\n\n if (!trial.response_allowed_while_playing) {\n this.audio.addEventListener(\"ended\", respond);\n } else {\n respond();\n }\n });\n }\n}\n\nexport default AudioSliderResponsePlugin;\n"],"names":["getAllProperties","object","properties","key","autoBind","self","include","exclude","filter","match","pattern","descriptor","info","version","ParameterType","AudioSliderResponsePlugin","jsPsych","html","j","label_width_perc","percent_of_range","percent_dist_from_center","offset","next_disabled_attribute","enable_button","endTime","rt","trialdata","display_element","trial","on_load","__async","resolve","simulation_mode","simulation_options","load_callback","default_data","data","respond","el"],"mappings":"4JAGA,MAAMA,EAAmBC,GAAU,CAClC,MAAMC,EAAa,IAAI,IAEvB,EACC,WAAWC,KAAO,QAAQ,QAAQF,CAAM,EACvCC,EAAW,IAAI,CAACD,EAAQE,CAAG,CAAC,SAEpBF,EAAS,QAAQ,eAAeA,CAAM,IAAMA,IAAW,OAAO,WAExE,OAAOC,CACR,MAEAE,EAAiB,CAACC,EAAM,CAAC,QAAAC,EAAS,QAAAC,CAAO,EAAI,CAAA,IAAO,CACnD,MAAMC,EAASL,GAAO,CACrB,MAAMM,EAAQC,GAAW,OAAOA,GAAY,SAAWP,IAAQO,EAAUA,EAAQ,KAAKP,CAAG,EAEzF,OAAIG,EACIA,EAAQ,KAAKG,CAAK,EAGtBF,EACI,CAACA,EAAQ,KAAKE,CAAK,EAGpB,EACT,EAEC,SAAW,CAACR,EAAQE,CAAG,IAAKH,EAAiBK,EAAK,YAAY,SAAS,EAAG,CACzE,GAAIF,IAAQ,eAAiB,CAACK,EAAOL,CAAG,EACvC,SAGD,MAAMQ,EAAa,QAAQ,yBAAyBV,EAAQE,CAAG,EAC3DQ,GAAc,OAAOA,EAAW,OAAU,aAC7CN,EAAKF,GAAOE,EAAKF,GAAK,KAAKE,CAAI,EAEhC,CAED,OAAOA,CACR,khCCpCA,MAAMO,EAAc,CAClB,KAAM,wBACN,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AK,QAAQ,UAAU,YAAYW,CAAE,EACrCA,EAAG,cAAgBF,EAAK,QAC1B,EAAGA,EAAK,GAAK,CAAC,EAEd,KAAK,QAAQ,UAAU,YAAYT,EAAgB,cAAc,QAAQ,EAAGS,EAAK,EAAE,CACrF,CACF,EAEA,KAAK,MAAMT,EAAiBC,EAAO,IAAM,CACvCM,EAAAA,EAEKN,EAAM,+BAGTS,EAAQ,EAFR,KAAK,MAAM,iBAAiB,QAASA,CAAO,CAIhD,CAAC,CACH,CACF,CAnSMvB,OAAAA,EACG,KAAOH"}
|
|
1
|
+
{"version":3,"file":"index.browser.min.js","sources":["../../../node_modules/auto-bind/index.js","../src/index.ts"],"sourcesContent":["'use strict';\n\n// Gets all non-builtin properties up the prototype chain\nconst getAllProperties = object => {\n\tconst properties = new Set();\n\n\tdo {\n\t\tfor (const key of Reflect.ownKeys(object)) {\n\t\t\tproperties.add([object, key]);\n\t\t}\n\t} while ((object = Reflect.getPrototypeOf(object)) && object !== Object.prototype);\n\n\treturn properties;\n};\n\nmodule.exports = (self, {include, exclude} = {}) => {\n\tconst filter = key => {\n\t\tconst match = pattern => typeof pattern === 'string' ? key === pattern : pattern.test(key);\n\n\t\tif (include) {\n\t\t\treturn include.some(match);\n\t\t}\n\n\t\tif (exclude) {\n\t\t\treturn !exclude.some(match);\n\t\t}\n\n\t\treturn true;\n\t};\n\n\tfor (const [object, key] of getAllProperties(self.constructor.prototype)) {\n\t\tif (key === 'constructor' || !filter(key)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst descriptor = Reflect.getOwnPropertyDescriptor(object, key);\n\t\tif (descriptor && typeof descriptor.value === 'function') {\n\t\t\tself[key] = self[key].bind(self);\n\t\t}\n\t}\n\n\treturn self;\n};\n","import autoBind from \"auto-bind\";\nimport { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { AudioPlayerInterface } from \"../../jspsych/src/modules/plugin-api/AudioPlayer\";\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"audio-slider-response\",\n version: version,\n parameters: {\n /** Audio file to be played. */\n stimulus: {\n type: ParameterType.AUDIO,\n default: undefined,\n },\n /** Sets the minimum value of the slider. */\n min: {\n type: ParameterType.INT,\n default: 0,\n },\n /** Sets the maximum value of the slider */\n max: {\n type: ParameterType.INT,\n default: 100,\n },\n /** Sets the starting value of the slider */\n slider_start: {\n type: ParameterType.INT,\n default: 50,\n },\n /** Sets the step of the slider. This is the smallest amount by which the slider can change. */\n step: {\n type: ParameterType.INT,\n default: 1,\n },\n /** Labels displayed at equidistant locations on the slider. For example, two labels will be placed at the ends of the\n * slider. Three labels would place two at the ends and one in the middle. Four will place two at the ends, and the\n * other two will be at 33% and 67% of the slider width.\n */\n labels: {\n type: ParameterType.HTML_STRING,\n default: [],\n array: true,\n },\n /** Set the width of the slider in pixels. If left null, then the width will be equal to the widest element in the display. */\n slider_width: {\n type: ParameterType.INT,\n default: null,\n },\n /** Label of the button to end the trial. */\n button_label: {\n type: ParameterType.STRING,\n default: \"Continue\",\n array: false,\n },\n /** If true, the participant must move the slider before clicking the continue button. */\n require_movement: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is\n * that it can be used to provide a reminder about the action the participant is supposed to take (e.g., which key to press).\n */\n prompt: {\n type: ParameterType.HTML_STRING,\n default: null,\n },\n /** How long to wait for the participant to make a response before ending the trial in milliseconds. If\n * the participant fails to make a response before this timer is reached, the participant's response will be\n * recorded as null for the trial and the trial will end. If the value of this parameter is null, then the trial\n * will wait for a response indefinitely.\n */\n trial_duration: {\n type: ParameterType.INT,\n default: null,\n },\n /** If true, then the trial will end whenever the participant makes a response (assuming they make their response\n * before the cutoff specified by the `trial_duration` parameter). If false, then the trial will continue until the\n * value for `trial_duration` is reached. You can set this parameter to `false` to force the participant to listen to\n * the stimulus for a fixed amount of time, even if they respond before the time is complete.\n */\n response_ends_trial: {\n type: ParameterType.BOOL,\n default: true,\n },\n /** If true, then the trial will end as soon as the audio file finishes playing. */\n trial_ends_after_audio: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** If true, then responses are allowed while the audio is playing. If false, then the audio must finish playing before\n * the slider is enabled and the trial can end via the next button click. Once the audio has played all the way through,\n * the slider is enabled and a response is allowed (including while the audio is being re-played via on-screen playback controls).\n */\n response_allowed_while_playing: {\n type: ParameterType.BOOL,\n default: true,\n },\n },\n data: {\n /** The numeric value of the slider. */\n response: {\n type: ParameterType.INT,\n },\n /** The time in milliseconds for the participant to make a response. The time is measured from when the stimulus first\n * began playing until the participant's response.\n */\n rt: {\n type: ParameterType.INT,\n },\n /** The path of the audio file that was played. */\n stimulus: {\n type: ParameterType.STRING,\n },\n /** The starting value of the slider. */\n slider_start: {\n type: ParameterType.INT,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * This plugin plays an audio file and allows the participant to respond by dragging a slider.\n *\n * If the browser supports it, audio files are played using the WebAudio API. This allows for reasonably precise timing of the\n * playback. The timing of responses generated is measured against the WebAudio specific clock, improving the measurement of\n * response times. If the browser does not support the WebAudio API, then the audio file is played with HTML5 audio.\n *\n * Audio files can be automatically preloaded by jsPsych using the [`preload` plugin](preload.md). However, if you are using\n * timeline variables or another dynamic method to specify the audio stimulus, then you will need\n * to [manually preload](../overview/media-preloading.md#manual-preloading) the audio.\n *\n * The trial can end when the participant responds, or if the participant has failed to respond within a fixed length of time. You can also prevent the slider response from being made before the audio has finished playing.\n * @author Josh de Leeuw\n * @see {@link https://www.jspsych.org/latest/plugins/audio-slider-response/ audio-slider-response plugin documentation on jspsych.org}\n */\nclass AudioSliderResponsePlugin implements JsPsychPlugin<Info> {\n static info = info;\n private audio: AudioPlayerInterface;\n private context: AudioContext;\n private params: TrialType<Info>;\n private display: HTMLElement;\n private response: { rt: number; response: number } = { rt: null, response: null };\n private startTime: number;\n private half_thumb_width: number;\n private trial_complete: (trial_data: {\n rt: number;\n slider_start: number;\n response: number;\n }) => void;\n\n constructor(private jsPsych: JsPsych) {\n autoBind(this);\n }\n\n async trial(display_element: HTMLElement, trial: TrialType<Info>, on_load: () => void) {\n this.params = trial;\n this.display = display_element;\n // for storing data related to response\n this.response;\n // half of the thumb width value from jspsych.css, used to adjust the label positions\n this.half_thumb_width = 7.5;\n // hold the .resolve() function from the Promise that ends the trial\n this.trial_complete;\n\n // setup stimulus\n this.context = this.jsPsych.pluginAPI.audioContext();\n\n // load audio file\n this.audio = await this.jsPsych.pluginAPI.getAudioPlayer(trial.stimulus);\n\n this.setupTrial();\n\n on_load();\n\n return new Promise((resolve) => {\n this.trial_complete = resolve;\n });\n }\n\n // to enable slider after audio ends\n private enable_slider() {\n document.querySelector<HTMLInputElement>(\"#jspsych-audio-slider-response-response\").disabled =\n false;\n if (!this.params.require_movement) {\n document.querySelector<HTMLButtonElement>(\"#jspsych-audio-slider-response-next\").disabled =\n false;\n }\n }\n\n private setupTrial = () => {\n // set up end event if trial needs it\n if (this.params.trial_ends_after_audio) {\n this.audio.addEventListener(\"ended\", this.end_trial);\n }\n\n // enable slider after audio ends if necessary\n if (!this.params.response_allowed_while_playing && !this.params.trial_ends_after_audio) {\n this.audio.addEventListener(\"ended\", this.enable_slider);\n }\n\n var html = '<div id=\"jspsych-audio-slider-response-wrapper\" style=\"margin: 100px 0px;\">';\n html +=\n '<div class=\"jspsych-audio-slider-response-container\" style=\"position:relative; margin: 0 auto 3em auto; width:';\n if (this.params.slider_width !== null) {\n html += this.params.slider_width + \"px;\";\n } else {\n html += \"auto;\";\n }\n html += '\">';\n html +=\n '<input type=\"range\" class=\"jspsych-slider\" value=\"' +\n this.params.slider_start +\n '\" min=\"' +\n this.params.min +\n '\" max=\"' +\n this.params.max +\n '\" step=\"' +\n this.params.step +\n '\" id=\"jspsych-audio-slider-response-response\"';\n if (!this.params.response_allowed_while_playing) {\n html += \" disabled\";\n }\n html += \"></input><div>\";\n for (var j = 0; j < this.params.labels.length; j++) {\n var label_width_perc = 100 / (this.params.labels.length - 1);\n var percent_of_range = j * (100 / (this.params.labels.length - 1));\n var percent_dist_from_center = ((percent_of_range - 50) / 50) * 100;\n var offset = (percent_dist_from_center * this.half_thumb_width) / 100;\n html +=\n '<div style=\"border: 1px solid transparent; display: inline-block; position: absolute; ' +\n \"left:calc(\" +\n percent_of_range +\n \"% - (\" +\n label_width_perc +\n \"% / 2) - \" +\n offset +\n \"px); text-align: center; width: \" +\n label_width_perc +\n '%;\">';\n html +=\n '<span style=\"text-align: center; font-size: 80%;\">' + this.params.labels[j] + \"</span>\";\n html += \"</div>\";\n }\n html += \"</div>\";\n html += \"</div>\";\n html += \"</div>\";\n\n if (this.params.prompt !== null) {\n html += this.params.prompt;\n }\n\n // add submit button\n var next_disabled_attribute = \"\";\n if (this.params.require_movement || !this.params.response_allowed_while_playing) {\n next_disabled_attribute = \"disabled\";\n }\n html +=\n '<button id=\"jspsych-audio-slider-response-next\" class=\"jspsych-btn\" ' +\n next_disabled_attribute +\n \">\" +\n this.params.button_label +\n \"</button>\";\n\n this.display.innerHTML = html;\n\n this.response = {\n rt: null,\n response: null,\n };\n\n if (!this.params.response_allowed_while_playing) {\n this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-response\"\n ).disabled = true;\n this.display.querySelector<HTMLInputElement>(\"#jspsych-audio-slider-response-next\").disabled =\n true;\n }\n\n if (this.params.require_movement) {\n const enable_button = () => {\n this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-next\"\n ).disabled = false;\n };\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-response\")\n .addEventListener(\"mousedown\", enable_button);\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-response\")\n .addEventListener(\"touchstart\", enable_button);\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-response\")\n .addEventListener(\"change\", enable_button);\n }\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-next\")\n .addEventListener(\"click\", () => {\n // measure response time\n var endTime = performance.now();\n var rt = Math.round(endTime - this.startTime);\n if (this.context !== null) {\n endTime = this.context.currentTime;\n rt = Math.round((endTime - this.startTime) * 1000);\n }\n this.response.rt = rt;\n this.response.response = this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-response\"\n ).valueAsNumber;\n\n if (this.params.response_ends_trial) {\n this.end_trial();\n } else {\n this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-next\"\n ).disabled = true;\n }\n });\n\n //record start time\n this.startTime = performance.now();\n // record webaudio context start time\n if (this.context !== null) {\n this.startTime = this.context.currentTime;\n }\n\n // start audio\n this.audio.play();\n\n // end trial if trial_duration is set\n if (this.params.trial_duration !== null) {\n this.jsPsych.pluginAPI.setTimeout(() => {\n this.end_trial();\n }, this.params.trial_duration);\n }\n };\n\n private end_trial = () => {\n // kill any remaining setTimeout handlers\n this.jsPsych.pluginAPI.clearAllTimeouts();\n\n // stop the audio file if it is playing\n this.audio.stop();\n\n // remove end event listeners if they exist\n this.audio.removeEventListener(\"ended\", this.end_trial);\n this.audio.removeEventListener(\"ended\", this.enable_slider);\n\n // save data\n var trialdata = {\n rt: this.response.rt,\n stimulus: this.params.stimulus,\n slider_start: this.params.slider_start,\n response: this.response.response,\n };\n\n this.display.innerHTML = \"\";\n\n // next trial\n this.trial_complete(trialdata);\n };\n\n simulate(\n trial: TrialType<Info>,\n simulation_mode,\n simulation_options: any,\n load_callback: () => void\n ) {\n if (simulation_mode == \"data-only\") {\n load_callback();\n this.simulate_data_only(trial, simulation_options);\n }\n if (simulation_mode == \"visual\") {\n this.simulate_visual(trial, simulation_options, load_callback);\n }\n }\n\n private create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const default_data = {\n stimulus: trial.stimulus,\n slider_start: trial.slider_start,\n response: this.jsPsych.randomization.randomInt(trial.min, trial.max),\n rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),\n };\n\n const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);\n\n this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);\n\n return data;\n }\n\n private simulate_data_only(trial: TrialType<Info>, simulation_options) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n this.jsPsych.finishTrial(data);\n }\n\n private simulate_visual(trial: TrialType<Info>, simulation_options, load_callback: () => void) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n const display_element = this.jsPsych.getDisplayElement();\n\n const respond = () => {\n if (data.rt !== null) {\n const el = display_element.querySelector<HTMLInputElement>(\"input[type='range']\");\n\n setTimeout(() => {\n this.jsPsych.pluginAPI.clickTarget(el);\n el.valueAsNumber = data.response;\n }, data.rt / 2);\n\n this.jsPsych.pluginAPI.clickTarget(display_element.querySelector(\"button\"), data.rt);\n }\n };\n\n this.trial(display_element, trial, () => {\n load_callback();\n\n if (!trial.response_allowed_while_playing) {\n this.audio.addEventListener(\"ended\", respond);\n } else {\n respond();\n }\n });\n }\n}\n\nexport default AudioSliderResponsePlugin;\n"],"names":["getAllProperties","object","properties","key","autoBind","self","include","exclude","filter","match","pattern","descriptor","info","version","ParameterType","AudioSliderResponsePlugin","jsPsych","html","j","label_width_perc","percent_of_range","percent_dist_from_center","offset","next_disabled_attribute","enable_button","endTime","rt","trialdata","display_element","trial","on_load","__async","resolve","simulation_mode","simulation_options","load_callback","default_data","data","respond","el"],"mappings":"4JAGA,MAAMA,EAAmBC,GAAU,CAClC,MAAMC,EAAa,IAAI,IAEvB,EACC,WAAWC,KAAO,QAAQ,QAAQF,CAAM,EACvCC,EAAW,IAAI,CAACD,EAAQE,CAAG,CAAC,SAEpBF,EAAS,QAAQ,eAAeA,CAAM,IAAMA,IAAW,OAAO,WAExE,OAAOC,CACR,MAEAE,EAAiB,CAACC,EAAM,CAAC,QAAAC,EAAS,QAAAC,CAAO,EAAI,CAAA,IAAO,CACnD,MAAMC,EAASL,GAAO,CACrB,MAAMM,EAAQC,GAAW,OAAOA,GAAY,SAAWP,IAAQO,EAAUA,EAAQ,KAAKP,CAAG,EAEzF,OAAIG,EACIA,EAAQ,KAAKG,CAAK,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AAA,KAAK,QAAQ,UAAU,gCAAgCL,EAAOQ,CAAI,EAE3DA,CACT,CAEQ,mBAAmBR,EAAwBK,EAAoB,CACrE,MAAMG,EAAO,KAAK,uBAAuBR,EAAOK,CAAkB,EAElE,KAAK,QAAQ,YAAYG,CAAI,CAC/B,CAEQ,gBAAgBR,EAAwBK,EAAoBC,EAA2B,CAC7F,MAAME,EAAO,KAAK,uBAAuBR,EAAOK,CAAkB,EAE5DN,EAAkB,KAAK,QAAQ,kBAAkB,EAEjDU,EAAU,IAAM,CACpB,GAAID,EAAK,KAAO,KAAM,CACpB,MAAME,EAAKX,EAAgB,cAAgC,qBAAqB,EAEhF,WAAW,IAAM,CACf,KAAK,QAAQ,UAAU,YAAYW,CAAE,EACrCA,EAAG,cAAgBF,EAAK,QAC1B,EAAGA,EAAK,GAAK,CAAC,EAEd,KAAK,QAAQ,UAAU,YAAYT,EAAgB,cAAc,QAAQ,EAAGS,EAAK,EAAE,CACrF,CACF,EAEA,KAAK,MAAMT,EAAiBC,EAAO,IAAM,CACvCM,EAAAA,EAEKN,EAAM,+BAGTS,EAAQ,EAFR,KAAK,MAAM,iBAAiB,QAASA,CAAO,CAIhD,CAAC,CACH,CACF,CAtSMvB,OAAAA,EACG,KAAOH"}
|
package/dist/index.cjs
CHANGED
|
@@ -5,7 +5,7 @@ var jspsych = require('jspsych');
|
|
|
5
5
|
|
|
6
6
|
var _package = {
|
|
7
7
|
name: "@jspsych/plugin-audio-slider-response",
|
|
8
|
-
version: "2.0.
|
|
8
|
+
version: "2.0.1",
|
|
9
9
|
description: "",
|
|
10
10
|
type: "module",
|
|
11
11
|
main: "dist/index.cjs",
|
|
@@ -210,6 +210,9 @@ class AudioSliderResponsePlugin {
|
|
|
210
210
|
}
|
|
211
211
|
});
|
|
212
212
|
this.startTime = performance.now();
|
|
213
|
+
if (this.context !== null) {
|
|
214
|
+
this.startTime = this.context.currentTime;
|
|
215
|
+
}
|
|
213
216
|
this.audio.play();
|
|
214
217
|
if (this.params.trial_duration !== null) {
|
|
215
218
|
this.jsPsych.pluginAPI.setTimeout(() => {
|
|
@@ -234,7 +237,6 @@ class AudioSliderResponsePlugin {
|
|
|
234
237
|
autoBind(this);
|
|
235
238
|
}
|
|
236
239
|
async trial(display_element, trial, on_load) {
|
|
237
|
-
this.startTime;
|
|
238
240
|
this.params = trial;
|
|
239
241
|
this.display = display_element;
|
|
240
242
|
this.response;
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["import autoBind from \"auto-bind\";\nimport { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { AudioPlayerInterface } from \"../../jspsych/src/modules/plugin-api/AudioPlayer\";\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"audio-slider-response\",\n version: version,\n parameters: {\n /** Audio file to be played. */\n stimulus: {\n type: ParameterType.AUDIO,\n default: undefined,\n },\n /** Sets the minimum value of the slider. */\n min: {\n type: ParameterType.INT,\n default: 0,\n },\n /** Sets the maximum value of the slider */\n max: {\n type: ParameterType.INT,\n default: 100,\n },\n /** Sets the starting value of the slider */\n slider_start: {\n type: ParameterType.INT,\n default: 50,\n },\n /** Sets the step of the slider. This is the smallest amount by which the slider can change. */\n step: {\n type: ParameterType.INT,\n default: 1,\n },\n /** Labels displayed at equidistant locations on the slider. For example, two labels will be placed at the ends of the\n * slider. Three labels would place two at the ends and one in the middle. Four will place two at the ends, and the\n * other two will be at 33% and 67% of the slider width.\n */\n labels: {\n type: ParameterType.HTML_STRING,\n default: [],\n array: true,\n },\n /** Set the width of the slider in pixels. If left null, then the width will be equal to the widest element in the display. */\n slider_width: {\n type: ParameterType.INT,\n default: null,\n },\n /** Label of the button to end the trial. */\n button_label: {\n type: ParameterType.STRING,\n default: \"Continue\",\n array: false,\n },\n /** If true, the participant must move the slider before clicking the continue button. */\n require_movement: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is\n * that it can be used to provide a reminder about the action the participant is supposed to take (e.g., which key to press).\n */\n prompt: {\n type: ParameterType.HTML_STRING,\n default: null,\n },\n /** How long to wait for the participant to make a response before ending the trial in milliseconds. If\n * the participant fails to make a response before this timer is reached, the participant's response will be\n * recorded as null for the trial and the trial will end. If the value of this parameter is null, then the trial\n * will wait for a response indefinitely.\n */\n trial_duration: {\n type: ParameterType.INT,\n default: null,\n },\n /** If true, then the trial will end whenever the participant makes a response (assuming they make their response\n * before the cutoff specified by the `trial_duration` parameter). If false, then the trial will continue until the\n * value for `trial_duration` is reached. You can set this parameter to `false` to force the participant to listen to\n * the stimulus for a fixed amount of time, even if they respond before the time is complete.\n */\n response_ends_trial: {\n type: ParameterType.BOOL,\n default: true,\n },\n /** If true, then the trial will end as soon as the audio file finishes playing. */\n trial_ends_after_audio: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** If true, then responses are allowed while the audio is playing. If false, then the audio must finish playing before\n * the slider is enabled and the trial can end via the next button click. Once the audio has played all the way through,\n * the slider is enabled and a response is allowed (including while the audio is being re-played via on-screen playback controls).\n */\n response_allowed_while_playing: {\n type: ParameterType.BOOL,\n default: true,\n },\n },\n data: {\n /** The numeric value of the slider. */\n response: {\n type: ParameterType.INT,\n },\n /** The time in milliseconds for the participant to make a response. The time is measured from when the stimulus first\n * began playing until the participant's response.\n */\n rt: {\n type: ParameterType.INT,\n },\n /** The path of the audio file that was played. */\n stimulus: {\n type: ParameterType.STRING,\n },\n /** The starting value of the slider. */\n slider_start: {\n type: ParameterType.INT,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * This plugin plays an audio file and allows the participant to respond by dragging a slider.\n *\n * If the browser supports it, audio files are played using the WebAudio API. This allows for reasonably precise timing of the\n * playback. The timing of responses generated is measured against the WebAudio specific clock, improving the measurement of\n * response times. If the browser does not support the WebAudio API, then the audio file is played with HTML5 audio.\n *\n * Audio files can be automatically preloaded by jsPsych using the [`preload` plugin](preload.md). However, if you are using\n * timeline variables or another dynamic method to specify the audio stimulus, then you will need\n * to [manually preload](../overview/media-preloading.md#manual-preloading) the audio.\n *\n * The trial can end when the participant responds, or if the participant has failed to respond within a fixed length of time. You can also prevent the slider response from being made before the audio has finished playing.\n * @author Josh de Leeuw\n * @see {@link https://www.jspsych.org/latest/plugins/audio-slider-response/ audio-slider-response plugin documentation on jspsych.org}\n */\nclass AudioSliderResponsePlugin implements JsPsychPlugin<Info> {\n static info = info;\n private audio: AudioPlayerInterface;\n private context: AudioContext;\n private params: TrialType<Info>;\n private display: HTMLElement;\n private response: { rt: number; response: number } = { rt: null, response: null };\n private startTime: number;\n private half_thumb_width: number;\n private trial_complete: (trial_data: {\n rt: number;\n slider_start: number;\n response: number;\n }) => void;\n\n constructor(private jsPsych: JsPsych) {\n autoBind(this);\n }\n\n async trial(display_element: HTMLElement, trial: TrialType<Info>, on_load: () => void) {\n // record webaudio context start time\n this.startTime;\n this.params = trial;\n this.display = display_element;\n // for storing data related to response\n this.response;\n // half of the thumb width value from jspsych.css, used to adjust the label positions\n this.half_thumb_width = 7.5;\n // hold the .resolve() function from the Promise that ends the trial\n this.trial_complete;\n\n // setup stimulus\n this.context = this.jsPsych.pluginAPI.audioContext();\n\n // load audio file\n this.audio = await this.jsPsych.pluginAPI.getAudioPlayer(trial.stimulus);\n\n this.setupTrial();\n\n on_load();\n\n return new Promise((resolve) => {\n this.trial_complete = resolve;\n });\n }\n\n // to enable slider after audio ends\n private enable_slider() {\n document.querySelector<HTMLInputElement>(\"#jspsych-audio-slider-response-response\").disabled =\n false;\n if (!this.params.require_movement) {\n document.querySelector<HTMLButtonElement>(\"#jspsych-audio-slider-response-next\").disabled =\n false;\n }\n }\n\n private setupTrial = () => {\n // set up end event if trial needs it\n if (this.params.trial_ends_after_audio) {\n this.audio.addEventListener(\"ended\", this.end_trial);\n }\n\n // enable slider after audio ends if necessary\n if (!this.params.response_allowed_while_playing && !this.params.trial_ends_after_audio) {\n this.audio.addEventListener(\"ended\", this.enable_slider);\n }\n\n var html = '<div id=\"jspsych-audio-slider-response-wrapper\" style=\"margin: 100px 0px;\">';\n html +=\n '<div class=\"jspsych-audio-slider-response-container\" style=\"position:relative; margin: 0 auto 3em auto; width:';\n if (this.params.slider_width !== null) {\n html += this.params.slider_width + \"px;\";\n } else {\n html += \"auto;\";\n }\n html += '\">';\n html +=\n '<input type=\"range\" class=\"jspsych-slider\" value=\"' +\n this.params.slider_start +\n '\" min=\"' +\n this.params.min +\n '\" max=\"' +\n this.params.max +\n '\" step=\"' +\n this.params.step +\n '\" id=\"jspsych-audio-slider-response-response\"';\n if (!this.params.response_allowed_while_playing) {\n html += \" disabled\";\n }\n html += \"></input><div>\";\n for (var j = 0; j < this.params.labels.length; j++) {\n var label_width_perc = 100 / (this.params.labels.length - 1);\n var percent_of_range = j * (100 / (this.params.labels.length - 1));\n var percent_dist_from_center = ((percent_of_range - 50) / 50) * 100;\n var offset = (percent_dist_from_center * this.half_thumb_width) / 100;\n html +=\n '<div style=\"border: 1px solid transparent; display: inline-block; position: absolute; ' +\n \"left:calc(\" +\n percent_of_range +\n \"% - (\" +\n label_width_perc +\n \"% / 2) - \" +\n offset +\n \"px); text-align: center; width: \" +\n label_width_perc +\n '%;\">';\n html +=\n '<span style=\"text-align: center; font-size: 80%;\">' + this.params.labels[j] + \"</span>\";\n html += \"</div>\";\n }\n html += \"</div>\";\n html += \"</div>\";\n html += \"</div>\";\n\n if (this.params.prompt !== null) {\n html += this.params.prompt;\n }\n\n // add submit button\n var next_disabled_attribute = \"\";\n if (this.params.require_movement || !this.params.response_allowed_while_playing) {\n next_disabled_attribute = \"disabled\";\n }\n html +=\n '<button id=\"jspsych-audio-slider-response-next\" class=\"jspsych-btn\" ' +\n next_disabled_attribute +\n \">\" +\n this.params.button_label +\n \"</button>\";\n\n this.display.innerHTML = html;\n\n this.response = {\n rt: null,\n response: null,\n };\n\n if (!this.params.response_allowed_while_playing) {\n this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-response\"\n ).disabled = true;\n this.display.querySelector<HTMLInputElement>(\"#jspsych-audio-slider-response-next\").disabled =\n true;\n }\n\n if (this.params.require_movement) {\n const enable_button = () => {\n this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-next\"\n ).disabled = false;\n };\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-response\")\n .addEventListener(\"mousedown\", enable_button);\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-response\")\n .addEventListener(\"touchstart\", enable_button);\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-response\")\n .addEventListener(\"change\", enable_button);\n }\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-next\")\n .addEventListener(\"click\", () => {\n // measure response time\n var endTime = performance.now();\n var rt = Math.round(endTime - this.startTime);\n if (this.context !== null) {\n endTime = this.context.currentTime;\n rt = Math.round((endTime - this.startTime) * 1000);\n }\n this.response.rt = rt;\n this.response.response = this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-response\"\n ).valueAsNumber;\n\n if (this.params.response_ends_trial) {\n this.end_trial();\n } else {\n this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-next\"\n ).disabled = true;\n }\n });\n\n this.startTime = performance.now();\n\n // start audio\n this.audio.play();\n\n // end trial if trial_duration is set\n if (this.params.trial_duration !== null) {\n this.jsPsych.pluginAPI.setTimeout(() => {\n this.end_trial();\n }, this.params.trial_duration);\n }\n };\n\n private end_trial = () => {\n // kill any remaining setTimeout handlers\n this.jsPsych.pluginAPI.clearAllTimeouts();\n\n // stop the audio file if it is playing\n this.audio.stop();\n\n // remove end event listeners if they exist\n this.audio.removeEventListener(\"ended\", this.end_trial);\n this.audio.removeEventListener(\"ended\", this.enable_slider);\n\n // save data\n var trialdata = {\n rt: this.response.rt,\n stimulus: this.params.stimulus,\n slider_start: this.params.slider_start,\n response: this.response.response,\n };\n\n this.display.innerHTML = \"\";\n\n // next trial\n this.trial_complete(trialdata);\n };\n\n simulate(\n trial: TrialType<Info>,\n simulation_mode,\n simulation_options: any,\n load_callback: () => void\n ) {\n if (simulation_mode == \"data-only\") {\n load_callback();\n this.simulate_data_only(trial, simulation_options);\n }\n if (simulation_mode == \"visual\") {\n this.simulate_visual(trial, simulation_options, load_callback);\n }\n }\n\n private create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const default_data = {\n stimulus: trial.stimulus,\n slider_start: trial.slider_start,\n response: this.jsPsych.randomization.randomInt(trial.min, trial.max),\n rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),\n };\n\n const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);\n\n this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);\n\n return data;\n }\n\n private simulate_data_only(trial: TrialType<Info>, simulation_options) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n this.jsPsych.finishTrial(data);\n }\n\n private simulate_visual(trial: TrialType<Info>, simulation_options, load_callback: () => void) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n const display_element = this.jsPsych.getDisplayElement();\n\n const respond = () => {\n if (data.rt !== null) {\n const el = display_element.querySelector<HTMLInputElement>(\"input[type='range']\");\n\n setTimeout(() => {\n this.jsPsych.pluginAPI.clickTarget(el);\n el.valueAsNumber = data.response;\n }, data.rt / 2);\n\n this.jsPsych.pluginAPI.clickTarget(display_element.querySelector(\"button\"), data.rt);\n }\n };\n\n this.trial(display_element, trial, () => {\n load_callback();\n\n if (!trial.response_allowed_while_playing) {\n this.audio.addEventListener(\"ended\", respond);\n } else {\n respond();\n }\n });\n }\n}\n\nexport default AudioSliderResponsePlugin;\n"],"names":["version","ParameterType"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAM,IAAc,GAAA;AAAA,EAClB,IAAM,EAAA,uBAAA;AAAA,WACNA,gBAAA;AAAA,EACA,UAAY,EAAA;AAAA,IAEV,QA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pB,MAAI,IAAA,IAAA,CAAK,OAAO,IAAM,EAAA;AACpB,QAAM,MAAA,EAAA,GAAK,eAAgB,CAAA,aAAA,CAAgC,qBAAqB,CAAA,CAAA;AAEhF,QAAA,UAAA,CAAW,MAAM;AACf,UAAK,IAAA,CAAA,OAAA,CAAQ,SAAU,CAAA,WAAA,CAAY,EAAE,CAAA,CAAA;AACrC,UAAA,EAAA,CAAG,gBAAgB,IAAK,CAAA,QAAA,CAAA;AAAA,SAC1B,EAAG,IAAK,CAAA,EAAA,GAAK,CAAC,CAAA,CAAA;AAEd,QAAK,IAAA,CAAA,OAAA,CAAQ,UAAU,WAAY,CAAA,eAAA,CAAgB,cAAc,QAAQ,CAAA,EAAG,KAAK,EAAE,CAAA,CAAA;AAAA,OACrF;AAAA,KACF,CAAA;AAEA,IAAK,IAAA,CAAA,KAAA,CAAM,eAAiB,EAAA,KAAA,EAAO,MAAM;AACvC,MAAc,aAAA,EAAA,CAAA;AAEd,MAAI,IAAA,CAAC,MAAM,8BAAgC,EAAA;AACzC,QAAK,IAAA,CAAA,KAAA,CAAM,gBAAiB,CAAA,OAAA,EAAS,OAAO,CAAA,CAAA;AAAA,OACvC,MAAA;AACL,QAAQ,OAAA,EAAA,CAAA;AAAA,OACV;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAA;AAnSM,yBAAA,CACG,IAAO,GAAA,IAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["import autoBind from \"auto-bind\";\nimport { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { AudioPlayerInterface } from \"../../jspsych/src/modules/plugin-api/AudioPlayer\";\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"audio-slider-response\",\n version: version,\n parameters: {\n /** Audio file to be played. */\n stimulus: {\n type: ParameterType.AUDIO,\n default: undefined,\n },\n /** Sets the minimum value of the slider. */\n min: {\n type: ParameterType.INT,\n default: 0,\n },\n /** Sets the maximum value of the slider */\n max: {\n type: ParameterType.INT,\n default: 100,\n },\n /** Sets the starting value of the slider */\n slider_start: {\n type: ParameterType.INT,\n default: 50,\n },\n /** Sets the step of the slider. This is the smallest amount by which the slider can change. */\n step: {\n type: ParameterType.INT,\n default: 1,\n },\n /** Labels displayed at equidistant locations on the slider. For example, two labels will be placed at the ends of the\n * slider. Three labels would place two at the ends and one in the middle. Four will place two at the ends, and the\n * other two will be at 33% and 67% of the slider width.\n */\n labels: {\n type: ParameterType.HTML_STRING,\n default: [],\n array: true,\n },\n /** Set the width of the slider in pixels. If left null, then the width will be equal to the widest element in the display. */\n slider_width: {\n type: ParameterType.INT,\n default: null,\n },\n /** Label of the button to end the trial. */\n button_label: {\n type: ParameterType.STRING,\n default: \"Continue\",\n array: false,\n },\n /** If true, the participant must move the slider before clicking the continue button. */\n require_movement: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is\n * that it can be used to provide a reminder about the action the participant is supposed to take (e.g., which key to press).\n */\n prompt: {\n type: ParameterType.HTML_STRING,\n default: null,\n },\n /** How long to wait for the participant to make a response before ending the trial in milliseconds. If\n * the participant fails to make a response before this timer is reached, the participant's response will be\n * recorded as null for the trial and the trial will end. If the value of this parameter is null, then the trial\n * will wait for a response indefinitely.\n */\n trial_duration: {\n type: ParameterType.INT,\n default: null,\n },\n /** If true, then the trial will end whenever the participant makes a response (assuming they make their response\n * before the cutoff specified by the `trial_duration` parameter). If false, then the trial will continue until the\n * value for `trial_duration` is reached. You can set this parameter to `false` to force the participant to listen to\n * the stimulus for a fixed amount of time, even if they respond before the time is complete.\n */\n response_ends_trial: {\n type: ParameterType.BOOL,\n default: true,\n },\n /** If true, then the trial will end as soon as the audio file finishes playing. */\n trial_ends_after_audio: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** If true, then responses are allowed while the audio is playing. If false, then the audio must finish playing before\n * the slider is enabled and the trial can end via the next button click. Once the audio has played all the way through,\n * the slider is enabled and a response is allowed (including while the audio is being re-played via on-screen playback controls).\n */\n response_allowed_while_playing: {\n type: ParameterType.BOOL,\n default: true,\n },\n },\n data: {\n /** The numeric value of the slider. */\n response: {\n type: ParameterType.INT,\n },\n /** The time in milliseconds for the participant to make a response. The time is measured from when the stimulus first\n * began playing until the participant's response.\n */\n rt: {\n type: ParameterType.INT,\n },\n /** The path of the audio file that was played. */\n stimulus: {\n type: ParameterType.STRING,\n },\n /** The starting value of the slider. */\n slider_start: {\n type: ParameterType.INT,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * This plugin plays an audio file and allows the participant to respond by dragging a slider.\n *\n * If the browser supports it, audio files are played using the WebAudio API. This allows for reasonably precise timing of the\n * playback. The timing of responses generated is measured against the WebAudio specific clock, improving the measurement of\n * response times. If the browser does not support the WebAudio API, then the audio file is played with HTML5 audio.\n *\n * Audio files can be automatically preloaded by jsPsych using the [`preload` plugin](preload.md). However, if you are using\n * timeline variables or another dynamic method to specify the audio stimulus, then you will need\n * to [manually preload](../overview/media-preloading.md#manual-preloading) the audio.\n *\n * The trial can end when the participant responds, or if the participant has failed to respond within a fixed length of time. You can also prevent the slider response from being made before the audio has finished playing.\n * @author Josh de Leeuw\n * @see {@link https://www.jspsych.org/latest/plugins/audio-slider-response/ audio-slider-response plugin documentation on jspsych.org}\n */\nclass AudioSliderResponsePlugin implements JsPsychPlugin<Info> {\n static info = info;\n private audio: AudioPlayerInterface;\n private context: AudioContext;\n private params: TrialType<Info>;\n private display: HTMLElement;\n private response: { rt: number; response: number } = { rt: null, response: null };\n private startTime: number;\n private half_thumb_width: number;\n private trial_complete: (trial_data: {\n rt: number;\n slider_start: number;\n response: number;\n }) => void;\n\n constructor(private jsPsych: JsPsych) {\n autoBind(this);\n }\n\n async trial(display_element: HTMLElement, trial: TrialType<Info>, on_load: () => void) {\n this.params = trial;\n this.display = display_element;\n // for storing data related to response\n this.response;\n // half of the thumb width value from jspsych.css, used to adjust the label positions\n this.half_thumb_width = 7.5;\n // hold the .resolve() function from the Promise that ends the trial\n this.trial_complete;\n\n // setup stimulus\n this.context = this.jsPsych.pluginAPI.audioContext();\n\n // load audio file\n this.audio = await this.jsPsych.pluginAPI.getAudioPlayer(trial.stimulus);\n\n this.setupTrial();\n\n on_load();\n\n return new Promise((resolve) => {\n this.trial_complete = resolve;\n });\n }\n\n // to enable slider after audio ends\n private enable_slider() {\n document.querySelector<HTMLInputElement>(\"#jspsych-audio-slider-response-response\").disabled =\n false;\n if (!this.params.require_movement) {\n document.querySelector<HTMLButtonElement>(\"#jspsych-audio-slider-response-next\").disabled =\n false;\n }\n }\n\n private setupTrial = () => {\n // set up end event if trial needs it\n if (this.params.trial_ends_after_audio) {\n this.audio.addEventListener(\"ended\", this.end_trial);\n }\n\n // enable slider after audio ends if necessary\n if (!this.params.response_allowed_while_playing && !this.params.trial_ends_after_audio) {\n this.audio.addEventListener(\"ended\", this.enable_slider);\n }\n\n var html = '<div id=\"jspsych-audio-slider-response-wrapper\" style=\"margin: 100px 0px;\">';\n html +=\n '<div class=\"jspsych-audio-slider-response-container\" style=\"position:relative; margin: 0 auto 3em auto; width:';\n if (this.params.slider_width !== null) {\n html += this.params.slider_width + \"px;\";\n } else {\n html += \"auto;\";\n }\n html += '\">';\n html +=\n '<input type=\"range\" class=\"jspsych-slider\" value=\"' +\n this.params.slider_start +\n '\" min=\"' +\n this.params.min +\n '\" max=\"' +\n this.params.max +\n '\" step=\"' +\n this.params.step +\n '\" id=\"jspsych-audio-slider-response-response\"';\n if (!this.params.response_allowed_while_playing) {\n html += \" disabled\";\n }\n html += \"></input><div>\";\n for (var j = 0; j < this.params.labels.length; j++) {\n var label_width_perc = 100 / (this.params.labels.length - 1);\n var percent_of_range = j * (100 / (this.params.labels.length - 1));\n var percent_dist_from_center = ((percent_of_range - 50) / 50) * 100;\n var offset = (percent_dist_from_center * this.half_thumb_width) / 100;\n html +=\n '<div style=\"border: 1px solid transparent; display: inline-block; position: absolute; ' +\n \"left:calc(\" +\n percent_of_range +\n \"% - (\" +\n label_width_perc +\n \"% / 2) - \" +\n offset +\n \"px); text-align: center; width: \" +\n label_width_perc +\n '%;\">';\n html +=\n '<span style=\"text-align: center; font-size: 80%;\">' + this.params.labels[j] + \"</span>\";\n html += \"</div>\";\n }\n html += \"</div>\";\n html += \"</div>\";\n html += \"</div>\";\n\n if (this.params.prompt !== null) {\n html += this.params.prompt;\n }\n\n // add submit button\n var next_disabled_attribute = \"\";\n if (this.params.require_movement || !this.params.response_allowed_while_playing) {\n next_disabled_attribute = \"disabled\";\n }\n html +=\n '<button id=\"jspsych-audio-slider-response-next\" class=\"jspsych-btn\" ' +\n next_disabled_attribute +\n \">\" +\n this.params.button_label +\n \"</button>\";\n\n this.display.innerHTML = html;\n\n this.response = {\n rt: null,\n response: null,\n };\n\n if (!this.params.response_allowed_while_playing) {\n this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-response\"\n ).disabled = true;\n this.display.querySelector<HTMLInputElement>(\"#jspsych-audio-slider-response-next\").disabled =\n true;\n }\n\n if (this.params.require_movement) {\n const enable_button = () => {\n this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-next\"\n ).disabled = false;\n };\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-response\")\n .addEventListener(\"mousedown\", enable_button);\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-response\")\n .addEventListener(\"touchstart\", enable_button);\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-response\")\n .addEventListener(\"change\", enable_button);\n }\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-next\")\n .addEventListener(\"click\", () => {\n // measure response time\n var endTime = performance.now();\n var rt = Math.round(endTime - this.startTime);\n if (this.context !== null) {\n endTime = this.context.currentTime;\n rt = Math.round((endTime - this.startTime) * 1000);\n }\n this.response.rt = rt;\n this.response.response = this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-response\"\n ).valueAsNumber;\n\n if (this.params.response_ends_trial) {\n this.end_trial();\n } else {\n this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-next\"\n ).disabled = true;\n }\n });\n\n //record start time\n this.startTime = performance.now();\n // record webaudio context start time\n if (this.context !== null) {\n this.startTime = this.context.currentTime;\n }\n\n // start audio\n this.audio.play();\n\n // end trial if trial_duration is set\n if (this.params.trial_duration !== null) {\n this.jsPsych.pluginAPI.setTimeout(() => {\n this.end_trial();\n }, this.params.trial_duration);\n }\n };\n\n private end_trial = () => {\n // kill any remaining setTimeout handlers\n this.jsPsych.pluginAPI.clearAllTimeouts();\n\n // stop the audio file if it is playing\n this.audio.stop();\n\n // remove end event listeners if they exist\n this.audio.removeEventListener(\"ended\", this.end_trial);\n this.audio.removeEventListener(\"ended\", this.enable_slider);\n\n // save data\n var trialdata = {\n rt: this.response.rt,\n stimulus: this.params.stimulus,\n slider_start: this.params.slider_start,\n response: this.response.response,\n };\n\n this.display.innerHTML = \"\";\n\n // next trial\n this.trial_complete(trialdata);\n };\n\n simulate(\n trial: TrialType<Info>,\n simulation_mode,\n simulation_options: any,\n load_callback: () => void\n ) {\n if (simulation_mode == \"data-only\") {\n load_callback();\n this.simulate_data_only(trial, simulation_options);\n }\n if (simulation_mode == \"visual\") {\n this.simulate_visual(trial, simulation_options, load_callback);\n }\n }\n\n private create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const default_data = {\n stimulus: trial.stimulus,\n slider_start: trial.slider_start,\n response: this.jsPsych.randomization.randomInt(trial.min, trial.max),\n rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),\n };\n\n const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);\n\n this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);\n\n return data;\n }\n\n private simulate_data_only(trial: TrialType<Info>, simulation_options) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n this.jsPsych.finishTrial(data);\n }\n\n private simulate_visual(trial: TrialType<Info>, simulation_options, load_callback: () => void) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n const display_element = this.jsPsych.getDisplayElement();\n\n const respond = () => {\n if (data.rt !== null) {\n const el = display_element.querySelector<HTMLInputElement>(\"input[type='range']\");\n\n setTimeout(() => {\n this.jsPsych.pluginAPI.clickTarget(el);\n el.valueAsNumber = data.response;\n }, data.rt / 2);\n\n this.jsPsych.pluginAPI.clickTarget(display_element.querySelector(\"button\"), data.rt);\n }\n };\n\n this.trial(display_element, trial, () => {\n load_callback();\n\n if (!trial.response_allowed_while_playing) {\n this.audio.addEventListener(\"ended\", respond);\n } else {\n respond();\n }\n });\n }\n}\n\nexport default AudioSliderResponsePlugin;\n"],"names":["version","ParameterType"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAM,IAAc,GAAA;AAAA,EAClB,IAAM,EAAA,uBAAA;AAAA,WACNA,gBAAA;AAAA,EACA,UAAY,EAAA;AAAA,IAEV,QAAU,EAAA;AAAA,MACR,MAAMC,qBAAc,CAAA,KAAA;AAAA,MACpB,OAAS,EAAA,KAAA,CAAA;AAAA,KACX;AAAA,IAEA,GAAK,EAAA;AAAA,MACH,MAAMA,qBAAc,CAAA,GAAA;AAAA,MACpB,OAAS,EAAA,CAAA;AAAA,KACX;AAAA,IAEA,GAAK,EAAA;AAAA,MACH,MAAMA,qBAAc,CAAA,GAAA;AAAA,MACpB,OAAS,EAAA,GAAA;AAAA,KACX;AAAA,IAEA,YAAc,EAAA;AAAA,MACZ,MAAMA,qBAAc,CAAA,GAAA;AAAA,MACpB,OAAS,EAAA,EAAA;AAAA,KACX;AAAA,IAEA,IAAM,EAAA;AAAA,MACJ,MAAMA,qBAAc,CAAA,GAAA;AAAA,MACpB,OAAS,EAAA,CAAA;AAAA,KACX;AAAA,IAKA,MAAQ,EAAA;AAAA,MACN,MAAMA,qBAAc,CAAA,WAAA;AAAA,MACpB,SAAS,EAAC;AAAA,MACV,KAAO,EAAA,IAAA;AAAA,KAC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B,EAAA,KAAA,EAAO,MAAM;AACvC,MAAc,aAAA,EAAA,CAAA;AAEd,MAAI,IAAA,CAAC,MAAM,8BAAgC,EAAA;AACzC,QAAK,IAAA,CAAA,KAAA,CAAM,gBAAiB,CAAA,OAAA,EAAS,OAAO,CAAA,CAAA;AAAA,OACvC,MAAA;AACL,QAAQ,OAAA,EAAA,CAAA;AAAA,OACV;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAA;AAtSM,yBAAA,CACG,IAAO,GAAA,IAAA;;;;"}
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { ParameterType } from 'jspsych';
|
|
|
3
3
|
|
|
4
4
|
var _package = {
|
|
5
5
|
name: "@jspsych/plugin-audio-slider-response",
|
|
6
|
-
version: "2.0.
|
|
6
|
+
version: "2.0.1",
|
|
7
7
|
description: "",
|
|
8
8
|
type: "module",
|
|
9
9
|
main: "dist/index.cjs",
|
|
@@ -208,6 +208,9 @@ class AudioSliderResponsePlugin {
|
|
|
208
208
|
}
|
|
209
209
|
});
|
|
210
210
|
this.startTime = performance.now();
|
|
211
|
+
if (this.context !== null) {
|
|
212
|
+
this.startTime = this.context.currentTime;
|
|
213
|
+
}
|
|
211
214
|
this.audio.play();
|
|
212
215
|
if (this.params.trial_duration !== null) {
|
|
213
216
|
this.jsPsych.pluginAPI.setTimeout(() => {
|
|
@@ -232,7 +235,6 @@ class AudioSliderResponsePlugin {
|
|
|
232
235
|
autoBind(this);
|
|
233
236
|
}
|
|
234
237
|
async trial(display_element, trial, on_load) {
|
|
235
|
-
this.startTime;
|
|
236
238
|
this.params = trial;
|
|
237
239
|
this.display = display_element;
|
|
238
240
|
this.response;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import autoBind from \"auto-bind\";\nimport { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { AudioPlayerInterface } from \"../../jspsych/src/modules/plugin-api/AudioPlayer\";\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"audio-slider-response\",\n version: version,\n parameters: {\n /** Audio file to be played. */\n stimulus: {\n type: ParameterType.AUDIO,\n default: undefined,\n },\n /** Sets the minimum value of the slider. */\n min: {\n type: ParameterType.INT,\n default: 0,\n },\n /** Sets the maximum value of the slider */\n max: {\n type: ParameterType.INT,\n default: 100,\n },\n /** Sets the starting value of the slider */\n slider_start: {\n type: ParameterType.INT,\n default: 50,\n },\n /** Sets the step of the slider. This is the smallest amount by which the slider can change. */\n step: {\n type: ParameterType.INT,\n default: 1,\n },\n /** Labels displayed at equidistant locations on the slider. For example, two labels will be placed at the ends of the\n * slider. Three labels would place two at the ends and one in the middle. Four will place two at the ends, and the\n * other two will be at 33% and 67% of the slider width.\n */\n labels: {\n type: ParameterType.HTML_STRING,\n default: [],\n array: true,\n },\n /** Set the width of the slider in pixels. If left null, then the width will be equal to the widest element in the display. */\n slider_width: {\n type: ParameterType.INT,\n default: null,\n },\n /** Label of the button to end the trial. */\n button_label: {\n type: ParameterType.STRING,\n default: \"Continue\",\n array: false,\n },\n /** If true, the participant must move the slider before clicking the continue button. */\n require_movement: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is\n * that it can be used to provide a reminder about the action the participant is supposed to take (e.g., which key to press).\n */\n prompt: {\n type: ParameterType.HTML_STRING,\n default: null,\n },\n /** How long to wait for the participant to make a response before ending the trial in milliseconds. If\n * the participant fails to make a response before this timer is reached, the participant's response will be\n * recorded as null for the trial and the trial will end. If the value of this parameter is null, then the trial\n * will wait for a response indefinitely.\n */\n trial_duration: {\n type: ParameterType.INT,\n default: null,\n },\n /** If true, then the trial will end whenever the participant makes a response (assuming they make their response\n * before the cutoff specified by the `trial_duration` parameter). If false, then the trial will continue until the\n * value for `trial_duration` is reached. You can set this parameter to `false` to force the participant to listen to\n * the stimulus for a fixed amount of time, even if they respond before the time is complete.\n */\n response_ends_trial: {\n type: ParameterType.BOOL,\n default: true,\n },\n /** If true, then the trial will end as soon as the audio file finishes playing. */\n trial_ends_after_audio: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** If true, then responses are allowed while the audio is playing. If false, then the audio must finish playing before\n * the slider is enabled and the trial can end via the next button click. Once the audio has played all the way through,\n * the slider is enabled and a response is allowed (including while the audio is being re-played via on-screen playback controls).\n */\n response_allowed_while_playing: {\n type: ParameterType.BOOL,\n default: true,\n },\n },\n data: {\n /** The numeric value of the slider. */\n response: {\n type: ParameterType.INT,\n },\n /** The time in milliseconds for the participant to make a response. The time is measured from when the stimulus first\n * began playing until the participant's response.\n */\n rt: {\n type: ParameterType.INT,\n },\n /** The path of the audio file that was played. */\n stimulus: {\n type: ParameterType.STRING,\n },\n /** The starting value of the slider. */\n slider_start: {\n type: ParameterType.INT,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * This plugin plays an audio file and allows the participant to respond by dragging a slider.\n *\n * If the browser supports it, audio files are played using the WebAudio API. This allows for reasonably precise timing of the\n * playback. The timing of responses generated is measured against the WebAudio specific clock, improving the measurement of\n * response times. If the browser does not support the WebAudio API, then the audio file is played with HTML5 audio.\n *\n * Audio files can be automatically preloaded by jsPsych using the [`preload` plugin](preload.md). However, if you are using\n * timeline variables or another dynamic method to specify the audio stimulus, then you will need\n * to [manually preload](../overview/media-preloading.md#manual-preloading) the audio.\n *\n * The trial can end when the participant responds, or if the participant has failed to respond within a fixed length of time. You can also prevent the slider response from being made before the audio has finished playing.\n * @author Josh de Leeuw\n * @see {@link https://www.jspsych.org/latest/plugins/audio-slider-response/ audio-slider-response plugin documentation on jspsych.org}\n */\nclass AudioSliderResponsePlugin implements JsPsychPlugin<Info> {\n static info = info;\n private audio: AudioPlayerInterface;\n private context: AudioContext;\n private params: TrialType<Info>;\n private display: HTMLElement;\n private response: { rt: number; response: number } = { rt: null, response: null };\n private startTime: number;\n private half_thumb_width: number;\n private trial_complete: (trial_data: {\n rt: number;\n slider_start: number;\n response: number;\n }) => void;\n\n constructor(private jsPsych: JsPsych) {\n autoBind(this);\n }\n\n async trial(display_element: HTMLElement, trial: TrialType<Info>, on_load: () => void) {\n // record webaudio context start time\n this.startTime;\n this.params = trial;\n this.display = display_element;\n // for storing data related to response\n this.response;\n // half of the thumb width value from jspsych.css, used to adjust the label positions\n this.half_thumb_width = 7.5;\n // hold the .resolve() function from the Promise that ends the trial\n this.trial_complete;\n\n // setup stimulus\n this.context = this.jsPsych.pluginAPI.audioContext();\n\n // load audio file\n this.audio = await this.jsPsych.pluginAPI.getAudioPlayer(trial.stimulus);\n\n this.setupTrial();\n\n on_load();\n\n return new Promise((resolve) => {\n this.trial_complete = resolve;\n });\n }\n\n // to enable slider after audio ends\n private enable_slider() {\n document.querySelector<HTMLInputElement>(\"#jspsych-audio-slider-response-response\").disabled =\n false;\n if (!this.params.require_movement) {\n document.querySelector<HTMLButtonElement>(\"#jspsych-audio-slider-response-next\").disabled =\n false;\n }\n }\n\n private setupTrial = () => {\n // set up end event if trial needs it\n if (this.params.trial_ends_after_audio) {\n this.audio.addEventListener(\"ended\", this.end_trial);\n }\n\n // enable slider after audio ends if necessary\n if (!this.params.response_allowed_while_playing && !this.params.trial_ends_after_audio) {\n this.audio.addEventListener(\"ended\", this.enable_slider);\n }\n\n var html = '<div id=\"jspsych-audio-slider-response-wrapper\" style=\"margin: 100px 0px;\">';\n html +=\n '<div class=\"jspsych-audio-slider-response-container\" style=\"position:relative; margin: 0 auto 3em auto; width:';\n if (this.params.slider_width !== null) {\n html += this.params.slider_width + \"px;\";\n } else {\n html += \"auto;\";\n }\n html += '\">';\n html +=\n '<input type=\"range\" class=\"jspsych-slider\" value=\"' +\n this.params.slider_start +\n '\" min=\"' +\n this.params.min +\n '\" max=\"' +\n this.params.max +\n '\" step=\"' +\n this.params.step +\n '\" id=\"jspsych-audio-slider-response-response\"';\n if (!this.params.response_allowed_while_playing) {\n html += \" disabled\";\n }\n html += \"></input><div>\";\n for (var j = 0; j < this.params.labels.length; j++) {\n var label_width_perc = 100 / (this.params.labels.length - 1);\n var percent_of_range = j * (100 / (this.params.labels.length - 1));\n var percent_dist_from_center = ((percent_of_range - 50) / 50) * 100;\n var offset = (percent_dist_from_center * this.half_thumb_width) / 100;\n html +=\n '<div style=\"border: 1px solid transparent; display: inline-block; position: absolute; ' +\n \"left:calc(\" +\n percent_of_range +\n \"% - (\" +\n label_width_perc +\n \"% / 2) - \" +\n offset +\n \"px); text-align: center; width: \" +\n label_width_perc +\n '%;\">';\n html +=\n '<span style=\"text-align: center; font-size: 80%;\">' + this.params.labels[j] + \"</span>\";\n html += \"</div>\";\n }\n html += \"</div>\";\n html += \"</div>\";\n html += \"</div>\";\n\n if (this.params.prompt !== null) {\n html += this.params.prompt;\n }\n\n // add submit button\n var next_disabled_attribute = \"\";\n if (this.params.require_movement || !this.params.response_allowed_while_playing) {\n next_disabled_attribute = \"disabled\";\n }\n html +=\n '<button id=\"jspsych-audio-slider-response-next\" class=\"jspsych-btn\" ' +\n next_disabled_attribute +\n \">\" +\n this.params.button_label +\n \"</button>\";\n\n this.display.innerHTML = html;\n\n this.response = {\n rt: null,\n response: null,\n };\n\n if (!this.params.response_allowed_while_playing) {\n this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-response\"\n ).disabled = true;\n this.display.querySelector<HTMLInputElement>(\"#jspsych-audio-slider-response-next\").disabled =\n true;\n }\n\n if (this.params.require_movement) {\n const enable_button = () => {\n this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-next\"\n ).disabled = false;\n };\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-response\")\n .addEventListener(\"mousedown\", enable_button);\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-response\")\n .addEventListener(\"touchstart\", enable_button);\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-response\")\n .addEventListener(\"change\", enable_button);\n }\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-next\")\n .addEventListener(\"click\", () => {\n // measure response time\n var endTime = performance.now();\n var rt = Math.round(endTime - this.startTime);\n if (this.context !== null) {\n endTime = this.context.currentTime;\n rt = Math.round((endTime - this.startTime) * 1000);\n }\n this.response.rt = rt;\n this.response.response = this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-response\"\n ).valueAsNumber;\n\n if (this.params.response_ends_trial) {\n this.end_trial();\n } else {\n this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-next\"\n ).disabled = true;\n }\n });\n\n this.startTime = performance.now();\n\n // start audio\n this.audio.play();\n\n // end trial if trial_duration is set\n if (this.params.trial_duration !== null) {\n this.jsPsych.pluginAPI.setTimeout(() => {\n this.end_trial();\n }, this.params.trial_duration);\n }\n };\n\n private end_trial = () => {\n // kill any remaining setTimeout handlers\n this.jsPsych.pluginAPI.clearAllTimeouts();\n\n // stop the audio file if it is playing\n this.audio.stop();\n\n // remove end event listeners if they exist\n this.audio.removeEventListener(\"ended\", this.end_trial);\n this.audio.removeEventListener(\"ended\", this.enable_slider);\n\n // save data\n var trialdata = {\n rt: this.response.rt,\n stimulus: this.params.stimulus,\n slider_start: this.params.slider_start,\n response: this.response.response,\n };\n\n this.display.innerHTML = \"\";\n\n // next trial\n this.trial_complete(trialdata);\n };\n\n simulate(\n trial: TrialType<Info>,\n simulation_mode,\n simulation_options: any,\n load_callback: () => void\n ) {\n if (simulation_mode == \"data-only\") {\n load_callback();\n this.simulate_data_only(trial, simulation_options);\n }\n if (simulation_mode == \"visual\") {\n this.simulate_visual(trial, simulation_options, load_callback);\n }\n }\n\n private create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const default_data = {\n stimulus: trial.stimulus,\n slider_start: trial.slider_start,\n response: this.jsPsych.randomization.randomInt(trial.min, trial.max),\n rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),\n };\n\n const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);\n\n this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);\n\n return data;\n }\n\n private simulate_data_only(trial: TrialType<Info>, simulation_options) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n this.jsPsych.finishTrial(data);\n }\n\n private simulate_visual(trial: TrialType<Info>, simulation_options, load_callback: () => void) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n const display_element = this.jsPsych.getDisplayElement();\n\n const respond = () => {\n if (data.rt !== null) {\n const el = display_element.querySelector<HTMLInputElement>(\"input[type='range']\");\n\n setTimeout(() => {\n this.jsPsych.pluginAPI.clickTarget(el);\n el.valueAsNumber = data.response;\n }, data.rt / 2);\n\n this.jsPsych.pluginAPI.clickTarget(display_element.querySelector(\"button\"), data.rt);\n }\n };\n\n this.trial(display_element, trial, () => {\n load_callback();\n\n if (!trial.response_allowed_while_playing) {\n this.audio.addEventListener(\"ended\", respond);\n } else {\n respond();\n }\n });\n }\n}\n\nexport default AudioSliderResponsePlugin;\n"],"names":["version"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAM,IAAc,GAAA;AAAA,EAClB,IAAM,EAAA,uBAAA;AAAA,WACNA,gBAAA;AAAA,EACA,UAAY,EAAA;AAAA,IAEV,QAAU,EAAA;AAAA,MACR,MAAM,aAAc,CAAA,KAAA;AAAA,MACpB,OAAS,EAAA,KAAA,CAAA;AAAA,KACX;AAAA,IAEA,GAAK,EAAA;AAAA,MACH,MAAM,aAAc,CAAA,GAAA;AAAA,MACpB,OAAS,EAAA,CAAA;AAAA,KACX;AAAA,IAEA,GAAK,EAAA;AAAA,MACH,MAAM,aAAc,CAAA,GAAA;AAAA,MACpB,OAAS,EAAA,GAAA;AAAA,KACX;AAAA,IAEA,YAAc,EAAA;AAAA,MACZ,MAAM,aAAc,CAAA,GAAA;AAAA,MACpB,OAAS,EAAA,EAAA;AAAA,KACX;AAAA,IAEA,IAAM,EAAA;AAAA,MACJ,MAAM,aAAc,CAAA,GAAA;AAAA,MACp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AK,IAAA,CAAA,KAAA,CAAM,eAAiB,EAAA,KAAA,EAAO,MAAM;AACvC,MAAc,aAAA,EAAA,CAAA;AAEd,MAAI,IAAA,CAAC,MAAM,8BAAgC,EAAA;AACzC,QAAK,IAAA,CAAA,KAAA,CAAM,gBAAiB,CAAA,OAAA,EAAS,OAAO,CAAA,CAAA;AAAA,OACvC,MAAA;AACL,QAAQ,OAAA,EAAA,CAAA;AAAA,OACV;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAA;AAnSM,yBAAA,CACG,IAAO,GAAA,IAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import autoBind from \"auto-bind\";\nimport { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { AudioPlayerInterface } from \"../../jspsych/src/modules/plugin-api/AudioPlayer\";\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"audio-slider-response\",\n version: version,\n parameters: {\n /** Audio file to be played. */\n stimulus: {\n type: ParameterType.AUDIO,\n default: undefined,\n },\n /** Sets the minimum value of the slider. */\n min: {\n type: ParameterType.INT,\n default: 0,\n },\n /** Sets the maximum value of the slider */\n max: {\n type: ParameterType.INT,\n default: 100,\n },\n /** Sets the starting value of the slider */\n slider_start: {\n type: ParameterType.INT,\n default: 50,\n },\n /** Sets the step of the slider. This is the smallest amount by which the slider can change. */\n step: {\n type: ParameterType.INT,\n default: 1,\n },\n /** Labels displayed at equidistant locations on the slider. For example, two labels will be placed at the ends of the\n * slider. Three labels would place two at the ends and one in the middle. Four will place two at the ends, and the\n * other two will be at 33% and 67% of the slider width.\n */\n labels: {\n type: ParameterType.HTML_STRING,\n default: [],\n array: true,\n },\n /** Set the width of the slider in pixels. If left null, then the width will be equal to the widest element in the display. */\n slider_width: {\n type: ParameterType.INT,\n default: null,\n },\n /** Label of the button to end the trial. */\n button_label: {\n type: ParameterType.STRING,\n default: \"Continue\",\n array: false,\n },\n /** If true, the participant must move the slider before clicking the continue button. */\n require_movement: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is\n * that it can be used to provide a reminder about the action the participant is supposed to take (e.g., which key to press).\n */\n prompt: {\n type: ParameterType.HTML_STRING,\n default: null,\n },\n /** How long to wait for the participant to make a response before ending the trial in milliseconds. If\n * the participant fails to make a response before this timer is reached, the participant's response will be\n * recorded as null for the trial and the trial will end. If the value of this parameter is null, then the trial\n * will wait for a response indefinitely.\n */\n trial_duration: {\n type: ParameterType.INT,\n default: null,\n },\n /** If true, then the trial will end whenever the participant makes a response (assuming they make their response\n * before the cutoff specified by the `trial_duration` parameter). If false, then the trial will continue until the\n * value for `trial_duration` is reached. You can set this parameter to `false` to force the participant to listen to\n * the stimulus for a fixed amount of time, even if they respond before the time is complete.\n */\n response_ends_trial: {\n type: ParameterType.BOOL,\n default: true,\n },\n /** If true, then the trial will end as soon as the audio file finishes playing. */\n trial_ends_after_audio: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** If true, then responses are allowed while the audio is playing. If false, then the audio must finish playing before\n * the slider is enabled and the trial can end via the next button click. Once the audio has played all the way through,\n * the slider is enabled and a response is allowed (including while the audio is being re-played via on-screen playback controls).\n */\n response_allowed_while_playing: {\n type: ParameterType.BOOL,\n default: true,\n },\n },\n data: {\n /** The numeric value of the slider. */\n response: {\n type: ParameterType.INT,\n },\n /** The time in milliseconds for the participant to make a response. The time is measured from when the stimulus first\n * began playing until the participant's response.\n */\n rt: {\n type: ParameterType.INT,\n },\n /** The path of the audio file that was played. */\n stimulus: {\n type: ParameterType.STRING,\n },\n /** The starting value of the slider. */\n slider_start: {\n type: ParameterType.INT,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * This plugin plays an audio file and allows the participant to respond by dragging a slider.\n *\n * If the browser supports it, audio files are played using the WebAudio API. This allows for reasonably precise timing of the\n * playback. The timing of responses generated is measured against the WebAudio specific clock, improving the measurement of\n * response times. If the browser does not support the WebAudio API, then the audio file is played with HTML5 audio.\n *\n * Audio files can be automatically preloaded by jsPsych using the [`preload` plugin](preload.md). However, if you are using\n * timeline variables or another dynamic method to specify the audio stimulus, then you will need\n * to [manually preload](../overview/media-preloading.md#manual-preloading) the audio.\n *\n * The trial can end when the participant responds, or if the participant has failed to respond within a fixed length of time. You can also prevent the slider response from being made before the audio has finished playing.\n * @author Josh de Leeuw\n * @see {@link https://www.jspsych.org/latest/plugins/audio-slider-response/ audio-slider-response plugin documentation on jspsych.org}\n */\nclass AudioSliderResponsePlugin implements JsPsychPlugin<Info> {\n static info = info;\n private audio: AudioPlayerInterface;\n private context: AudioContext;\n private params: TrialType<Info>;\n private display: HTMLElement;\n private response: { rt: number; response: number } = { rt: null, response: null };\n private startTime: number;\n private half_thumb_width: number;\n private trial_complete: (trial_data: {\n rt: number;\n slider_start: number;\n response: number;\n }) => void;\n\n constructor(private jsPsych: JsPsych) {\n autoBind(this);\n }\n\n async trial(display_element: HTMLElement, trial: TrialType<Info>, on_load: () => void) {\n this.params = trial;\n this.display = display_element;\n // for storing data related to response\n this.response;\n // half of the thumb width value from jspsych.css, used to adjust the label positions\n this.half_thumb_width = 7.5;\n // hold the .resolve() function from the Promise that ends the trial\n this.trial_complete;\n\n // setup stimulus\n this.context = this.jsPsych.pluginAPI.audioContext();\n\n // load audio file\n this.audio = await this.jsPsych.pluginAPI.getAudioPlayer(trial.stimulus);\n\n this.setupTrial();\n\n on_load();\n\n return new Promise((resolve) => {\n this.trial_complete = resolve;\n });\n }\n\n // to enable slider after audio ends\n private enable_slider() {\n document.querySelector<HTMLInputElement>(\"#jspsych-audio-slider-response-response\").disabled =\n false;\n if (!this.params.require_movement) {\n document.querySelector<HTMLButtonElement>(\"#jspsych-audio-slider-response-next\").disabled =\n false;\n }\n }\n\n private setupTrial = () => {\n // set up end event if trial needs it\n if (this.params.trial_ends_after_audio) {\n this.audio.addEventListener(\"ended\", this.end_trial);\n }\n\n // enable slider after audio ends if necessary\n if (!this.params.response_allowed_while_playing && !this.params.trial_ends_after_audio) {\n this.audio.addEventListener(\"ended\", this.enable_slider);\n }\n\n var html = '<div id=\"jspsych-audio-slider-response-wrapper\" style=\"margin: 100px 0px;\">';\n html +=\n '<div class=\"jspsych-audio-slider-response-container\" style=\"position:relative; margin: 0 auto 3em auto; width:';\n if (this.params.slider_width !== null) {\n html += this.params.slider_width + \"px;\";\n } else {\n html += \"auto;\";\n }\n html += '\">';\n html +=\n '<input type=\"range\" class=\"jspsych-slider\" value=\"' +\n this.params.slider_start +\n '\" min=\"' +\n this.params.min +\n '\" max=\"' +\n this.params.max +\n '\" step=\"' +\n this.params.step +\n '\" id=\"jspsych-audio-slider-response-response\"';\n if (!this.params.response_allowed_while_playing) {\n html += \" disabled\";\n }\n html += \"></input><div>\";\n for (var j = 0; j < this.params.labels.length; j++) {\n var label_width_perc = 100 / (this.params.labels.length - 1);\n var percent_of_range = j * (100 / (this.params.labels.length - 1));\n var percent_dist_from_center = ((percent_of_range - 50) / 50) * 100;\n var offset = (percent_dist_from_center * this.half_thumb_width) / 100;\n html +=\n '<div style=\"border: 1px solid transparent; display: inline-block; position: absolute; ' +\n \"left:calc(\" +\n percent_of_range +\n \"% - (\" +\n label_width_perc +\n \"% / 2) - \" +\n offset +\n \"px); text-align: center; width: \" +\n label_width_perc +\n '%;\">';\n html +=\n '<span style=\"text-align: center; font-size: 80%;\">' + this.params.labels[j] + \"</span>\";\n html += \"</div>\";\n }\n html += \"</div>\";\n html += \"</div>\";\n html += \"</div>\";\n\n if (this.params.prompt !== null) {\n html += this.params.prompt;\n }\n\n // add submit button\n var next_disabled_attribute = \"\";\n if (this.params.require_movement || !this.params.response_allowed_while_playing) {\n next_disabled_attribute = \"disabled\";\n }\n html +=\n '<button id=\"jspsych-audio-slider-response-next\" class=\"jspsych-btn\" ' +\n next_disabled_attribute +\n \">\" +\n this.params.button_label +\n \"</button>\";\n\n this.display.innerHTML = html;\n\n this.response = {\n rt: null,\n response: null,\n };\n\n if (!this.params.response_allowed_while_playing) {\n this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-response\"\n ).disabled = true;\n this.display.querySelector<HTMLInputElement>(\"#jspsych-audio-slider-response-next\").disabled =\n true;\n }\n\n if (this.params.require_movement) {\n const enable_button = () => {\n this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-next\"\n ).disabled = false;\n };\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-response\")\n .addEventListener(\"mousedown\", enable_button);\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-response\")\n .addEventListener(\"touchstart\", enable_button);\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-response\")\n .addEventListener(\"change\", enable_button);\n }\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-next\")\n .addEventListener(\"click\", () => {\n // measure response time\n var endTime = performance.now();\n var rt = Math.round(endTime - this.startTime);\n if (this.context !== null) {\n endTime = this.context.currentTime;\n rt = Math.round((endTime - this.startTime) * 1000);\n }\n this.response.rt = rt;\n this.response.response = this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-response\"\n ).valueAsNumber;\n\n if (this.params.response_ends_trial) {\n this.end_trial();\n } else {\n this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-next\"\n ).disabled = true;\n }\n });\n\n //record start time\n this.startTime = performance.now();\n // record webaudio context start time\n if (this.context !== null) {\n this.startTime = this.context.currentTime;\n }\n\n // start audio\n this.audio.play();\n\n // end trial if trial_duration is set\n if (this.params.trial_duration !== null) {\n this.jsPsych.pluginAPI.setTimeout(() => {\n this.end_trial();\n }, this.params.trial_duration);\n }\n };\n\n private end_trial = () => {\n // kill any remaining setTimeout handlers\n this.jsPsych.pluginAPI.clearAllTimeouts();\n\n // stop the audio file if it is playing\n this.audio.stop();\n\n // remove end event listeners if they exist\n this.audio.removeEventListener(\"ended\", this.end_trial);\n this.audio.removeEventListener(\"ended\", this.enable_slider);\n\n // save data\n var trialdata = {\n rt: this.response.rt,\n stimulus: this.params.stimulus,\n slider_start: this.params.slider_start,\n response: this.response.response,\n };\n\n this.display.innerHTML = \"\";\n\n // next trial\n this.trial_complete(trialdata);\n };\n\n simulate(\n trial: TrialType<Info>,\n simulation_mode,\n simulation_options: any,\n load_callback: () => void\n ) {\n if (simulation_mode == \"data-only\") {\n load_callback();\n this.simulate_data_only(trial, simulation_options);\n }\n if (simulation_mode == \"visual\") {\n this.simulate_visual(trial, simulation_options, load_callback);\n }\n }\n\n private create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const default_data = {\n stimulus: trial.stimulus,\n slider_start: trial.slider_start,\n response: this.jsPsych.randomization.randomInt(trial.min, trial.max),\n rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),\n };\n\n const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);\n\n this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);\n\n return data;\n }\n\n private simulate_data_only(trial: TrialType<Info>, simulation_options) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n this.jsPsych.finishTrial(data);\n }\n\n private simulate_visual(trial: TrialType<Info>, simulation_options, load_callback: () => void) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n const display_element = this.jsPsych.getDisplayElement();\n\n const respond = () => {\n if (data.rt !== null) {\n const el = display_element.querySelector<HTMLInputElement>(\"input[type='range']\");\n\n setTimeout(() => {\n this.jsPsych.pluginAPI.clickTarget(el);\n el.valueAsNumber = data.response;\n }, data.rt / 2);\n\n this.jsPsych.pluginAPI.clickTarget(display_element.querySelector(\"button\"), data.rt);\n }\n };\n\n this.trial(display_element, trial, () => {\n load_callback();\n\n if (!trial.response_allowed_while_playing) {\n this.audio.addEventListener(\"ended\", respond);\n } else {\n respond();\n }\n });\n }\n}\n\nexport default AudioSliderResponsePlugin;\n"],"names":["version"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAM,IAAc,GAAA;AA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O,kBAAkB,CAAA,CAAA;AAElE,IAAM,MAAA,eAAA,GAAkB,IAAK,CAAA,OAAA,CAAQ,iBAAkB,EAAA,CAAA;AAEvD,IAAA,MAAM,UAAU,MAAM;AACpB,MAAI,IAAA,IAAA,CAAK,OAAO,IAAM,EAAA;AACpB,QAAM,MAAA,EAAA,GAAK,eAAgB,CAAA,aAAA,CAAgC,qBAAqB,CAAA,CAAA;AAEhF,QAAA,UAAA,CAAW,MAAM;AACf,UAAK,IAAA,CAAA,OAAA,CAAQ,SAAU,CAAA,WAAA,CAAY,EAAE,CAAA,CAAA;AACrC,UAAA,EAAA,CAAG,gBAAgB,IAAK,CAAA,QAAA,CAAA;AAAA,SAC1B,EAAG,IAAK,CAAA,EAAA,GAAK,CAAC,CAAA,CAAA;AAEd,QAAK,IAAA,CAAA,OAAA,CAAQ,UAAU,WAAY,CAAA,eAAA,CAAgB,cAAc,QAAQ,CAAA,EAAG,KAAK,EAAE,CAAA,CAAA;AAAA,OACrF;AAAA,KACF,CAAA;AAEA,IAAK,IAAA,CAAA,KAAA,CAAM,eAAiB,EAAA,KAAA,EAAO,MAAM;AACvC,MAAc,aAAA,EAAA,CAAA;AAEd,MAAI,IAAA,CAAC,MAAM,8BAAgC,EAAA;AACzC,QAAK,IAAA,CAAA,KAAA,CAAM,gBAAiB,CAAA,OAAA,EAAS,OAAO,CAAA,CAAA;AAAA,OACvC,MAAA;AACL,QAAQ,OAAA,EAAA,CAAA;AAAA,OACV;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAA;AAtSM,yBAAA,CACG,IAAO,GAAA,IAAA;;;;"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -156,8 +156,6 @@ class AudioSliderResponsePlugin implements JsPsychPlugin<Info> {
|
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
async trial(display_element: HTMLElement, trial: TrialType<Info>, on_load: () => void) {
|
|
159
|
-
// record webaudio context start time
|
|
160
|
-
this.startTime;
|
|
161
159
|
this.params = trial;
|
|
162
160
|
this.display = display_element;
|
|
163
161
|
// for storing data related to response
|
|
@@ -325,7 +323,12 @@ class AudioSliderResponsePlugin implements JsPsychPlugin<Info> {
|
|
|
325
323
|
}
|
|
326
324
|
});
|
|
327
325
|
|
|
326
|
+
//record start time
|
|
328
327
|
this.startTime = performance.now();
|
|
328
|
+
// record webaudio context start time
|
|
329
|
+
if (this.context !== null) {
|
|
330
|
+
this.startTime = this.context.currentTime;
|
|
331
|
+
}
|
|
329
332
|
|
|
330
333
|
// start audio
|
|
331
334
|
this.audio.play();
|