@lookit/record 2.0.0 → 3.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.
@@ -1,158 +0,0 @@
1
- import { JsPsych } from "jspsych";
2
- import { CSSWidthHeight } from "./types";
3
- /** Recorder handles the state of recording and data storage. */
4
- export default class Recorder {
5
- private jsPsych;
6
- private url?;
7
- private _s3?;
8
- private blobs;
9
- private localDownload;
10
- private filename?;
11
- private stopPromise?;
12
- private webcam_element_id;
13
- private streamClone;
14
- /**
15
- * Recorder for online experiments.
16
- *
17
- * @param jsPsych - Object supplied by jsPsych.
18
- */
19
- constructor(jsPsych: JsPsych);
20
- /**
21
- * Get recorder from jsPsych plugin API.
22
- *
23
- * If camera recorder hasn't been initialized, then return the microphone
24
- * recorder.
25
- *
26
- * @returns MediaRecorder from the plugin API.
27
- */
28
- private get recorder();
29
- /**
30
- * Get stream from either recorder.
31
- *
32
- * @returns MediaStream from the plugin API.
33
- */
34
- private get stream();
35
- /**
36
- * Get s3 class variable. Throw error if doesn't exist.
37
- *
38
- * @returns - S3 object.
39
- */
40
- private get s3();
41
- /** Set s3 class variable. */
42
- private set s3(value);
43
- /**
44
- * Initialize recorder using the jsPsych plugin API. There should always be a
45
- * stream initialized when the Recorder class is instantiated. This method is
46
- * just used to re-initialize the stream with a clone when the recorder needs
47
- * to be reset during a trial.
48
- *
49
- * @param stream - Media stream returned from getUserMedia that should be used
50
- * to set up the jsPsych recorder.
51
- * @param opts - Media recorder options to use when setting up the recorder.
52
- */
53
- initializeRecorder(stream: MediaStream, opts?: MediaRecorderOptions): void;
54
- /** Reset the recorder to be used again. */
55
- reset(): void;
56
- /**
57
- * Insert a rendered template into an element.
58
- *
59
- * @param element - Element to have video inserted into.
60
- * @param template - Template string
61
- * @param insertStream - Should the stream be attributed to the webcam
62
- * element.
63
- * @returns Webcam element
64
- */
65
- private insertVideoFeed;
66
- /**
67
- * Insert a video element containing the webcam feed onto the page.
68
- *
69
- * @param element - The HTML div element that should serve as the container
70
- * for the webcam display.
71
- * @param width - The width of the video element containing the webcam feed,
72
- * in CSS units (optional). Default is `'100%'`
73
- * @param height - The height of the video element containing the webcam feed,
74
- * in CSS units (optional). Default is `'auto'`
75
- */
76
- insertWebcamFeed(element: HTMLDivElement, width?: CSSWidthHeight, height?: CSSWidthHeight): void;
77
- /**
78
- * Insert video playback feed into supplied element.
79
- *
80
- * @param element - The HTML div element that should serve as the container
81
- * for the webcam display.
82
- * @param on_ended - Callback function called when playing video ends.
83
- * @param width - The width of the video element containing the webcam feed,
84
- * in CSS units (optional). Default is `'100%'`
85
- * @param height - The height of the video element containing the webcam feed,
86
- * in CSS units (optional). Default is `'auto'`
87
- */
88
- insertPlaybackFeed(element: HTMLDivElement, on_ended: (this: HTMLVideoElement, e: Event) => void, width?: CSSWidthHeight, height?: CSSWidthHeight): void;
89
- /**
90
- * Insert a feed to be used for recording into an element.
91
- *
92
- * @param element - Element to have record feed inserted into.
93
- * @param width - The width of the video element containing the webcam feed,
94
- * in CSS units (optional). Default is `'100%'`
95
- * @param height - The height of the video element containing the webcam feed,
96
- * in CSS units (optional). Default is `'auto'`
97
- */
98
- insertRecordFeed(element: HTMLDivElement, width?: CSSWidthHeight, height?: CSSWidthHeight): void;
99
- /**
100
- * Start recording. Also, adds event listeners for handling data and checks
101
- * for recorder initialization.
102
- *
103
- * @param consent - Boolean indicating whether or not the recording is consent
104
- * footage.
105
- * @param trial_type - Trial type, as saved in the jsPsych data. This comes
106
- * from the plugin info "name" value (not the class name).
107
- */
108
- start(consent: boolean, trial_type: string): Promise<void>;
109
- /**
110
- * Stop all streams/tracks. This stops any in-progress recordings and releases
111
- * the media devices. This is can be called when recording is not in progress,
112
- * e.g. To end the camera/mic access when the experiment is displaying the
113
- * camera feed but not recording (e.g. Video-config).
114
- */
115
- stopTracks(): void;
116
- /**
117
- * Stop recording and camera/microphone. This will stop accessing all media
118
- * tracks, clear the webcam feed element (if there is one), and return the
119
- * stop promise. This should only be called after recording has started.
120
- *
121
- * @returns Promise that resolves after the media recorder has stopped and
122
- * final 'dataavailable' event has occurred, when the "stop" event-related
123
- * callback function is called.
124
- */
125
- stop(): Promise<void>;
126
- /** Throw Error if there isn't a recorder provided by jsPsych. */
127
- private initializeCheck;
128
- /**
129
- * Handle the recorder's stop event. This is a function that takes the stop
130
- * promise's 'resolve' as an argument and returns a function that resolves
131
- * that stop promise. The function that is returned is used as the recorder's
132
- * "stop" event-related callback function.
133
- *
134
- * @param resolve - Promise resolve function.
135
- * @returns Function that is called on the recorder's "stop" event.
136
- */
137
- private handleStop;
138
- /**
139
- * Function ran at each time slice and when the recorder stopped.
140
- *
141
- * @param event - Event containing blob data.
142
- */
143
- private handleDataAvailable;
144
- /** Download data url used in local development. */
145
- private download;
146
- /** Private helper to clear the webcam feed, if there is one. */
147
- private clearWebcamFeed;
148
- /**
149
- * Creates a valid video file name based on parameters
150
- *
151
- * @param consent - Boolean indicating whether or not the recording is consent
152
- * footage.
153
- * @param trial_type - Trial type, as saved in the jsPsych data. This comes
154
- * from the plugin info "name" value (not the class name).
155
- * @returns File name string with .webm extension.
156
- */
157
- private createFileName;
158
- }
package/dist/start.d.ts DELETED
@@ -1,24 +0,0 @@
1
- import { JsPsych, JsPsychPlugin } from "jspsych";
2
- declare const info: {
3
- readonly name: "start-record-plugin";
4
- readonly parameters: {};
5
- };
6
- type Info = typeof info;
7
- /** Start recording. Used by researchers who want to record across trials. */
8
- export default class StartRecordPlugin implements JsPsychPlugin<Info> {
9
- private jsPsych;
10
- static readonly info: {
11
- readonly name: "start-record-plugin";
12
- readonly parameters: {};
13
- };
14
- private recorder;
15
- /**
16
- * Plugin used to start recording.
17
- *
18
- * @param jsPsych - Object provided by jsPsych.
19
- */
20
- constructor(jsPsych: JsPsych);
21
- /** Trial function called by jsPsych. */
22
- trial(): void;
23
- }
24
- export {};
package/dist/stop.d.ts DELETED
@@ -1,41 +0,0 @@
1
- import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from "jspsych";
2
- declare const info: {
3
- readonly name: "stop-record-plugin";
4
- readonly parameters: {
5
- readonly locale: {
6
- readonly type: ParameterType.STRING;
7
- readonly default: "en-us";
8
- };
9
- };
10
- };
11
- type Info = typeof info;
12
- /** Stop recording. Used by researchers who want to record across trials. */
13
- export default class StopRecordPlugin implements JsPsychPlugin<Info> {
14
- private jsPsych;
15
- static readonly info: {
16
- readonly name: "stop-record-plugin";
17
- readonly parameters: {
18
- readonly locale: {
19
- readonly type: ParameterType.STRING;
20
- readonly default: "en-us";
21
- };
22
- };
23
- };
24
- private recorder;
25
- /**
26
- * Plugin used to stop recording.
27
- *
28
- * @param jsPsych - Object provided by jsPsych.
29
- */
30
- constructor(jsPsych: JsPsych);
31
- /**
32
- * Trial function called by jsPsych.
33
- *
34
- * @param display_element - DOM element where jsPsych content is being
35
- * rendered (set in initJsPsych and automatically made available to a
36
- * plugin's trial method via jsPsych core).
37
- * @param trial - Trial object with parameters/values.
38
- */
39
- trial(display_element: HTMLElement, trial: TrialType<Info>): void;
40
- }
41
- export {};
package/dist/trial.d.ts DELETED
@@ -1,36 +0,0 @@
1
- import { JsPsych, JsPsychExtension, JsPsychExtensionInfo } from "jspsych";
2
- /** This extension will allow reasearchers to record trials. */
3
- export default class TrialRecordExtension implements JsPsychExtension {
4
- private jsPsych;
5
- static readonly info: JsPsychExtensionInfo;
6
- private recorder?;
7
- private pluginName;
8
- /**
9
- * Video recording extension.
10
- *
11
- * @param jsPsych - JsPsych object passed into extensions.
12
- */
13
- constructor(jsPsych: JsPsych);
14
- /**
15
- * Ran on the initialize step for extensions, called when an instance of
16
- * jsPsych is first initialized through initJsPsych().
17
- */
18
- initialize(): Promise<void>;
19
- /** Ran at the start of a trial. */
20
- on_start(): void;
21
- /** Ran when the trial has loaded. */
22
- on_load(): void;
23
- /**
24
- * Ran when trial has finished.
25
- *
26
- * @returns Trial data.
27
- */
28
- on_finish(): {};
29
- /**
30
- * Gets the plugin name for the trial that is being extended. This is same as
31
- * the "trial_type" value that is stored in the data for this trial.
32
- *
33
- * @returns Plugin name string from the plugin class's info.
34
- */
35
- private getCurrentPluginName;
36
- }
package/dist/types.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import { JsPsychPlugin, PluginInfo } from "jspsych";
2
- import { Class } from "type-fest";
3
- export interface jsPsychPluginWithInfo extends Class<JsPsychPlugin<PluginInfo>> {
4
- info: PluginInfo;
5
- }
6
- /**
7
- * A valid CSS height/width value, which can be a number, a string containing a
8
- * number with units, or 'auto'.
9
- */
10
- export type CSSWidthHeight = number | `${number}${"px" | "cm" | "mm" | "em" | "%"}` | "auto";
@@ -1,312 +0,0 @@
1
- import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from "jspsych";
2
- declare const info: {
3
- readonly name: "video-config-plugin";
4
- readonly version: string;
5
- readonly parameters: {
6
- readonly locale: {
7
- readonly type: ParameterType.STRING;
8
- readonly default: "en-us";
9
- };
10
- readonly troubleshooting_intro: {
11
- /**
12
- * Optional string to appear at the start of the "Setup tips and
13
- * troubleshooting" section.
14
- */
15
- readonly type: ParameterType.HTML_STRING;
16
- readonly default: "";
17
- readonly pretty_name: "Troubleshooting Intro";
18
- };
19
- };
20
- readonly data: {
21
- readonly rt: {
22
- readonly type: ParameterType.INT;
23
- };
24
- readonly camId: {
25
- readonly type: ParameterType.STRING;
26
- };
27
- readonly micId: {
28
- readonly type: ParameterType.STRING;
29
- };
30
- };
31
- };
32
- type Info = typeof info;
33
- export type VideoConsentTrialType = TrialType<Info>;
34
- export declare const html_params: {
35
- webcam_container_id: string;
36
- reload_button_id_text: string;
37
- reload_button_id_cam: string;
38
- camera_selection_id: string;
39
- mic_selection_id: string;
40
- next_button_id: string;
41
- error_msg_div_id: string;
42
- step1_id: string;
43
- step2_id: string;
44
- step3_id: string;
45
- step_complete_class: string;
46
- waiting_for_access_msg_id: string;
47
- checking_mic_msg_id: string;
48
- access_problem_msg_id: string;
49
- setup_problem_msg_id: string;
50
- chromeInitialPrompt: any;
51
- chromeAlwaysAllow: any;
52
- chromePermissions: any;
53
- firefoxInitialPrompt: any;
54
- firefoxChooseDevice: any;
55
- firefoxDevicesBlocked: any;
56
- checkmarkIcon: any;
57
- };
58
- /**
59
- * **Video Config**.
60
- *
61
- * CHS jsPsych plugin for presenting a video recording configuration plugin, to
62
- * help participants set up their webcam and microphone before beginning a study
63
- * that includes video/audio recording. This plugin must be used before any
64
- * other trials in the experiment can access the camera/mic.
65
- *
66
- * @author Becky Gilbert
67
- * @see {@link https://github.com/lookit/lookit-jspsych/blob/main/packages/video-config/README.md video-config plugin documentation on Github}
68
- */
69
- export default class VideoConfigPlugin implements JsPsychPlugin<Info> {
70
- private jsPsych;
71
- static info: {
72
- readonly name: "video-config-plugin";
73
- readonly version: string;
74
- readonly parameters: {
75
- readonly locale: {
76
- readonly type: ParameterType.STRING;
77
- readonly default: "en-us";
78
- };
79
- readonly troubleshooting_intro: {
80
- /**
81
- * Optional string to appear at the start of the "Setup tips and
82
- * troubleshooting" section.
83
- */
84
- readonly type: ParameterType.HTML_STRING;
85
- readonly default: "";
86
- readonly pretty_name: "Troubleshooting Intro";
87
- };
88
- };
89
- readonly data: {
90
- readonly rt: {
91
- readonly type: ParameterType.INT;
92
- };
93
- readonly camId: {
94
- readonly type: ParameterType.STRING;
95
- };
96
- readonly micId: {
97
- readonly type: ParameterType.STRING;
98
- };
99
- };
100
- };
101
- private display_el;
102
- private start_time;
103
- private recorder;
104
- private hasReloaded;
105
- private response;
106
- private camId;
107
- private micId;
108
- private minVolume;
109
- private micChecked;
110
- private processorNode;
111
- /**
112
- * Constructor for video config plugin.
113
- *
114
- * @param jsPsych - JsPsych object automatically passed into the constructor.
115
- */
116
- constructor(jsPsych: JsPsych);
117
- /**
118
- * Trial method called by jsPsych.
119
- *
120
- * @param display_element - Element where the jsPsych trial will be displayed.
121
- * @param trial - Trial object with parameters/values.
122
- */
123
- trial(display_element: HTMLElement, trial: VideoConsentTrialType): void;
124
- /**
125
- * Add HTML content to the page.
126
- *
127
- * @param trial - Trial object.
128
- */
129
- private addHtmlContent;
130
- /** Add event listeners to elements after they've been added to the page. */
131
- private addEventListeners;
132
- /**
133
- * Access media devices, populate device lists, setup the jsPsych
134
- * camera/stream and Recorder instance, and run the permissions/mic checks.
135
- * This is run when the trial first loads and anytime the user clicks the
136
- * reload recorder button.
137
- *
138
- * 1. Request permissions.
139
- * 2. Enumerate devices and populate the device selection elements with options.
140
- * 3. Initialize the jsPsych recorder with the current/selected devices, and
141
- * create a new Recorder.
142
- * 4. Run the stream checks. (If completed successfully, this will clear any
143
- * error messages and enable the next button).
144
- */
145
- private setupRecorder;
146
- /**
147
- * Request permission to use the webcam and/or microphone. This can be used
148
- * with and without specific device selection (and other constraints).
149
- *
150
- * @param constraints - Media stream constraints object with 'video' and
151
- * 'audio' properties, whose values can be boolean or a
152
- * MediaTrackConstraints object or undefined.
153
- * @param constraints.video - If false, do not include video. If true, use the
154
- * default webcam device. If a media track constraints object is passed,
155
- * then it can contain the properties of all media tracks and video tracks:
156
- * https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints.
157
- * @param constraints.audio - If false, do not include audio. If true, use the
158
- * default mic device. If a media track constraints object is passed, then
159
- * it can contain the properties of all media tracks and audio tracks:
160
- * https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints.
161
- * @returns Camera/microphone stream.
162
- */
163
- private requestPermission;
164
- /**
165
- * Receives device lists and populates the device selection HTML elements.
166
- * This is run when the trial loads, and in response to changes to the
167
- * available devices.
168
- *
169
- * @param devices - Object with properties 'cameras' and 'mics', which are
170
- * arrays containing lists of available devices.
171
- * @param devices.cameras - Array of MediaDeviceInfo objects for webcam/video
172
- * input devices.
173
- * @param devices.mics - Array of MediaDeviceInfo objects for mic/audio input
174
- * devices.
175
- */
176
- private updateDeviceSelection;
177
- /**
178
- * Takes the selected device IDs from the camera/mic selection elements, gets
179
- * the streams for these devices, sets these as the input devices via
180
- * jsPsych.pluginAPI.initializeCameraRecorder, and creates a new Recorder.
181
- */
182
- private setDevices;
183
- /**
184
- * Run the stream checks after permissions have been granted and devices have
185
- * been selected. This is run when the trial first loads, after permissions
186
- * are granted, and in response to changes to the device selection. It checks
187
- * for (1) the existence of the required streams, (2) minimum microphone input
188
- * level (when audio is included), and (3) media permissions (via recorder
189
- * destroy/reload). This runs the stream checks, updates the info/error
190
- * messages, enables the next button, and handles errors. This is factored out
191
- * of the set up process (setupRecorder) because it is also triggered by a
192
- * change in the cam/mic device selection.
193
- */
194
- private runStreamChecks;
195
- /**
196
- * If there is a change to the available devices, then we need to: (1) get the
197
- * updated device lists, and (2) update the select elements with these list
198
- * elements.
199
- */
200
- private onDeviceChange;
201
- /**
202
- * Gets the lists of available cameras and mics (via Media Devices
203
- * 'enumerateDevices'). These lists can be used to populate camera/mic
204
- * selection elements.
205
- *
206
- * @param include_audio - Whether or not to include audio capture (mic)
207
- * devices. Optional, default is true.
208
- * @param include_camera - Whether or not to include the webcam (video)
209
- * devices. Optional, default is true.
210
- * @returns Object with properties 'cameras' and 'mics', containing lists of
211
- * available devices.
212
- */
213
- private getDeviceLists;
214
- /**
215
- * Initialize recorder using the jsPsych plugin API. This must be called
216
- * before running the stream checks.
217
- *
218
- * @param stream - Media stream returned from getUserMedia that should be used
219
- * to set up the jsPsych recorder.
220
- * @param opts - Media recorder options to use when setting up the recorder.
221
- */
222
- initializeAndCreateRecorder: (stream: MediaStream, opts?: MediaRecorderOptions) => void;
223
- /**
224
- * Perform a sound check on the audio input (microphone).
225
- *
226
- * @param minVol - Minimum mic activity needed to reach the mic check
227
- * threshold (optional). Default is `this.minVolume`
228
- * @returns Promise that resolves when the mic check is complete because the
229
- * audio stream has reached the required minimum level.
230
- */
231
- private checkMic;
232
- /**
233
- * Handle the mic level messages that are sent via an AudioWorkletProcessor.
234
- * This checks the current level against the minimum threshold, and if the
235
- * threshold is met, sets the micChecked property to true and resolves the
236
- * checkMic promise.
237
- *
238
- * @param currentActivityLevel - Microphone activity level calculated by the
239
- * processor node.
240
- * @param minVolume - Minimum microphone activity level needed to pass the
241
- * microphone check.
242
- * @param resolve - Resolve callback function for Promise returned by the
243
- * checkMic method.
244
- */
245
- private onMicActivityLevel;
246
- /**
247
- * Creates the processor node for the mic check input level processing, and
248
- * connects the microphone to the processor node.
249
- *
250
- * @param audioContext - Audio context that was created in checkMic. This is
251
- * used to create the processor node.
252
- * @param microphone - Microphone audio stream source, created in checkMic.
253
- * The processor node will be connected to this source.
254
- * @returns Promise that resolves after the processor node has been created,
255
- * and the microphone audio stream source is connected to the processor node
256
- * and audio context destination.
257
- */
258
- private createConnectProcessor;
259
- /**
260
- * Set up the port's on message event handler for the mic check processor
261
- * node. This adds the event related callback, which calls onMicActivityLevel
262
- * with the event data.
263
- *
264
- * @param minVol - Minimum volume level (RMS amplitude) passed from checkMic.
265
- * @returns Promise that resolves from inside the onMicActivityLevel callback,
266
- * when the mic stream input level has reached the threshold.
267
- */
268
- private setupPortOnMessage;
269
- /**
270
- * Update the instructions for a given step, based on whether or not the check
271
- * has passed for that step.
272
- *
273
- * @param step - Which instructions step to update. 1 = stream access, 2 =
274
- * reload complete, 3 = mic level check.
275
- * @param checkPassed - Whether or not the mic check has passed.
276
- */
277
- private updateInstructions;
278
- /**
279
- * Update the errors/messages div with information for the user about the
280
- * camera/mic checks.
281
- *
282
- * @param errorMsgId - Span element ID containing the message to display in
283
- * the error message div. Call the function without an errorMsgId to clear
284
- * the errors.
285
- */
286
- private updateErrors;
287
- /**
288
- * Collect trial data and end the trial. JsPsych.finishTrial takes the
289
- * plugin's trial data as an argument, ends the trial, and moves on to the
290
- * next trial in the experiment timeline.
291
- */
292
- private endTrial;
293
- /**
294
- * Destroy the recorder. This is used to stop the streams at the end of the
295
- * trial, and as part of the reload check to test the user's browser
296
- * permissions by mimicking the start of a new trial (i.e. stop streams and
297
- * then create a new Recorder instance).
298
- */
299
- private destroyRecorder;
300
- /** Handle the next button click event. */
301
- private nextButtonClick;
302
- /** Handle the reload recorder button click event. */
303
- private reloadButtonClick;
304
- /**
305
- * Toggle the next button disable property.
306
- *
307
- * @param enable - Whether to enable (true) or disable (false) the next
308
- * button.
309
- */
310
- private enableNext;
311
- }
312
- export {};