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