@lookit/record 1.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.
- package/README.md +87 -85
- package/dist/index.browser.js +9082 -9918
- package/dist/index.browser.js.map +1 -1
- package/dist/index.browser.min.js +50 -2
- package/dist/index.browser.min.js.map +1 -1
- package/dist/index.cjs +854 -10006
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +760 -6
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +854 -10006
- package/dist/index.js.map +1 -1
- package/package.json +8 -13
- package/src/index.spec.ts +6 -2
- package/src/index.ts +1 -1
- package/src/recorder.spec.ts +1 -1
- package/src/stop.ts +11 -6
- package/src/{video_config.spec.ts → videoConfig.spec.ts} +70 -85
- package/src/{video_config.ts → videoConfig.ts} +70 -72
- package/src/{video_config_mic_check.spec.ts → videoConfig_mic_check.spec.ts} +1 -1
- package/dist/consentVideo.d.ts +0 -370
- package/dist/errors.d.ts +0 -149
- package/dist/mic_check.d.ts +0 -33
- package/dist/recorder.d.ts +0 -158
- package/dist/start.d.ts +0 -24
- package/dist/stop.d.ts +0 -30
- package/dist/trial.d.ts +0 -36
- package/dist/types.d.ts +0 -10
- package/dist/video_config.d.ts +0 -296
package/dist/video_config.d.ts
DELETED
|
@@ -1,296 +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 troubleshooting_intro: {
|
|
7
|
-
/**
|
|
8
|
-
* Optional string to appear at the start of the "Setup tips and
|
|
9
|
-
* troubleshooting" section.
|
|
10
|
-
*/
|
|
11
|
-
readonly type: ParameterType.HTML_STRING;
|
|
12
|
-
readonly default: "";
|
|
13
|
-
readonly pretty_name: "Troubleshooting Intro";
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
readonly data: {
|
|
17
|
-
readonly rt: {
|
|
18
|
-
readonly type: ParameterType.INT;
|
|
19
|
-
};
|
|
20
|
-
readonly camId: {
|
|
21
|
-
readonly type: ParameterType.STRING;
|
|
22
|
-
};
|
|
23
|
-
readonly micId: {
|
|
24
|
-
readonly type: ParameterType.STRING;
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
type Info = typeof info;
|
|
29
|
-
export type VideoConsentTrialType = TrialType<Info>;
|
|
30
|
-
/**
|
|
31
|
-
* **Video Config**.
|
|
32
|
-
*
|
|
33
|
-
* CHS jsPsych plugin for presenting a video recording configuration plugin, to
|
|
34
|
-
* help participants set up their webcam and microphone before beginning a study
|
|
35
|
-
* that includes video/audio recording. This plugin must be used before any
|
|
36
|
-
* other trials in the experiment can access the camera/mic.
|
|
37
|
-
*
|
|
38
|
-
* @author Becky Gilbert
|
|
39
|
-
* @see {@link https://github.com/lookit/lookit-jspsych/blob/main/packages/video-config/README.md video-config plugin documentation on Github}
|
|
40
|
-
*/
|
|
41
|
-
export default class VideoConfigPlugin implements JsPsychPlugin<Info> {
|
|
42
|
-
private jsPsych;
|
|
43
|
-
static info: {
|
|
44
|
-
readonly name: "video-config-plugin";
|
|
45
|
-
readonly version: string;
|
|
46
|
-
readonly parameters: {
|
|
47
|
-
readonly troubleshooting_intro: {
|
|
48
|
-
/**
|
|
49
|
-
* Optional string to appear at the start of the "Setup tips and
|
|
50
|
-
* troubleshooting" section.
|
|
51
|
-
*/
|
|
52
|
-
readonly type: ParameterType.HTML_STRING;
|
|
53
|
-
readonly default: "";
|
|
54
|
-
readonly pretty_name: "Troubleshooting Intro";
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
readonly data: {
|
|
58
|
-
readonly rt: {
|
|
59
|
-
readonly type: ParameterType.INT;
|
|
60
|
-
};
|
|
61
|
-
readonly camId: {
|
|
62
|
-
readonly type: ParameterType.STRING;
|
|
63
|
-
};
|
|
64
|
-
readonly micId: {
|
|
65
|
-
readonly type: ParameterType.STRING;
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
};
|
|
69
|
-
private display_el;
|
|
70
|
-
private start_time;
|
|
71
|
-
private recorder;
|
|
72
|
-
private hasReloaded;
|
|
73
|
-
private response;
|
|
74
|
-
private camId;
|
|
75
|
-
private micId;
|
|
76
|
-
private minVolume;
|
|
77
|
-
private micChecked;
|
|
78
|
-
private processorNode;
|
|
79
|
-
private webcam_container_id;
|
|
80
|
-
private reload_button_id_text;
|
|
81
|
-
private reload_button_id_cam;
|
|
82
|
-
private camera_selection_id;
|
|
83
|
-
private mic_selection_id;
|
|
84
|
-
private next_button_id;
|
|
85
|
-
private error_msg_div_id;
|
|
86
|
-
private step1_id;
|
|
87
|
-
private step2_id;
|
|
88
|
-
private step3_id;
|
|
89
|
-
private step_complete_class;
|
|
90
|
-
private step_complete_text;
|
|
91
|
-
private waiting_for_access_msg;
|
|
92
|
-
private checking_mic_msg;
|
|
93
|
-
private access_problem_msg;
|
|
94
|
-
private setup_problem_msg;
|
|
95
|
-
/**
|
|
96
|
-
* Constructor for video config plugin.
|
|
97
|
-
*
|
|
98
|
-
* @param jsPsych - JsPsych object automatically passed into the constructor.
|
|
99
|
-
*/
|
|
100
|
-
constructor(jsPsych: JsPsych);
|
|
101
|
-
/**
|
|
102
|
-
* Trial method called by jsPsych.
|
|
103
|
-
*
|
|
104
|
-
* @param display_element - Element where the jsPsych trial will be displayed.
|
|
105
|
-
* @param trial - Trial object with parameters/values.
|
|
106
|
-
*/
|
|
107
|
-
trial(display_element: HTMLElement, trial: VideoConsentTrialType): void;
|
|
108
|
-
/**
|
|
109
|
-
* Add HTML content to the page.
|
|
110
|
-
*
|
|
111
|
-
* @param troubleshooting_intro - Troubleshooting intro parameter from the
|
|
112
|
-
* Trial object.
|
|
113
|
-
*/
|
|
114
|
-
private addHtmlContent;
|
|
115
|
-
/** Add event listeners to elements after they've been added to the page. */
|
|
116
|
-
private addEventListeners;
|
|
117
|
-
/**
|
|
118
|
-
* Access media devices, populate device lists, setup the jsPsych
|
|
119
|
-
* camera/stream and Recorder instance, and run the permissions/mic checks.
|
|
120
|
-
* This is run when the trial first loads and anytime the user clicks the
|
|
121
|
-
* reload recorder button.
|
|
122
|
-
*
|
|
123
|
-
* 1. Request permissions.
|
|
124
|
-
* 2. Enumerate devices and populate the device selection elements with options.
|
|
125
|
-
* 3. Initialize the jsPsych recorder with the current/selected devices, and
|
|
126
|
-
* create a new Recorder.
|
|
127
|
-
* 4. Run the stream checks. (If completed successfully, this will clear any
|
|
128
|
-
* error messages and enable the next button).
|
|
129
|
-
*/
|
|
130
|
-
private setupRecorder;
|
|
131
|
-
/**
|
|
132
|
-
* Request permission to use the webcam and/or microphone. This can be used
|
|
133
|
-
* with and without specific device selection (and other constraints).
|
|
134
|
-
*
|
|
135
|
-
* @param constraints - Media stream constraints object with 'video' and
|
|
136
|
-
* 'audio' properties, whose values can be boolean or a
|
|
137
|
-
* MediaTrackConstraints object or undefined.
|
|
138
|
-
* @param constraints.video - If false, do not include video. If true, use the
|
|
139
|
-
* default webcam device. If a media track constraints object is passed,
|
|
140
|
-
* then it can contain the properties of all media tracks and video tracks:
|
|
141
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints.
|
|
142
|
-
* @param constraints.audio - If false, do not include audio. If true, use the
|
|
143
|
-
* default mic device. If a media track constraints object is passed, then
|
|
144
|
-
* it can contain the properties of all media tracks and audio tracks:
|
|
145
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints.
|
|
146
|
-
* @returns Camera/microphone stream.
|
|
147
|
-
*/
|
|
148
|
-
private requestPermission;
|
|
149
|
-
/**
|
|
150
|
-
* Receives device lists and populates the device selection HTML elements.
|
|
151
|
-
* This is run when the trial loads, and in response to changes to the
|
|
152
|
-
* available devices.
|
|
153
|
-
*
|
|
154
|
-
* @param devices - Object with properties 'cameras' and 'mics', which are
|
|
155
|
-
* arrays containing lists of available devices.
|
|
156
|
-
* @param devices.cameras - Array of MediaDeviceInfo objects for webcam/video
|
|
157
|
-
* input devices.
|
|
158
|
-
* @param devices.mics - Array of MediaDeviceInfo objects for mic/audio input
|
|
159
|
-
* devices.
|
|
160
|
-
*/
|
|
161
|
-
private updateDeviceSelection;
|
|
162
|
-
/**
|
|
163
|
-
* Takes the selected device IDs from the camera/mic selection elements, gets
|
|
164
|
-
* the streams for these devices, sets these as the input devices via
|
|
165
|
-
* jsPsych.pluginAPI.initializeCameraRecorder, and creates a new Recorder.
|
|
166
|
-
*/
|
|
167
|
-
private setDevices;
|
|
168
|
-
/**
|
|
169
|
-
* Run the stream checks after permissions have been granted and devices have
|
|
170
|
-
* been selected. This is run when the trial first loads, after permissions
|
|
171
|
-
* are granted, and in response to changes to the device selection. It checks
|
|
172
|
-
* for (1) the existence of the required streams, (2) minimum microphone input
|
|
173
|
-
* level (when audio is included), and (3) media permissions (via recorder
|
|
174
|
-
* destroy/reload). This runs the stream checks, updates the info/error
|
|
175
|
-
* messages, enables the next button, and handles errors. This is factored out
|
|
176
|
-
* of the set up process (setupRecorder) because it is also triggered by a
|
|
177
|
-
* change in the cam/mic device selection.
|
|
178
|
-
*/
|
|
179
|
-
private runStreamChecks;
|
|
180
|
-
/**
|
|
181
|
-
* If there is a change to the available devices, then we need to: (1) get the
|
|
182
|
-
* updated device lists, and (2) update the select elements with these list
|
|
183
|
-
* elements.
|
|
184
|
-
*/
|
|
185
|
-
private onDeviceChange;
|
|
186
|
-
/**
|
|
187
|
-
* Gets the lists of available cameras and mics (via Media Devices
|
|
188
|
-
* 'enumerateDevices'). These lists can be used to populate camera/mic
|
|
189
|
-
* selection elements.
|
|
190
|
-
*
|
|
191
|
-
* @param include_audio - Whether or not to include audio capture (mic)
|
|
192
|
-
* devices. Optional, default is true.
|
|
193
|
-
* @param include_camera - Whether or not to include the webcam (video)
|
|
194
|
-
* devices. Optional, default is true.
|
|
195
|
-
* @returns Object with properties 'cameras' and 'mics', containing lists of
|
|
196
|
-
* available devices.
|
|
197
|
-
*/
|
|
198
|
-
private getDeviceLists;
|
|
199
|
-
/**
|
|
200
|
-
* Initialize recorder using the jsPsych plugin API. This must be called
|
|
201
|
-
* before running the stream checks.
|
|
202
|
-
*
|
|
203
|
-
* @param stream - Media stream returned from getUserMedia that should be used
|
|
204
|
-
* to set up the jsPsych recorder.
|
|
205
|
-
* @param opts - Media recorder options to use when setting up the recorder.
|
|
206
|
-
*/
|
|
207
|
-
initializeAndCreateRecorder: (stream: MediaStream, opts?: MediaRecorderOptions) => void;
|
|
208
|
-
/**
|
|
209
|
-
* Perform a sound check on the audio input (microphone).
|
|
210
|
-
*
|
|
211
|
-
* @param minVol - Minimum mic activity needed to reach the mic check
|
|
212
|
-
* threshold (optional). Default is `this.minVolume`
|
|
213
|
-
* @returns Promise that resolves when the mic check is complete because the
|
|
214
|
-
* audio stream has reached the required minimum level.
|
|
215
|
-
*/
|
|
216
|
-
private checkMic;
|
|
217
|
-
/**
|
|
218
|
-
* Handle the mic level messages that are sent via an AudioWorkletProcessor.
|
|
219
|
-
* This checks the current level against the minimum threshold, and if the
|
|
220
|
-
* threshold is met, sets the micChecked property to true and resolves the
|
|
221
|
-
* checkMic promise.
|
|
222
|
-
*
|
|
223
|
-
* @param currentActivityLevel - Microphone activity level calculated by the
|
|
224
|
-
* processor node.
|
|
225
|
-
* @param minVolume - Minimum microphone activity level needed to pass the
|
|
226
|
-
* microphone check.
|
|
227
|
-
* @param resolve - Resolve callback function for Promise returned by the
|
|
228
|
-
* checkMic method.
|
|
229
|
-
*/
|
|
230
|
-
private onMicActivityLevel;
|
|
231
|
-
/**
|
|
232
|
-
* Creates the processor node for the mic check input level processing, and
|
|
233
|
-
* connects the microphone to the processor node.
|
|
234
|
-
*
|
|
235
|
-
* @param audioContext - Audio context that was created in checkMic. This is
|
|
236
|
-
* used to create the processor node.
|
|
237
|
-
* @param microphone - Microphone audio stream source, created in checkMic.
|
|
238
|
-
* The processor node will be connected to this source.
|
|
239
|
-
* @returns Promise that resolves after the processor node has been created,
|
|
240
|
-
* and the microphone audio stream source is connected to the processor node
|
|
241
|
-
* and audio context destination.
|
|
242
|
-
*/
|
|
243
|
-
private createConnectProcessor;
|
|
244
|
-
/**
|
|
245
|
-
* Set up the port's on message event handler for the mic check processor
|
|
246
|
-
* node. This adds the event related callback, which calls onMicActivityLevel
|
|
247
|
-
* with the event data.
|
|
248
|
-
*
|
|
249
|
-
* @param minVol - Minimum volume level (RMS amplitude) passed from checkMic.
|
|
250
|
-
* @returns Promise that resolves from inside the onMicActivityLevel callback,
|
|
251
|
-
* when the mic stream input level has reached the threshold.
|
|
252
|
-
*/
|
|
253
|
-
private setupPortOnMessage;
|
|
254
|
-
/**
|
|
255
|
-
* Update the instructions for a given step, based on whether or not the check
|
|
256
|
-
* has passed for that step.
|
|
257
|
-
*
|
|
258
|
-
* @param step - Which instructions step to update. 1 = stream access, 2 =
|
|
259
|
-
* reload complete, 3 = mic level check.
|
|
260
|
-
* @param checkPassed - Whether or not the mic check has passed.
|
|
261
|
-
*/
|
|
262
|
-
private updateInstructions;
|
|
263
|
-
/**
|
|
264
|
-
* Update the errors/messages div with information for the user about the
|
|
265
|
-
* camera/mic checks.
|
|
266
|
-
*
|
|
267
|
-
* @param errorMsg - Message to display in the error message div. Pass an
|
|
268
|
-
* empty string to clear any existing errors/messages.
|
|
269
|
-
*/
|
|
270
|
-
private updateErrors;
|
|
271
|
-
/**
|
|
272
|
-
* Collect trial data and end the trial. JsPsych.finishTrial takes the
|
|
273
|
-
* plugin's trial data as an argument, ends the trial, and moves on to the
|
|
274
|
-
* next trial in the experiment timeline.
|
|
275
|
-
*/
|
|
276
|
-
private endTrial;
|
|
277
|
-
/**
|
|
278
|
-
* Destroy the recorder. This is used to stop the streams at the end of the
|
|
279
|
-
* trial, and as part of the reload check to test the user's browser
|
|
280
|
-
* permissions by mimicking the start of a new trial (i.e. stop streams and
|
|
281
|
-
* then create a new Recorder instance).
|
|
282
|
-
*/
|
|
283
|
-
private destroyRecorder;
|
|
284
|
-
/** Handle the next button click event. */
|
|
285
|
-
private nextButtonClick;
|
|
286
|
-
/** Handle the reload recorder button click event. */
|
|
287
|
-
private reloadButtonClick;
|
|
288
|
-
/**
|
|
289
|
-
* Toggle the next button disable property.
|
|
290
|
-
*
|
|
291
|
-
* @param enable - Whether to enable (true) or disable (false) the next
|
|
292
|
-
* button.
|
|
293
|
-
*/
|
|
294
|
-
private enableNext;
|
|
295
|
-
}
|
|
296
|
-
export {};
|