@jspsych/plugin-video-keyboard-response 1.1.2 → 2.0.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/README.md +8 -2
- package/dist/index.browser.js +332 -322
- 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 +330 -320
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +246 -200
- package/dist/index.js +330 -320
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +31 -9
package/dist/index.cjs
CHANGED
|
@@ -2,328 +2,338 @@
|
|
|
2
2
|
|
|
3
3
|
var jspsych = require('jspsych');
|
|
4
4
|
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
},
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
5
|
+
var _package = {
|
|
6
|
+
name: "@jspsych/plugin-video-keyboard-response",
|
|
7
|
+
version: "2.0.0",
|
|
8
|
+
description: "jsPsych plugin for playing a video file and getting a keyboard response",
|
|
9
|
+
type: "module",
|
|
10
|
+
main: "dist/index.cjs",
|
|
11
|
+
exports: {
|
|
12
|
+
import: "./dist/index.js",
|
|
13
|
+
require: "./dist/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
typings: "dist/index.d.ts",
|
|
16
|
+
unpkg: "dist/index.browser.min.js",
|
|
17
|
+
files: [
|
|
18
|
+
"src",
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
source: "src/index.ts",
|
|
22
|
+
scripts: {
|
|
23
|
+
test: "jest --passWithNoTests",
|
|
24
|
+
"test:watch": "npm test -- --watch",
|
|
25
|
+
tsc: "tsc",
|
|
26
|
+
build: "rollup --config",
|
|
27
|
+
"build:watch": "npm run build -- --watch"
|
|
28
|
+
},
|
|
29
|
+
repository: {
|
|
30
|
+
type: "git",
|
|
31
|
+
url: "git+https://github.com/jspsych/jsPsych.git",
|
|
32
|
+
directory: "packages/plugin-video-keyboard-response"
|
|
33
|
+
},
|
|
34
|
+
author: "Josh de Leeuw",
|
|
35
|
+
license: "MIT",
|
|
36
|
+
bugs: {
|
|
37
|
+
url: "https://github.com/jspsych/jsPsych/issues"
|
|
38
|
+
},
|
|
39
|
+
homepage: "https://www.jspsych.org/latest/plugins/video-keyboard-response",
|
|
40
|
+
peerDependencies: {
|
|
41
|
+
jspsych: ">=7.1.0"
|
|
42
|
+
},
|
|
43
|
+
devDependencies: {
|
|
44
|
+
"@jspsych/config": "^3.0.0",
|
|
45
|
+
"@jspsych/test-utils": "^1.2.0"
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const info = {
|
|
50
|
+
name: "video-keyboard-response",
|
|
51
|
+
version: _package.version,
|
|
52
|
+
parameters: {
|
|
53
|
+
stimulus: {
|
|
54
|
+
type: jspsych.ParameterType.VIDEO,
|
|
55
|
+
pretty_name: "Video",
|
|
56
|
+
default: void 0,
|
|
57
|
+
array: true
|
|
58
|
+
},
|
|
59
|
+
choices: {
|
|
60
|
+
type: jspsych.ParameterType.KEYS,
|
|
61
|
+
pretty_name: "Choices",
|
|
62
|
+
default: "ALL_KEYS"
|
|
63
|
+
},
|
|
64
|
+
prompt: {
|
|
65
|
+
type: jspsych.ParameterType.HTML_STRING,
|
|
66
|
+
pretty_name: "Prompt",
|
|
67
|
+
default: null
|
|
68
|
+
},
|
|
69
|
+
width: {
|
|
70
|
+
type: jspsych.ParameterType.INT,
|
|
71
|
+
pretty_name: "Width",
|
|
72
|
+
default: ""
|
|
73
|
+
},
|
|
74
|
+
height: {
|
|
75
|
+
type: jspsych.ParameterType.INT,
|
|
76
|
+
pretty_name: "Height",
|
|
77
|
+
default: ""
|
|
78
|
+
},
|
|
79
|
+
autoplay: {
|
|
80
|
+
type: jspsych.ParameterType.BOOL,
|
|
81
|
+
pretty_name: "Autoplay",
|
|
82
|
+
default: true
|
|
83
|
+
},
|
|
84
|
+
controls: {
|
|
85
|
+
type: jspsych.ParameterType.BOOL,
|
|
86
|
+
pretty_name: "Controls",
|
|
87
|
+
default: false
|
|
88
|
+
},
|
|
89
|
+
start: {
|
|
90
|
+
type: jspsych.ParameterType.FLOAT,
|
|
91
|
+
pretty_name: "Start",
|
|
92
|
+
default: null
|
|
93
|
+
},
|
|
94
|
+
stop: {
|
|
95
|
+
type: jspsych.ParameterType.FLOAT,
|
|
96
|
+
pretty_name: "Stop",
|
|
97
|
+
default: null
|
|
98
|
+
},
|
|
99
|
+
rate: {
|
|
100
|
+
type: jspsych.ParameterType.FLOAT,
|
|
101
|
+
pretty_name: "Rate",
|
|
102
|
+
default: 1
|
|
103
|
+
},
|
|
104
|
+
trial_ends_after_video: {
|
|
105
|
+
type: jspsych.ParameterType.BOOL,
|
|
106
|
+
pretty_name: "End trial after video finishes",
|
|
107
|
+
default: false
|
|
108
|
+
},
|
|
109
|
+
trial_duration: {
|
|
110
|
+
type: jspsych.ParameterType.INT,
|
|
111
|
+
pretty_name: "Trial duration",
|
|
112
|
+
default: null
|
|
113
|
+
},
|
|
114
|
+
response_ends_trial: {
|
|
115
|
+
type: jspsych.ParameterType.BOOL,
|
|
116
|
+
pretty_name: "Response ends trial",
|
|
117
|
+
default: true
|
|
118
|
+
},
|
|
119
|
+
response_allowed_while_playing: {
|
|
120
|
+
type: jspsych.ParameterType.BOOL,
|
|
121
|
+
pretty_name: "Response allowed while playing",
|
|
122
|
+
default: true
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
data: {
|
|
126
|
+
response: {
|
|
127
|
+
type: jspsych.ParameterType.STRING
|
|
128
|
+
},
|
|
129
|
+
rt: {
|
|
130
|
+
type: jspsych.ParameterType.INT
|
|
131
|
+
},
|
|
132
|
+
stimulus: {
|
|
133
|
+
type: jspsych.ParameterType.STRING,
|
|
134
|
+
array: true
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
class VideoKeyboardResponsePlugin {
|
|
139
|
+
constructor(jsPsych) {
|
|
140
|
+
this.jsPsych = jsPsych;
|
|
141
|
+
}
|
|
142
|
+
trial(display_element, trial) {
|
|
143
|
+
if (!Array.isArray(trial.stimulus)) {
|
|
144
|
+
throw new Error(`
|
|
111
145
|
The stimulus property for the video-keyboard-response plugin must be an array
|
|
112
146
|
of files. See https://www.jspsych.org/latest/plugins/video-keyboard-response/#parameters
|
|
113
|
-
`);
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
if (trial.
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
const video_element = display_element.querySelector("#jspsych-video-button-response-stimulus");
|
|
304
|
-
const respond = () => {
|
|
305
|
-
if (data.rt !== null) {
|
|
306
|
-
this.jsPsych.pluginAPI.pressKey(data.response, data.rt);
|
|
307
|
-
}
|
|
308
|
-
};
|
|
309
|
-
if (!trial.response_allowed_while_playing) {
|
|
310
|
-
video_element.addEventListener("ended", respond);
|
|
311
|
-
}
|
|
312
|
-
else {
|
|
313
|
-
respond();
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
create_simulation_data(trial, simulation_options) {
|
|
317
|
-
const default_data = {
|
|
318
|
-
stimulus: trial.stimulus,
|
|
319
|
-
rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),
|
|
320
|
-
response: this.jsPsych.pluginAPI.getValidKey(trial.choices),
|
|
321
|
-
};
|
|
322
|
-
const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);
|
|
323
|
-
this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);
|
|
324
|
-
return data;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
147
|
+
`);
|
|
148
|
+
}
|
|
149
|
+
var video_html = "<div>";
|
|
150
|
+
video_html += '<video id="jspsych-video-keyboard-response-stimulus"';
|
|
151
|
+
if (trial.width) {
|
|
152
|
+
video_html += ' width="' + trial.width + '"';
|
|
153
|
+
}
|
|
154
|
+
if (trial.height) {
|
|
155
|
+
video_html += ' height="' + trial.height + '"';
|
|
156
|
+
}
|
|
157
|
+
if (trial.autoplay && trial.start == null) {
|
|
158
|
+
video_html += " autoplay ";
|
|
159
|
+
}
|
|
160
|
+
if (trial.controls) {
|
|
161
|
+
video_html += " controls ";
|
|
162
|
+
}
|
|
163
|
+
if (trial.start !== null) {
|
|
164
|
+
video_html += ' style="visibility: hidden;"';
|
|
165
|
+
}
|
|
166
|
+
video_html += ">";
|
|
167
|
+
var video_preload_blob = this.jsPsych.pluginAPI.getVideoBuffer(trial.stimulus[0]);
|
|
168
|
+
if (!video_preload_blob) {
|
|
169
|
+
for (var i = 0; i < trial.stimulus.length; i++) {
|
|
170
|
+
var file_name = trial.stimulus[i];
|
|
171
|
+
if (file_name.indexOf("?") > -1) {
|
|
172
|
+
file_name = file_name.substring(0, file_name.indexOf("?"));
|
|
173
|
+
}
|
|
174
|
+
var type = file_name.substr(file_name.lastIndexOf(".") + 1);
|
|
175
|
+
type = type.toLowerCase();
|
|
176
|
+
if (type == "mov") {
|
|
177
|
+
console.warn(
|
|
178
|
+
"Warning: video-keyboard-response plugin does not reliably support .mov files."
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
video_html += '<source src="' + file_name + '" type="video/' + type + '">';
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
video_html += "</video>";
|
|
185
|
+
video_html += "</div>";
|
|
186
|
+
if (trial.prompt !== null) {
|
|
187
|
+
video_html += trial.prompt;
|
|
188
|
+
}
|
|
189
|
+
display_element.innerHTML = video_html;
|
|
190
|
+
var video_element = display_element.querySelector(
|
|
191
|
+
"#jspsych-video-keyboard-response-stimulus"
|
|
192
|
+
);
|
|
193
|
+
if (video_preload_blob) {
|
|
194
|
+
video_element.src = video_preload_blob;
|
|
195
|
+
}
|
|
196
|
+
video_element.onended = () => {
|
|
197
|
+
if (trial.trial_ends_after_video) {
|
|
198
|
+
end_trial();
|
|
199
|
+
}
|
|
200
|
+
if (trial.response_allowed_while_playing == false && !trial.trial_ends_after_video) {
|
|
201
|
+
this.jsPsych.pluginAPI.getKeyboardResponse({
|
|
202
|
+
callback_function: after_response,
|
|
203
|
+
valid_responses: trial.choices,
|
|
204
|
+
rt_method: "performance",
|
|
205
|
+
persist: false,
|
|
206
|
+
allow_held_key: false
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
video_element.playbackRate = trial.rate;
|
|
211
|
+
if (trial.start !== null) {
|
|
212
|
+
video_element.pause();
|
|
213
|
+
video_element.onseeked = () => {
|
|
214
|
+
video_element.style.visibility = "visible";
|
|
215
|
+
video_element.muted = false;
|
|
216
|
+
if (trial.autoplay) {
|
|
217
|
+
video_element.play();
|
|
218
|
+
} else {
|
|
219
|
+
video_element.pause();
|
|
220
|
+
}
|
|
221
|
+
video_element.onseeked = () => {
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
video_element.onplaying = () => {
|
|
225
|
+
video_element.currentTime = trial.start;
|
|
226
|
+
video_element.onplaying = () => {
|
|
227
|
+
};
|
|
228
|
+
};
|
|
229
|
+
video_element.muted = true;
|
|
230
|
+
video_element.play();
|
|
231
|
+
}
|
|
232
|
+
let stopped = false;
|
|
233
|
+
if (trial.stop !== null) {
|
|
234
|
+
video_element.addEventListener("timeupdate", (e) => {
|
|
235
|
+
var currenttime = video_element.currentTime;
|
|
236
|
+
if (currenttime >= trial.stop) {
|
|
237
|
+
if (!trial.response_allowed_while_playing) {
|
|
238
|
+
this.jsPsych.pluginAPI.getKeyboardResponse({
|
|
239
|
+
callback_function: after_response,
|
|
240
|
+
valid_responses: trial.choices,
|
|
241
|
+
rt_method: "performance",
|
|
242
|
+
persist: false,
|
|
243
|
+
allow_held_key: false
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
video_element.pause();
|
|
247
|
+
if (trial.trial_ends_after_video && !stopped) {
|
|
248
|
+
stopped = true;
|
|
249
|
+
end_trial();
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
var response = {
|
|
255
|
+
rt: null,
|
|
256
|
+
key: null
|
|
257
|
+
};
|
|
258
|
+
const end_trial = () => {
|
|
259
|
+
this.jsPsych.pluginAPI.cancelAllKeyboardResponses();
|
|
260
|
+
display_element.querySelector("#jspsych-video-keyboard-response-stimulus").pause();
|
|
261
|
+
display_element.querySelector(
|
|
262
|
+
"#jspsych-video-keyboard-response-stimulus"
|
|
263
|
+
).onended = () => {
|
|
264
|
+
};
|
|
265
|
+
var trial_data = {
|
|
266
|
+
rt: response.rt,
|
|
267
|
+
stimulus: trial.stimulus,
|
|
268
|
+
response: response.key
|
|
269
|
+
};
|
|
270
|
+
this.jsPsych.finishTrial(trial_data);
|
|
271
|
+
};
|
|
272
|
+
var after_response = (info2) => {
|
|
273
|
+
display_element.querySelector("#jspsych-video-keyboard-response-stimulus").className += " responded";
|
|
274
|
+
if (response.key == null) {
|
|
275
|
+
response = info2;
|
|
276
|
+
}
|
|
277
|
+
if (trial.response_ends_trial) {
|
|
278
|
+
end_trial();
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
if (trial.choices != "NO_KEYS" && trial.response_allowed_while_playing) {
|
|
282
|
+
this.jsPsych.pluginAPI.getKeyboardResponse({
|
|
283
|
+
callback_function: after_response,
|
|
284
|
+
valid_responses: trial.choices,
|
|
285
|
+
rt_method: "performance",
|
|
286
|
+
persist: false,
|
|
287
|
+
allow_held_key: false
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
if (trial.trial_duration !== null) {
|
|
291
|
+
this.jsPsych.pluginAPI.setTimeout(end_trial, trial.trial_duration);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
simulate(trial, simulation_mode, simulation_options, load_callback) {
|
|
295
|
+
if (simulation_mode == "data-only") {
|
|
296
|
+
load_callback();
|
|
297
|
+
this.simulate_data_only(trial, simulation_options);
|
|
298
|
+
}
|
|
299
|
+
if (simulation_mode == "visual") {
|
|
300
|
+
this.simulate_visual(trial, simulation_options, load_callback);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
simulate_data_only(trial, simulation_options) {
|
|
304
|
+
const data = this.create_simulation_data(trial, simulation_options);
|
|
305
|
+
this.jsPsych.finishTrial(data);
|
|
306
|
+
}
|
|
307
|
+
simulate_visual(trial, simulation_options, load_callback) {
|
|
308
|
+
const data = this.create_simulation_data(trial, simulation_options);
|
|
309
|
+
const display_element = this.jsPsych.getDisplayElement();
|
|
310
|
+
this.trial(display_element, trial);
|
|
311
|
+
load_callback();
|
|
312
|
+
const video_element = display_element.querySelector(
|
|
313
|
+
"#jspsych-video-button-response-stimulus"
|
|
314
|
+
);
|
|
315
|
+
const respond = () => {
|
|
316
|
+
if (data.rt !== null) {
|
|
317
|
+
this.jsPsych.pluginAPI.pressKey(data.response, data.rt);
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
if (!trial.response_allowed_while_playing) {
|
|
321
|
+
video_element.addEventListener("ended", respond);
|
|
322
|
+
} else {
|
|
323
|
+
respond();
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
create_simulation_data(trial, simulation_options) {
|
|
327
|
+
const default_data = {
|
|
328
|
+
stimulus: trial.stimulus,
|
|
329
|
+
rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),
|
|
330
|
+
response: this.jsPsych.pluginAPI.getValidKey(trial.choices)
|
|
331
|
+
};
|
|
332
|
+
const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);
|
|
333
|
+
this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);
|
|
334
|
+
return data;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
327
337
|
VideoKeyboardResponsePlugin.info = info;
|
|
328
338
|
|
|
329
339
|
module.exports = VideoKeyboardResponsePlugin;
|