@jspsych/plugin-video-keyboard-response 1.1.3 → 2.1.0
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 +297 -303
- package/dist/index.browser.js.map +1 -1
- package/dist/index.browser.min.js +5 -2
- package/dist/index.browser.min.js.map +1 -1
- package/dist/index.cjs +296 -302
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +53 -5
- package/dist/index.js +296 -302
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +33 -9
package/dist/index.browser.js
CHANGED
|
@@ -1,331 +1,325 @@
|
|
|
1
1
|
var jsPsychVideoKeyboardResponse = (function (jspsych) {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
+
var version = "2.1.0";
|
|
5
|
+
|
|
4
6
|
const info = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
/** If true, the trial will end when subject makes a response. */
|
|
81
|
-
response_ends_trial: {
|
|
82
|
-
type: jspsych.ParameterType.BOOL,
|
|
83
|
-
pretty_name: "Response ends trial",
|
|
84
|
-
default: true,
|
|
85
|
-
},
|
|
86
|
-
/** If true, then responses are allowed while the video is playing. If false, then the video must finish playing before a response is accepted. */
|
|
87
|
-
response_allowed_while_playing: {
|
|
88
|
-
type: jspsych.ParameterType.BOOL,
|
|
89
|
-
pretty_name: "Response allowed while playing",
|
|
90
|
-
default: true,
|
|
91
|
-
},
|
|
7
|
+
name: "video-keyboard-response",
|
|
8
|
+
version,
|
|
9
|
+
parameters: {
|
|
10
|
+
/** Array of the video file(s) to play. Video can be provided in multiple file formats for better cross-browser support. */
|
|
11
|
+
stimulus: {
|
|
12
|
+
type: jspsych.ParameterType.VIDEO,
|
|
13
|
+
pretty_name: "Video",
|
|
14
|
+
default: void 0,
|
|
15
|
+
array: true
|
|
16
|
+
},
|
|
17
|
+
/** Array containing the key(s) the subject is allowed to press to respond to the stimulus. */
|
|
18
|
+
choices: {
|
|
19
|
+
type: jspsych.ParameterType.KEYS,
|
|
20
|
+
pretty_name: "Choices",
|
|
21
|
+
default: "ALL_KEYS"
|
|
22
|
+
},
|
|
23
|
+
/** Any content here will be displayed below the stimulus. */
|
|
24
|
+
prompt: {
|
|
25
|
+
type: jspsych.ParameterType.HTML_STRING,
|
|
26
|
+
pretty_name: "Prompt",
|
|
27
|
+
default: null
|
|
28
|
+
},
|
|
29
|
+
/** The width of the video in pixels. */
|
|
30
|
+
width: {
|
|
31
|
+
type: jspsych.ParameterType.INT,
|
|
32
|
+
pretty_name: "Width",
|
|
33
|
+
default: ""
|
|
34
|
+
},
|
|
35
|
+
/** The height of the video display in pixels. */
|
|
36
|
+
height: {
|
|
37
|
+
type: jspsych.ParameterType.INT,
|
|
38
|
+
pretty_name: "Height",
|
|
39
|
+
default: ""
|
|
40
|
+
},
|
|
41
|
+
/** If true, the video will begin playing as soon as it has loaded. */
|
|
42
|
+
autoplay: {
|
|
43
|
+
type: jspsych.ParameterType.BOOL,
|
|
44
|
+
pretty_name: "Autoplay",
|
|
45
|
+
default: true
|
|
46
|
+
},
|
|
47
|
+
/** If true, the subject will be able to pause the video or move the playback to any point in the video. */
|
|
48
|
+
controls: {
|
|
49
|
+
type: jspsych.ParameterType.BOOL,
|
|
50
|
+
pretty_name: "Controls",
|
|
51
|
+
default: false
|
|
52
|
+
},
|
|
53
|
+
/** Time to start the clip. If null (default), video will start at the beginning of the file. */
|
|
54
|
+
start: {
|
|
55
|
+
type: jspsych.ParameterType.FLOAT,
|
|
56
|
+
pretty_name: "Start",
|
|
57
|
+
default: null
|
|
58
|
+
},
|
|
59
|
+
/** Time to stop the clip. If null (default), video will stop at the end of the file. */
|
|
60
|
+
stop: {
|
|
61
|
+
type: jspsych.ParameterType.FLOAT,
|
|
62
|
+
pretty_name: "Stop",
|
|
63
|
+
default: null
|
|
64
|
+
},
|
|
65
|
+
/** The playback rate of the video. 1 is normal, <1 is slower, >1 is faster. */
|
|
66
|
+
rate: {
|
|
67
|
+
type: jspsych.ParameterType.FLOAT,
|
|
68
|
+
pretty_name: "Rate",
|
|
69
|
+
default: 1
|
|
70
|
+
},
|
|
71
|
+
/** If true, the trial will end immediately after the video finishes playing. */
|
|
72
|
+
trial_ends_after_video: {
|
|
73
|
+
type: jspsych.ParameterType.BOOL,
|
|
74
|
+
pretty_name: "End trial after video finishes",
|
|
75
|
+
default: false
|
|
76
|
+
},
|
|
77
|
+
/** How long to show trial before it ends. */
|
|
78
|
+
trial_duration: {
|
|
79
|
+
type: jspsych.ParameterType.INT,
|
|
80
|
+
pretty_name: "Trial duration",
|
|
81
|
+
default: null
|
|
92
82
|
},
|
|
83
|
+
/** If true, the trial will end when subject makes a response. */
|
|
84
|
+
response_ends_trial: {
|
|
85
|
+
type: jspsych.ParameterType.BOOL,
|
|
86
|
+
pretty_name: "Response ends trial",
|
|
87
|
+
default: true
|
|
88
|
+
},
|
|
89
|
+
/** If true, then responses are allowed while the video is playing. If false, then the video must finish playing before a response is accepted. */
|
|
90
|
+
response_allowed_while_playing: {
|
|
91
|
+
type: jspsych.ParameterType.BOOL,
|
|
92
|
+
pretty_name: "Response allowed while playing",
|
|
93
|
+
default: true
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
data: {
|
|
97
|
+
/** Indicates which key the participant pressed. */
|
|
98
|
+
response: {
|
|
99
|
+
type: jspsych.ParameterType.STRING
|
|
100
|
+
},
|
|
101
|
+
/** The response time in milliseconds for the participant to make a response. The time is measured from when the
|
|
102
|
+
* stimulus first appears on the screen until the participant's response.
|
|
103
|
+
* */
|
|
104
|
+
rt: {
|
|
105
|
+
type: jspsych.ParameterType.INT
|
|
106
|
+
},
|
|
107
|
+
/** The `stimulus` array. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */
|
|
108
|
+
stimulus: {
|
|
109
|
+
type: jspsych.ParameterType.STRING,
|
|
110
|
+
array: true
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
// prettier-ignore
|
|
114
|
+
citations: {
|
|
115
|
+
"apa": "de Leeuw, J. R., Gilbert, R. A., & Luchterhandt, B. (2023). jsPsych: Enabling an Open-Source Collaborative Ecosystem of Behavioral Experiments. Journal of Open Source Software, 8(85), 5351. https://doi.org/10.21105/joss.05351 ",
|
|
116
|
+
"bibtex": '@article{Leeuw2023jsPsych, author = {de Leeuw, Joshua R. and Gilbert, Rebecca A. and Luchterhandt, Bj{\\" o}rn}, journal = {Journal of Open Source Software}, doi = {10.21105/joss.05351}, issn = {2475-9066}, number = {85}, year = {2023}, month = {may 11}, pages = {5351}, publisher = {Open Journals}, title = {jsPsych: Enabling an {Open}-{Source} {Collaborative} {Ecosystem} of {Behavioral} {Experiments}}, url = {https://joss.theoj.org/papers/10.21105/joss.05351}, volume = {8}, } '
|
|
117
|
+
}
|
|
93
118
|
};
|
|
94
|
-
/**
|
|
95
|
-
* **video-keyboard-response**
|
|
96
|
-
*
|
|
97
|
-
* jsPsych plugin for playing a video file and getting a keyboard response
|
|
98
|
-
*
|
|
99
|
-
* @author Josh de Leeuw
|
|
100
|
-
* @see {@link https://www.jspsych.org/plugins/jspsych-video-keyboard-response/ video-keyboard-response plugin documentation on jspsych.org}
|
|
101
|
-
*/
|
|
102
119
|
class VideoKeyboardResponsePlugin {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
120
|
+
constructor(jsPsych) {
|
|
121
|
+
this.jsPsych = jsPsych;
|
|
122
|
+
}
|
|
123
|
+
static {
|
|
124
|
+
this.info = info;
|
|
125
|
+
}
|
|
126
|
+
trial(display_element, trial) {
|
|
127
|
+
if (!Array.isArray(trial.stimulus)) {
|
|
128
|
+
throw new Error(`
|
|
110
129
|
The stimulus property for the video-keyboard-response plugin must be an array
|
|
111
130
|
of files. See https://www.jspsych.org/latest/plugins/video-keyboard-response/#parameters
|
|
112
131
|
`);
|
|
132
|
+
}
|
|
133
|
+
var video_html = "<div>";
|
|
134
|
+
video_html += '<video id="jspsych-video-keyboard-response-stimulus"';
|
|
135
|
+
if (trial.width) {
|
|
136
|
+
video_html += ' width="' + trial.width + '"';
|
|
137
|
+
}
|
|
138
|
+
if (trial.height) {
|
|
139
|
+
video_html += ' height="' + trial.height + '"';
|
|
140
|
+
}
|
|
141
|
+
if (trial.autoplay && trial.start == null) {
|
|
142
|
+
video_html += " autoplay ";
|
|
143
|
+
}
|
|
144
|
+
if (trial.controls) {
|
|
145
|
+
video_html += " controls ";
|
|
146
|
+
}
|
|
147
|
+
if (trial.start !== null) {
|
|
148
|
+
video_html += ' style="visibility: hidden;"';
|
|
149
|
+
}
|
|
150
|
+
video_html += ">";
|
|
151
|
+
var video_preload_blob = this.jsPsych.pluginAPI.getVideoBuffer(trial.stimulus[0]);
|
|
152
|
+
if (!video_preload_blob) {
|
|
153
|
+
for (var i = 0; i < trial.stimulus.length; i++) {
|
|
154
|
+
var file_name = trial.stimulus[i];
|
|
155
|
+
if (file_name.indexOf("?") > -1) {
|
|
156
|
+
file_name = file_name.substring(0, file_name.indexOf("?"));
|
|
113
157
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if (trial.height) {
|
|
121
|
-
video_html += ' height="' + trial.height + '"';
|
|
122
|
-
}
|
|
123
|
-
if (trial.autoplay && trial.start == null) {
|
|
124
|
-
// if autoplay is true and the start time is specified, then the video will start automatically
|
|
125
|
-
// via the play() method, rather than the autoplay attribute, to prevent showing the first frame
|
|
126
|
-
video_html += " autoplay ";
|
|
127
|
-
}
|
|
128
|
-
if (trial.controls) {
|
|
129
|
-
video_html += " controls ";
|
|
130
|
-
}
|
|
131
|
-
if (trial.start !== null) {
|
|
132
|
-
// hide video element when page loads if the start time is specified,
|
|
133
|
-
// to prevent the video element from showing the first frame
|
|
134
|
-
video_html += ' style="visibility: hidden;"';
|
|
135
|
-
}
|
|
136
|
-
video_html += ">";
|
|
137
|
-
var video_preload_blob = this.jsPsych.pluginAPI.getVideoBuffer(trial.stimulus[0]);
|
|
138
|
-
if (!video_preload_blob) {
|
|
139
|
-
for (var i = 0; i < trial.stimulus.length; i++) {
|
|
140
|
-
var file_name = trial.stimulus[i];
|
|
141
|
-
if (file_name.indexOf("?") > -1) {
|
|
142
|
-
file_name = file_name.substring(0, file_name.indexOf("?"));
|
|
143
|
-
}
|
|
144
|
-
var type = file_name.substr(file_name.lastIndexOf(".") + 1);
|
|
145
|
-
type = type.toLowerCase();
|
|
146
|
-
if (type == "mov") {
|
|
147
|
-
console.warn("Warning: video-keyboard-response plugin does not reliably support .mov files.");
|
|
148
|
-
}
|
|
149
|
-
video_html += '<source src="' + file_name + '" type="video/' + type + '">';
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
video_html += "</video>";
|
|
153
|
-
video_html += "</div>";
|
|
154
|
-
// add prompt if there is one
|
|
155
|
-
if (trial.prompt !== null) {
|
|
156
|
-
video_html += trial.prompt;
|
|
157
|
-
}
|
|
158
|
-
display_element.innerHTML = video_html;
|
|
159
|
-
var video_element = display_element.querySelector("#jspsych-video-keyboard-response-stimulus");
|
|
160
|
-
if (video_preload_blob) {
|
|
161
|
-
video_element.src = video_preload_blob;
|
|
162
|
-
}
|
|
163
|
-
video_element.onended = () => {
|
|
164
|
-
if (trial.trial_ends_after_video) {
|
|
165
|
-
end_trial();
|
|
166
|
-
}
|
|
167
|
-
if (trial.response_allowed_while_playing == false && !trial.trial_ends_after_video) {
|
|
168
|
-
// start keyboard listener
|
|
169
|
-
this.jsPsych.pluginAPI.getKeyboardResponse({
|
|
170
|
-
callback_function: after_response,
|
|
171
|
-
valid_responses: trial.choices,
|
|
172
|
-
rt_method: "performance",
|
|
173
|
-
persist: false,
|
|
174
|
-
allow_held_key: false,
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
video_element.playbackRate = trial.rate;
|
|
179
|
-
// if video start time is specified, hide the video and set the starting time
|
|
180
|
-
// before showing and playing, so that the video doesn't automatically show the first frame
|
|
181
|
-
if (trial.start !== null) {
|
|
182
|
-
video_element.pause();
|
|
183
|
-
video_element.onseeked = () => {
|
|
184
|
-
video_element.style.visibility = "visible";
|
|
185
|
-
video_element.muted = false;
|
|
186
|
-
if (trial.autoplay) {
|
|
187
|
-
video_element.play();
|
|
188
|
-
}
|
|
189
|
-
else {
|
|
190
|
-
video_element.pause();
|
|
191
|
-
}
|
|
192
|
-
video_element.onseeked = () => { };
|
|
193
|
-
};
|
|
194
|
-
video_element.onplaying = () => {
|
|
195
|
-
video_element.currentTime = trial.start;
|
|
196
|
-
video_element.onplaying = () => { };
|
|
197
|
-
};
|
|
198
|
-
// fix for iOS/MacOS browsers: videos aren't seekable until they start playing, so need to hide/mute, play,
|
|
199
|
-
// change current time, then show/unmute
|
|
200
|
-
video_element.muted = true;
|
|
201
|
-
video_element.play();
|
|
158
|
+
var type = file_name.substr(file_name.lastIndexOf(".") + 1);
|
|
159
|
+
type = type.toLowerCase();
|
|
160
|
+
if (type == "mov") {
|
|
161
|
+
console.warn(
|
|
162
|
+
"Warning: video-keyboard-response plugin does not reliably support .mov files."
|
|
163
|
+
);
|
|
202
164
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
165
|
+
video_html += '<source src="' + file_name + '" type="video/' + type + '">';
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
video_html += "</video>";
|
|
169
|
+
video_html += "</div>";
|
|
170
|
+
if (trial.prompt !== null) {
|
|
171
|
+
video_html += trial.prompt;
|
|
172
|
+
}
|
|
173
|
+
display_element.innerHTML = video_html;
|
|
174
|
+
var video_element = display_element.querySelector(
|
|
175
|
+
"#jspsych-video-keyboard-response-stimulus"
|
|
176
|
+
);
|
|
177
|
+
if (video_preload_blob) {
|
|
178
|
+
video_element.src = video_preload_blob;
|
|
179
|
+
}
|
|
180
|
+
video_element.onended = () => {
|
|
181
|
+
if (trial.trial_ends_after_video) {
|
|
182
|
+
end_trial();
|
|
183
|
+
}
|
|
184
|
+
if (trial.response_allowed_while_playing == false && !trial.trial_ends_after_video) {
|
|
185
|
+
this.jsPsych.pluginAPI.getKeyboardResponse({
|
|
186
|
+
callback_function: after_response,
|
|
187
|
+
valid_responses: trial.choices,
|
|
188
|
+
rt_method: "performance",
|
|
189
|
+
persist: false,
|
|
190
|
+
allow_held_key: false
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
video_element.playbackRate = trial.rate;
|
|
195
|
+
if (trial.start !== null) {
|
|
196
|
+
video_element.pause();
|
|
197
|
+
video_element.onseeked = () => {
|
|
198
|
+
video_element.style.visibility = "visible";
|
|
199
|
+
video_element.muted = false;
|
|
200
|
+
if (trial.autoplay) {
|
|
201
|
+
video_element.play();
|
|
202
|
+
} else {
|
|
203
|
+
video_element.pause();
|
|
226
204
|
}
|
|
227
|
-
|
|
228
|
-
var response = {
|
|
229
|
-
rt: null,
|
|
230
|
-
key: null,
|
|
231
|
-
};
|
|
232
|
-
// function to end trial when it is time
|
|
233
|
-
const end_trial = () => {
|
|
234
|
-
// kill any remaining setTimeout handlers
|
|
235
|
-
this.jsPsych.pluginAPI.clearAllTimeouts();
|
|
236
|
-
// kill keyboard listeners
|
|
237
|
-
this.jsPsych.pluginAPI.cancelAllKeyboardResponses();
|
|
238
|
-
// stop the video file if it is playing
|
|
239
|
-
// remove end event listeners if they exist
|
|
240
|
-
display_element
|
|
241
|
-
.querySelector("#jspsych-video-keyboard-response-stimulus")
|
|
242
|
-
.pause();
|
|
243
|
-
display_element.querySelector("#jspsych-video-keyboard-response-stimulus").onended = () => { };
|
|
244
|
-
// gather the data to store for the trial
|
|
245
|
-
var trial_data = {
|
|
246
|
-
rt: response.rt,
|
|
247
|
-
stimulus: trial.stimulus,
|
|
248
|
-
response: response.key,
|
|
249
|
-
};
|
|
250
|
-
// clear the display
|
|
251
|
-
display_element.innerHTML = "";
|
|
252
|
-
// move on to the next trial
|
|
253
|
-
this.jsPsych.finishTrial(trial_data);
|
|
205
|
+
video_element.onseeked = () => {
|
|
254
206
|
};
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
display_element.querySelector("#jspsych-video-keyboard-response-stimulus").className +=
|
|
260
|
-
" responded";
|
|
261
|
-
// only record the first response
|
|
262
|
-
if (response.key == null) {
|
|
263
|
-
response = info;
|
|
264
|
-
}
|
|
265
|
-
if (trial.response_ends_trial) {
|
|
266
|
-
end_trial();
|
|
267
|
-
}
|
|
207
|
+
};
|
|
208
|
+
video_element.onplaying = () => {
|
|
209
|
+
video_element.currentTime = trial.start;
|
|
210
|
+
video_element.onplaying = () => {
|
|
268
211
|
};
|
|
269
|
-
|
|
270
|
-
|
|
212
|
+
};
|
|
213
|
+
video_element.muted = true;
|
|
214
|
+
video_element.play();
|
|
215
|
+
}
|
|
216
|
+
let stopped = false;
|
|
217
|
+
if (trial.stop !== null) {
|
|
218
|
+
video_element.addEventListener("timeupdate", (e) => {
|
|
219
|
+
var currenttime = video_element.currentTime;
|
|
220
|
+
if (currenttime >= trial.stop) {
|
|
221
|
+
if (!trial.response_allowed_while_playing) {
|
|
271
222
|
this.jsPsych.pluginAPI.getKeyboardResponse({
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
223
|
+
callback_function: after_response,
|
|
224
|
+
valid_responses: trial.choices,
|
|
225
|
+
rt_method: "performance",
|
|
226
|
+
persist: false,
|
|
227
|
+
allow_held_key: false
|
|
277
228
|
});
|
|
229
|
+
}
|
|
230
|
+
video_element.pause();
|
|
231
|
+
if (trial.trial_ends_after_video && !stopped) {
|
|
232
|
+
stopped = true;
|
|
233
|
+
end_trial();
|
|
234
|
+
}
|
|
278
235
|
}
|
|
279
|
-
|
|
280
|
-
if (trial.trial_duration !== null) {
|
|
281
|
-
this.jsPsych.pluginAPI.setTimeout(end_trial, trial.trial_duration);
|
|
282
|
-
}
|
|
236
|
+
});
|
|
283
237
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
238
|
+
var response = {
|
|
239
|
+
rt: null,
|
|
240
|
+
key: null
|
|
241
|
+
};
|
|
242
|
+
const end_trial = () => {
|
|
243
|
+
this.jsPsych.pluginAPI.cancelAllKeyboardResponses();
|
|
244
|
+
display_element.querySelector("#jspsych-video-keyboard-response-stimulus").pause();
|
|
245
|
+
display_element.querySelector(
|
|
246
|
+
"#jspsych-video-keyboard-response-stimulus"
|
|
247
|
+
).onended = () => {
|
|
248
|
+
};
|
|
249
|
+
var trial_data = {
|
|
250
|
+
rt: response.rt,
|
|
251
|
+
stimulus: trial.stimulus,
|
|
252
|
+
response: response.key
|
|
253
|
+
};
|
|
254
|
+
this.jsPsych.finishTrial(trial_data);
|
|
255
|
+
};
|
|
256
|
+
var after_response = (info2) => {
|
|
257
|
+
display_element.querySelector("#jspsych-video-keyboard-response-stimulus").className += " responded";
|
|
258
|
+
if (response.key == null) {
|
|
259
|
+
response = info2;
|
|
260
|
+
}
|
|
261
|
+
if (trial.response_ends_trial) {
|
|
262
|
+
end_trial();
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
if (trial.choices != "NO_KEYS" && trial.response_allowed_while_playing) {
|
|
266
|
+
this.jsPsych.pluginAPI.getKeyboardResponse({
|
|
267
|
+
callback_function: after_response,
|
|
268
|
+
valid_responses: trial.choices,
|
|
269
|
+
rt_method: "performance",
|
|
270
|
+
persist: false,
|
|
271
|
+
allow_held_key: false
|
|
272
|
+
});
|
|
292
273
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
this.jsPsych.finishTrial(data);
|
|
274
|
+
if (trial.trial_duration !== null) {
|
|
275
|
+
this.jsPsych.pluginAPI.setTimeout(end_trial, trial.trial_duration);
|
|
296
276
|
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
const video_element = display_element.querySelector("#jspsych-video-button-response-stimulus");
|
|
303
|
-
const respond = () => {
|
|
304
|
-
if (data.rt !== null) {
|
|
305
|
-
this.jsPsych.pluginAPI.pressKey(data.response, data.rt);
|
|
306
|
-
}
|
|
307
|
-
};
|
|
308
|
-
if (!trial.response_allowed_while_playing) {
|
|
309
|
-
video_element.addEventListener("ended", respond);
|
|
310
|
-
}
|
|
311
|
-
else {
|
|
312
|
-
respond();
|
|
313
|
-
}
|
|
277
|
+
}
|
|
278
|
+
simulate(trial, simulation_mode, simulation_options, load_callback) {
|
|
279
|
+
if (simulation_mode == "data-only") {
|
|
280
|
+
load_callback();
|
|
281
|
+
this.simulate_data_only(trial, simulation_options);
|
|
314
282
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
283
|
+
if (simulation_mode == "visual") {
|
|
284
|
+
this.simulate_visual(trial, simulation_options, load_callback);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
simulate_data_only(trial, simulation_options) {
|
|
288
|
+
const data = this.create_simulation_data(trial, simulation_options);
|
|
289
|
+
this.jsPsych.finishTrial(data);
|
|
290
|
+
}
|
|
291
|
+
simulate_visual(trial, simulation_options, load_callback) {
|
|
292
|
+
const data = this.create_simulation_data(trial, simulation_options);
|
|
293
|
+
const display_element = this.jsPsych.getDisplayElement();
|
|
294
|
+
this.trial(display_element, trial);
|
|
295
|
+
load_callback();
|
|
296
|
+
const video_element = display_element.querySelector(
|
|
297
|
+
"#jspsych-video-button-response-stimulus"
|
|
298
|
+
);
|
|
299
|
+
const respond = () => {
|
|
300
|
+
if (data.rt !== null) {
|
|
301
|
+
this.jsPsych.pluginAPI.pressKey(data.response, data.rt);
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
if (!trial.response_allowed_while_playing) {
|
|
305
|
+
video_element.addEventListener("ended", respond);
|
|
306
|
+
} else {
|
|
307
|
+
respond();
|
|
324
308
|
}
|
|
309
|
+
}
|
|
310
|
+
create_simulation_data(trial, simulation_options) {
|
|
311
|
+
const default_data = {
|
|
312
|
+
stimulus: trial.stimulus,
|
|
313
|
+
rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),
|
|
314
|
+
response: this.jsPsych.pluginAPI.getValidKey(trial.choices)
|
|
315
|
+
};
|
|
316
|
+
const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);
|
|
317
|
+
this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);
|
|
318
|
+
return data;
|
|
319
|
+
}
|
|
325
320
|
}
|
|
326
|
-
VideoKeyboardResponsePlugin.info = info;
|
|
327
321
|
|
|
328
322
|
return VideoKeyboardResponsePlugin;
|
|
329
323
|
|
|
330
324
|
})(jsPsychModule);
|
|
331
|
-
//# sourceMappingURL=https://unpkg.com/@jspsych/plugin-video-keyboard-response@
|
|
325
|
+
//# sourceMappingURL=https://unpkg.com/@jspsych/plugin-video-keyboard-response@2.1.0/dist/index.browser.js.map
|