@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.cjs
CHANGED
|
@@ -2,327 +2,337 @@
|
|
|
2
2
|
|
|
3
3
|
var jspsych = require('jspsych');
|
|
4
4
|
|
|
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
|
+
|
|
5
49
|
const info = {
|
|
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
|
-
rate: {
|
|
65
|
-
type: jspsych.ParameterType.FLOAT,
|
|
66
|
-
pretty_name: "Rate",
|
|
67
|
-
default: 1,
|
|
68
|
-
},
|
|
69
|
-
/** If true, the trial will end immediately after the video finishes playing. */
|
|
70
|
-
trial_ends_after_video: {
|
|
71
|
-
type: jspsych.ParameterType.BOOL,
|
|
72
|
-
pretty_name: "End trial after video finishes",
|
|
73
|
-
default: false,
|
|
74
|
-
},
|
|
75
|
-
/** How long to show trial before it ends. */
|
|
76
|
-
trial_duration: {
|
|
77
|
-
type: jspsych.ParameterType.INT,
|
|
78
|
-
pretty_name: "Trial duration",
|
|
79
|
-
default: null,
|
|
80
|
-
},
|
|
81
|
-
/** If true, the trial will end when subject makes a response. */
|
|
82
|
-
response_ends_trial: {
|
|
83
|
-
type: jspsych.ParameterType.BOOL,
|
|
84
|
-
pretty_name: "Response ends trial",
|
|
85
|
-
default: true,
|
|
86
|
-
},
|
|
87
|
-
/** If true, then responses are allowed while the video is playing. If false, then the video must finish playing before a response is accepted. */
|
|
88
|
-
response_allowed_while_playing: {
|
|
89
|
-
type: jspsych.ParameterType.BOOL,
|
|
90
|
-
pretty_name: "Response allowed while playing",
|
|
91
|
-
default: true,
|
|
92
|
-
},
|
|
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
|
|
93
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
|
+
}
|
|
94
137
|
};
|
|
95
|
-
/**
|
|
96
|
-
* **video-keyboard-response**
|
|
97
|
-
*
|
|
98
|
-
* jsPsych plugin for playing a video file and getting a keyboard response
|
|
99
|
-
*
|
|
100
|
-
* @author Josh de Leeuw
|
|
101
|
-
* @see {@link https://www.jspsych.org/plugins/jspsych-video-keyboard-response/ video-keyboard-response plugin documentation on jspsych.org}
|
|
102
|
-
*/
|
|
103
138
|
class VideoKeyboardResponsePlugin {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
throw new Error(`
|
|
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
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("?"));
|
|
114
173
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if (trial.height) {
|
|
122
|
-
video_html += ' height="' + trial.height + '"';
|
|
123
|
-
}
|
|
124
|
-
if (trial.autoplay && trial.start == null) {
|
|
125
|
-
// if autoplay is true and the start time is specified, then the video will start automatically
|
|
126
|
-
// via the play() method, rather than the autoplay attribute, to prevent showing the first frame
|
|
127
|
-
video_html += " autoplay ";
|
|
128
|
-
}
|
|
129
|
-
if (trial.controls) {
|
|
130
|
-
video_html += " controls ";
|
|
131
|
-
}
|
|
132
|
-
if (trial.start !== null) {
|
|
133
|
-
// hide video element when page loads if the start time is specified,
|
|
134
|
-
// to prevent the video element from showing the first frame
|
|
135
|
-
video_html += ' style="visibility: hidden;"';
|
|
136
|
-
}
|
|
137
|
-
video_html += ">";
|
|
138
|
-
var video_preload_blob = this.jsPsych.pluginAPI.getVideoBuffer(trial.stimulus[0]);
|
|
139
|
-
if (!video_preload_blob) {
|
|
140
|
-
for (var i = 0; i < trial.stimulus.length; i++) {
|
|
141
|
-
var file_name = trial.stimulus[i];
|
|
142
|
-
if (file_name.indexOf("?") > -1) {
|
|
143
|
-
file_name = file_name.substring(0, file_name.indexOf("?"));
|
|
144
|
-
}
|
|
145
|
-
var type = file_name.substr(file_name.lastIndexOf(".") + 1);
|
|
146
|
-
type = type.toLowerCase();
|
|
147
|
-
if (type == "mov") {
|
|
148
|
-
console.warn("Warning: video-keyboard-response plugin does not reliably support .mov files.");
|
|
149
|
-
}
|
|
150
|
-
video_html += '<source src="' + file_name + '" type="video/' + type + '">';
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
video_html += "</video>";
|
|
154
|
-
video_html += "</div>";
|
|
155
|
-
// add prompt if there is one
|
|
156
|
-
if (trial.prompt !== null) {
|
|
157
|
-
video_html += trial.prompt;
|
|
158
|
-
}
|
|
159
|
-
display_element.innerHTML = video_html;
|
|
160
|
-
var video_element = display_element.querySelector("#jspsych-video-keyboard-response-stimulus");
|
|
161
|
-
if (video_preload_blob) {
|
|
162
|
-
video_element.src = video_preload_blob;
|
|
163
|
-
}
|
|
164
|
-
video_element.onended = () => {
|
|
165
|
-
if (trial.trial_ends_after_video) {
|
|
166
|
-
end_trial();
|
|
167
|
-
}
|
|
168
|
-
if (trial.response_allowed_while_playing == false && !trial.trial_ends_after_video) {
|
|
169
|
-
// start keyboard listener
|
|
170
|
-
this.jsPsych.pluginAPI.getKeyboardResponse({
|
|
171
|
-
callback_function: after_response,
|
|
172
|
-
valid_responses: trial.choices,
|
|
173
|
-
rt_method: "performance",
|
|
174
|
-
persist: false,
|
|
175
|
-
allow_held_key: false,
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
video_element.playbackRate = trial.rate;
|
|
180
|
-
// if video start time is specified, hide the video and set the starting time
|
|
181
|
-
// before showing and playing, so that the video doesn't automatically show the first frame
|
|
182
|
-
if (trial.start !== null) {
|
|
183
|
-
video_element.pause();
|
|
184
|
-
video_element.onseeked = () => {
|
|
185
|
-
video_element.style.visibility = "visible";
|
|
186
|
-
video_element.muted = false;
|
|
187
|
-
if (trial.autoplay) {
|
|
188
|
-
video_element.play();
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
191
|
-
video_element.pause();
|
|
192
|
-
}
|
|
193
|
-
video_element.onseeked = () => { };
|
|
194
|
-
};
|
|
195
|
-
video_element.onplaying = () => {
|
|
196
|
-
video_element.currentTime = trial.start;
|
|
197
|
-
video_element.onplaying = () => { };
|
|
198
|
-
};
|
|
199
|
-
// fix for iOS/MacOS browsers: videos aren't seekable until they start playing, so need to hide/mute, play,
|
|
200
|
-
// change current time, then show/unmute
|
|
201
|
-
video_element.muted = true;
|
|
202
|
-
video_element.play();
|
|
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
|
+
);
|
|
203
180
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
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();
|
|
227
220
|
}
|
|
228
|
-
|
|
229
|
-
var response = {
|
|
230
|
-
rt: null,
|
|
231
|
-
key: null,
|
|
232
|
-
};
|
|
233
|
-
// function to end trial when it is time
|
|
234
|
-
const end_trial = () => {
|
|
235
|
-
// kill any remaining setTimeout handlers
|
|
236
|
-
this.jsPsych.pluginAPI.clearAllTimeouts();
|
|
237
|
-
// kill keyboard listeners
|
|
238
|
-
this.jsPsych.pluginAPI.cancelAllKeyboardResponses();
|
|
239
|
-
// stop the video file if it is playing
|
|
240
|
-
// remove end event listeners if they exist
|
|
241
|
-
display_element
|
|
242
|
-
.querySelector("#jspsych-video-keyboard-response-stimulus")
|
|
243
|
-
.pause();
|
|
244
|
-
display_element.querySelector("#jspsych-video-keyboard-response-stimulus").onended = () => { };
|
|
245
|
-
// gather the data to store for the trial
|
|
246
|
-
var trial_data = {
|
|
247
|
-
rt: response.rt,
|
|
248
|
-
stimulus: trial.stimulus,
|
|
249
|
-
response: response.key,
|
|
250
|
-
};
|
|
251
|
-
// clear the display
|
|
252
|
-
display_element.innerHTML = "";
|
|
253
|
-
// move on to the next trial
|
|
254
|
-
this.jsPsych.finishTrial(trial_data);
|
|
221
|
+
video_element.onseeked = () => {
|
|
255
222
|
};
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
display_element.querySelector("#jspsych-video-keyboard-response-stimulus").className +=
|
|
261
|
-
" responded";
|
|
262
|
-
// only record the first response
|
|
263
|
-
if (response.key == null) {
|
|
264
|
-
response = info;
|
|
265
|
-
}
|
|
266
|
-
if (trial.response_ends_trial) {
|
|
267
|
-
end_trial();
|
|
268
|
-
}
|
|
223
|
+
};
|
|
224
|
+
video_element.onplaying = () => {
|
|
225
|
+
video_element.currentTime = trial.start;
|
|
226
|
+
video_element.onplaying = () => {
|
|
269
227
|
};
|
|
270
|
-
|
|
271
|
-
|
|
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) {
|
|
272
238
|
this.jsPsych.pluginAPI.getKeyboardResponse({
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
239
|
+
callback_function: after_response,
|
|
240
|
+
valid_responses: trial.choices,
|
|
241
|
+
rt_method: "performance",
|
|
242
|
+
persist: false,
|
|
243
|
+
allow_held_key: false
|
|
278
244
|
});
|
|
245
|
+
}
|
|
246
|
+
video_element.pause();
|
|
247
|
+
if (trial.trial_ends_after_video && !stopped) {
|
|
248
|
+
stopped = true;
|
|
249
|
+
end_trial();
|
|
250
|
+
}
|
|
279
251
|
}
|
|
280
|
-
|
|
281
|
-
if (trial.trial_duration !== null) {
|
|
282
|
-
this.jsPsych.pluginAPI.setTimeout(end_trial, trial.trial_duration);
|
|
283
|
-
}
|
|
252
|
+
});
|
|
284
253
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
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
|
+
});
|
|
293
289
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
this.jsPsych.finishTrial(data);
|
|
290
|
+
if (trial.trial_duration !== null) {
|
|
291
|
+
this.jsPsych.pluginAPI.setTimeout(end_trial, trial.trial_duration);
|
|
297
292
|
}
|
|
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
|
-
}
|
|
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);
|
|
315
298
|
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
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();
|
|
325
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
|
+
}
|
|
326
336
|
}
|
|
327
337
|
VideoKeyboardResponsePlugin.info = info;
|
|
328
338
|
|