@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.browser.js
CHANGED
|
@@ -1,331 +1,341 @@
|
|
|
1
1
|
var jsPsychVideoKeyboardResponse = (function (jspsych) {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
+
var _package = {
|
|
5
|
+
name: "@jspsych/plugin-video-keyboard-response",
|
|
6
|
+
version: "2.0.0",
|
|
7
|
+
description: "jsPsych plugin for playing a video file and getting a keyboard response",
|
|
8
|
+
type: "module",
|
|
9
|
+
main: "dist/index.cjs",
|
|
10
|
+
exports: {
|
|
11
|
+
import: "./dist/index.js",
|
|
12
|
+
require: "./dist/index.cjs"
|
|
13
|
+
},
|
|
14
|
+
typings: "dist/index.d.ts",
|
|
15
|
+
unpkg: "dist/index.browser.min.js",
|
|
16
|
+
files: [
|
|
17
|
+
"src",
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
source: "src/index.ts",
|
|
21
|
+
scripts: {
|
|
22
|
+
test: "jest --passWithNoTests",
|
|
23
|
+
"test:watch": "npm test -- --watch",
|
|
24
|
+
tsc: "tsc",
|
|
25
|
+
build: "rollup --config",
|
|
26
|
+
"build:watch": "npm run build -- --watch"
|
|
27
|
+
},
|
|
28
|
+
repository: {
|
|
29
|
+
type: "git",
|
|
30
|
+
url: "git+https://github.com/jspsych/jsPsych.git",
|
|
31
|
+
directory: "packages/plugin-video-keyboard-response"
|
|
32
|
+
},
|
|
33
|
+
author: "Josh de Leeuw",
|
|
34
|
+
license: "MIT",
|
|
35
|
+
bugs: {
|
|
36
|
+
url: "https://github.com/jspsych/jsPsych/issues"
|
|
37
|
+
},
|
|
38
|
+
homepage: "https://www.jspsych.org/latest/plugins/video-keyboard-response",
|
|
39
|
+
peerDependencies: {
|
|
40
|
+
jspsych: ">=7.1.0"
|
|
41
|
+
},
|
|
42
|
+
devDependencies: {
|
|
43
|
+
"@jspsych/config": "^3.0.0",
|
|
44
|
+
"@jspsych/test-utils": "^1.2.0"
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
4
48
|
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
|
-
rate: {
|
|
64
|
-
type: jspsych.ParameterType.FLOAT,
|
|
65
|
-
pretty_name: "Rate",
|
|
66
|
-
default: 1,
|
|
67
|
-
},
|
|
68
|
-
/** If true, the trial will end immediately after the video finishes playing. */
|
|
69
|
-
trial_ends_after_video: {
|
|
70
|
-
type: jspsych.ParameterType.BOOL,
|
|
71
|
-
pretty_name: "End trial after video finishes",
|
|
72
|
-
default: false,
|
|
73
|
-
},
|
|
74
|
-
/** How long to show trial before it ends. */
|
|
75
|
-
trial_duration: {
|
|
76
|
-
type: jspsych.ParameterType.INT,
|
|
77
|
-
pretty_name: "Trial duration",
|
|
78
|
-
default: null,
|
|
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
|
-
},
|
|
49
|
+
name: "video-keyboard-response",
|
|
50
|
+
version: _package.version,
|
|
51
|
+
parameters: {
|
|
52
|
+
stimulus: {
|
|
53
|
+
type: jspsych.ParameterType.VIDEO,
|
|
54
|
+
pretty_name: "Video",
|
|
55
|
+
default: void 0,
|
|
56
|
+
array: true
|
|
57
|
+
},
|
|
58
|
+
choices: {
|
|
59
|
+
type: jspsych.ParameterType.KEYS,
|
|
60
|
+
pretty_name: "Choices",
|
|
61
|
+
default: "ALL_KEYS"
|
|
62
|
+
},
|
|
63
|
+
prompt: {
|
|
64
|
+
type: jspsych.ParameterType.HTML_STRING,
|
|
65
|
+
pretty_name: "Prompt",
|
|
66
|
+
default: null
|
|
67
|
+
},
|
|
68
|
+
width: {
|
|
69
|
+
type: jspsych.ParameterType.INT,
|
|
70
|
+
pretty_name: "Width",
|
|
71
|
+
default: ""
|
|
72
|
+
},
|
|
73
|
+
height: {
|
|
74
|
+
type: jspsych.ParameterType.INT,
|
|
75
|
+
pretty_name: "Height",
|
|
76
|
+
default: ""
|
|
77
|
+
},
|
|
78
|
+
autoplay: {
|
|
79
|
+
type: jspsych.ParameterType.BOOL,
|
|
80
|
+
pretty_name: "Autoplay",
|
|
81
|
+
default: true
|
|
82
|
+
},
|
|
83
|
+
controls: {
|
|
84
|
+
type: jspsych.ParameterType.BOOL,
|
|
85
|
+
pretty_name: "Controls",
|
|
86
|
+
default: false
|
|
87
|
+
},
|
|
88
|
+
start: {
|
|
89
|
+
type: jspsych.ParameterType.FLOAT,
|
|
90
|
+
pretty_name: "Start",
|
|
91
|
+
default: null
|
|
92
|
+
},
|
|
93
|
+
stop: {
|
|
94
|
+
type: jspsych.ParameterType.FLOAT,
|
|
95
|
+
pretty_name: "Stop",
|
|
96
|
+
default: null
|
|
97
|
+
},
|
|
98
|
+
rate: {
|
|
99
|
+
type: jspsych.ParameterType.FLOAT,
|
|
100
|
+
pretty_name: "Rate",
|
|
101
|
+
default: 1
|
|
102
|
+
},
|
|
103
|
+
trial_ends_after_video: {
|
|
104
|
+
type: jspsych.ParameterType.BOOL,
|
|
105
|
+
pretty_name: "End trial after video finishes",
|
|
106
|
+
default: false
|
|
92
107
|
},
|
|
108
|
+
trial_duration: {
|
|
109
|
+
type: jspsych.ParameterType.INT,
|
|
110
|
+
pretty_name: "Trial duration",
|
|
111
|
+
default: null
|
|
112
|
+
},
|
|
113
|
+
response_ends_trial: {
|
|
114
|
+
type: jspsych.ParameterType.BOOL,
|
|
115
|
+
pretty_name: "Response ends trial",
|
|
116
|
+
default: true
|
|
117
|
+
},
|
|
118
|
+
response_allowed_while_playing: {
|
|
119
|
+
type: jspsych.ParameterType.BOOL,
|
|
120
|
+
pretty_name: "Response allowed while playing",
|
|
121
|
+
default: true
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
data: {
|
|
125
|
+
response: {
|
|
126
|
+
type: jspsych.ParameterType.STRING
|
|
127
|
+
},
|
|
128
|
+
rt: {
|
|
129
|
+
type: jspsych.ParameterType.INT
|
|
130
|
+
},
|
|
131
|
+
stimulus: {
|
|
132
|
+
type: jspsych.ParameterType.STRING,
|
|
133
|
+
array: true
|
|
134
|
+
}
|
|
135
|
+
}
|
|
93
136
|
};
|
|
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
137
|
class VideoKeyboardResponsePlugin {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
138
|
+
constructor(jsPsych) {
|
|
139
|
+
this.jsPsych = jsPsych;
|
|
140
|
+
}
|
|
141
|
+
static info = info;
|
|
142
|
+
trial(display_element, trial) {
|
|
143
|
+
if (!Array.isArray(trial.stimulus)) {
|
|
144
|
+
throw new Error(`
|
|
110
145
|
The stimulus property for the video-keyboard-response plugin must be an array
|
|
111
146
|
of files. See https://www.jspsych.org/latest/plugins/video-keyboard-response/#parameters
|
|
112
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("?"));
|
|
113
173
|
}
|
|
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();
|
|
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
|
+
);
|
|
202
180
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
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();
|
|
226
220
|
}
|
|
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);
|
|
221
|
+
video_element.onseeked = () => {
|
|
254
222
|
};
|
|
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
|
-
}
|
|
223
|
+
};
|
|
224
|
+
video_element.onplaying = () => {
|
|
225
|
+
video_element.currentTime = trial.start;
|
|
226
|
+
video_element.onplaying = () => {
|
|
268
227
|
};
|
|
269
|
-
|
|
270
|
-
|
|
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) {
|
|
271
238
|
this.jsPsych.pluginAPI.getKeyboardResponse({
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
239
|
+
callback_function: after_response,
|
|
240
|
+
valid_responses: trial.choices,
|
|
241
|
+
rt_method: "performance",
|
|
242
|
+
persist: false,
|
|
243
|
+
allow_held_key: false
|
|
277
244
|
});
|
|
245
|
+
}
|
|
246
|
+
video_element.pause();
|
|
247
|
+
if (trial.trial_ends_after_video && !stopped) {
|
|
248
|
+
stopped = true;
|
|
249
|
+
end_trial();
|
|
250
|
+
}
|
|
278
251
|
}
|
|
279
|
-
|
|
280
|
-
if (trial.trial_duration !== null) {
|
|
281
|
-
this.jsPsych.pluginAPI.setTimeout(end_trial, trial.trial_duration);
|
|
282
|
-
}
|
|
252
|
+
});
|
|
283
253
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
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
|
+
});
|
|
292
289
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
this.jsPsych.finishTrial(data);
|
|
290
|
+
if (trial.trial_duration !== null) {
|
|
291
|
+
this.jsPsych.pluginAPI.setTimeout(end_trial, trial.trial_duration);
|
|
296
292
|
}
|
|
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
|
-
}
|
|
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);
|
|
314
298
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
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
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
|
+
}
|
|
325
336
|
}
|
|
326
|
-
VideoKeyboardResponsePlugin.info = info;
|
|
327
337
|
|
|
328
338
|
return VideoKeyboardResponsePlugin;
|
|
329
339
|
|
|
330
340
|
})(jsPsychModule);
|
|
331
|
-
//# sourceMappingURL=https://unpkg.com/@jspsych/plugin-video-keyboard-response@
|
|
341
|
+
//# sourceMappingURL=https://unpkg.com/@jspsych/plugin-video-keyboard-response@2.0.0/dist/index.browser.js.map
|