Skip to content

Commit 09ee347

Browse files
committed
Add RT property to fullscreen data collection. Support setting this property in simulation mode. #2462
1 parent 347bbb5 commit 09ee347

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

.changeset/mean-ads-clap.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@jspsych/plugin-fullscreen": minor
3+
---
4+
5+
Plugin now records RT of the button press to launch fullscreen mode and simulation mode supports setting this property

docs/plugins/fullscreen.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ In addition to the [default data collected by all plugins](../overview/plugins.m
2525
Name | Type | Value
2626
-----|------|------
2727
success | boolean | true if the browser supports fullscreen mode (i.e., is not Safari)
28+
rt | number | Response time to click the button that launches fullscreen mode
2829

2930
## Simulation Mode
3031

packages/plugin-fullscreen/src/index.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,23 @@ describe("fullscreen plugin", () => {
2323
clickTarget(document.querySelector("#jspsych-fullscreen-btn"));
2424
expect(document.documentElement.requestFullscreen).toHaveBeenCalled();
2525
});
26+
27+
test("records RT of click", async () => {
28+
const { getData, expectFinished } = await startTimeline([
29+
{
30+
type: fullscreen,
31+
delay_after: 0,
32+
},
33+
]);
34+
35+
expect(document.documentElement.requestFullscreen).not.toHaveBeenCalled();
36+
jest.advanceTimersByTime(1000);
37+
clickTarget(document.querySelector("#jspsych-fullscreen-btn"));
38+
expect(document.documentElement.requestFullscreen).toHaveBeenCalled();
39+
jest.runAllTimers();
40+
await expectFinished();
41+
expect(getData().values()[0].rt).toBeGreaterThanOrEqual(1000);
42+
});
2643
});
2744

2845
describe("fullscreen plugin simulation", () => {
@@ -63,5 +80,6 @@ describe("fullscreen plugin simulation", () => {
6380
await expectFinished();
6481

6582
expect(getData().values()[0].success).toBe(true);
83+
expect(getData().values()[0].rt).toBeGreaterThan(0);
6684
});
6785
});

packages/plugin-fullscreen/src/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ type Info = typeof info;
4747
*/
4848
class FullscreenPlugin implements JsPsychPlugin<Info> {
4949
static info = info;
50+
private rt = null;
51+
private start_time = 0;
5052

5153
constructor(private jsPsych: JsPsych) {}
5254

@@ -73,9 +75,11 @@ class FullscreenPlugin implements JsPsychPlugin<Info> {
7375
<button id="jspsych-fullscreen-btn" class="jspsych-btn">${trial.button_label}</button>
7476
`;
7577
display_element.querySelector("#jspsych-fullscreen-btn").addEventListener("click", () => {
78+
this.rt = Math.round(performance.now() - this.start_time);
7679
this.enterFullScreen();
7780
this.endTrial(display_element, true, trial);
7881
});
82+
this.start_time = performance.now();
7983
}
8084

8185
private endTrial(display_element, success, trial) {
@@ -84,6 +88,7 @@ class FullscreenPlugin implements JsPsychPlugin<Info> {
8488
this.jsPsych.pluginAPI.setTimeout(() => {
8589
var trial_data = {
8690
success: success,
91+
rt: this.rt,
8792
};
8893

8994
this.jsPsych.finishTrial(trial_data);
@@ -137,8 +142,11 @@ class FullscreenPlugin implements JsPsychPlugin<Info> {
137142
}
138143

139144
private create_simulation_data(trial: TrialType<Info>, simulation_options) {
145+
const rt = this.jsPsych.randomization.sampleExGaussian(1000, 100, 1 / 200, true);
146+
140147
const default_data = {
141148
success: true,
149+
rt: rt,
142150
};
143151

144152
const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);
@@ -164,7 +172,7 @@ class FullscreenPlugin implements JsPsychPlugin<Info> {
164172
load_callback();
165173
this.jsPsych.pluginAPI.clickTarget(
166174
display_element.querySelector("#jspsych-fullscreen-btn"),
167-
this.jsPsych.randomization.sampleExGaussian(1000, 100, 1 / 200, true)
175+
data.rt
168176
);
169177
}
170178
}

0 commit comments

Comments
 (0)