@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/dist/errors.d.ts DELETED
@@ -1,149 +0,0 @@
1
- /** Error thrown when recorder is null. */
2
- export declare class RecorderInitializeError extends Error {
3
- /**
4
- * When there isn't a recorder, provide the user with an explanation of what
5
- * they could do to resolve the issue.
6
- */
7
- constructor();
8
- }
9
- /** Error thrown when stream is inactive and recorder is started. */
10
- export declare class StreamInactiveInitializeError extends Error {
11
- /**
12
- * Error check on initialize. Attempting to validate recorder is ready to
13
- * start recording.
14
- */
15
- constructor();
16
- }
17
- /** Error thrown when stream data is available and recorder is started. */
18
- export declare class StreamDataInitializeError extends Error {
19
- /**
20
- * Error check on recorder initialize. Attempt to validate recorder data array
21
- * is empty and ready to start recording.
22
- */
23
- constructor();
24
- }
25
- /**
26
- * Error thrown when trying to stop an active session recording that cannot be
27
- * found.
28
- */
29
- export declare class NoSessionRecordingError extends Error {
30
- /**
31
- * When trying to stop a recording that isn't found, provide the user with an
32
- * explanation of what they could do to resolve the issue.
33
- */
34
- constructor();
35
- }
36
- /**
37
- * Error thrown when trying to trying to start a recording while another is
38
- * already active.
39
- */
40
- export declare class ExistingRecordingError extends Error {
41
- /**
42
- * When trying to start a recording but there is already an active recording
43
- * in progress, provide the user with an explanation of what they could do to
44
- * resolve the issue.
45
- */
46
- constructor();
47
- }
48
- /**
49
- * Error thrown when trying to to stop the recorder and the stop promise doesn't
50
- * exist.
51
- */
52
- export declare class NoStopPromiseError extends Error {
53
- /**
54
- * When attempting to stop a recording but there's no stop promise to ensure
55
- * the stop has completed.
56
- */
57
- constructor();
58
- }
59
- /**
60
- * Error thrown when attempting an action that relies on an input stream, such
61
- * as the mic volume check, but no such stream is found.
62
- */
63
- export declare class NoStreamError extends Error {
64
- /**
65
- * When attempting an action that requires an input stream, such as the mic
66
- * check, but no stream is found.
67
- */
68
- constructor();
69
- }
70
- /**
71
- * Error thrown if there's a problem setting up the microphone input level
72
- * check.
73
- */
74
- export declare class MicCheckError extends Error {
75
- /**
76
- * Occurs if there's a problem setting up the mic check, including setting up
77
- * the audio context and stream source, loading the audio worklet processor
78
- * script, setting up the port message event handler, and resolving the
79
- * promise chain via message events passed to onMicActivityLevel.
80
- *
81
- * @param err - Error passed into this error that is thrown in the catch
82
- * block, if any. Errors passed to catch blocks must have type unknown.
83
- */
84
- constructor(err: unknown);
85
- }
86
- /**
87
- * Error thrown when attempting to access S3 object and it's, unknowingly,
88
- * undefined.
89
- */
90
- export declare class S3UndefinedError extends Error {
91
- /**
92
- * Provide feed back when recorder attempts to use S3 object and it's
93
- * undefined.
94
- */
95
- constructor();
96
- }
97
- /**
98
- * Error thrown when attempting to reset recorder, but its stream is still
99
- * active.
100
- */
101
- export declare class StreamActiveOnResetError extends Error {
102
- /**
103
- * This error will be thrown when developer attempts to reset recorder while
104
- * active.
105
- */
106
- constructor();
107
- }
108
- /** Error thrown when attempting to select webcam element and it's not found. */
109
- export declare class NoWebCamElementError extends Error {
110
- /**
111
- * Error thrown when attempting to retrieve webcam element and it's not in the
112
- * DOM.
113
- */
114
- constructor();
115
- }
116
- /**
117
- * Error thrown when attempting to create playback/download url and data array
118
- * is empty.
119
- */
120
- export declare class CreateURLError extends Error {
121
- /**
122
- * Throw this error when data array is empty and url still needs to be
123
- * created. Sometimes this means the "reset()" method was called too early.
124
- */
125
- constructor();
126
- }
127
- /** Error thrown when video container couldn't be found. */
128
- export declare class VideoContainerNotFoundError extends Error {
129
- /** No video container found. */
130
- constructor();
131
- }
132
- /** Error thrown when button not found. */
133
- export declare class ButtonNotFoundError extends Error {
134
- /**
135
- * Button couldn't be found by ID field.
136
- *
137
- * @param id - HTML ID parameter.
138
- */
139
- constructor(id: string);
140
- }
141
- /** Throw Error when image couldn't be found. */
142
- export declare class ImageNotFoundError extends Error {
143
- /**
144
- * Error when image couldn't be found by ID field.
145
- *
146
- * @param id - HTML ID parameter
147
- */
148
- constructor(id: string);
149
- }
@@ -1,33 +0,0 @@
1
- /**
2
- * Audio Worklet Processor class for processing audio input streams. This is
3
- * used by the Recorder to run a volume check on the microphone input stream.
4
- * Source:
5
- * https://www.webrtc-developers.com/how-to-know-if-my-microphone-works/#detect-noise-or-silence
6
- */
7
- export default class MicCheckProcessor extends AudioWorkletProcessor {
8
- private _volume;
9
- private _micChecked;
10
- /** Constructor for the mic check processor. */
11
- constructor();
12
- /**
13
- * Process method that implements the audio processing algorithm for the Audio
14
- * Processor Worklet. "Although the method is not a part of the
15
- * AudioWorkletProcessor interface, any implementation of
16
- * AudioWorkletProcessor must provide a process() method." Source:
17
- * https://developer.mozilla.org/en-US/docs/Web/API/AudioWorkletProcessor/process
18
- * The process method can take the following arguments: inputs, outputs,
19
- * parameters. Here we are only using inputs.
20
- *
21
- * @param inputs - An array of inputs from the audio stream (microphone)
22
- * connnected to the node. Each item in the inputs array is an array of
23
- * channels. Each channel is a Float32Array containing 128 samples. For
24
- * example, inputs[n][m][i] will access n-th input, m-th channel of that
25
- * input, and i-th sample of that channel.
26
- * @returns Boolean indicating whether or not the Audio Worklet Node should
27
- * remain active, even if the User Agent thinks it is safe to shut down. In
28
- * this case, when the recorder decides that the mic check criteria has been
29
- * met, it will return false (processor should be shut down), otherwise it
30
- * will return true (processor should remain active).
31
- */
32
- process(inputs: Float32Array[][]): boolean;
33
- }
@@ -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,30 +0,0 @@
1
- import { JsPsych, JsPsychPlugin } from "jspsych";
2
- declare const info: {
3
- readonly name: "stop-record-plugin";
4
- readonly parameters: {};
5
- };
6
- type Info = typeof info;
7
- /** Stop recording. Used by researchers who want to record across trials. */
8
- export default class StopRecordPlugin implements JsPsychPlugin<Info> {
9
- private jsPsych;
10
- static readonly info: {
11
- readonly name: "stop-record-plugin";
12
- readonly parameters: {};
13
- };
14
- private recorder;
15
- /**
16
- * Plugin used to stop recording.
17
- *
18
- * @param jsPsych - Object provided by jsPsych.
19
- */
20
- constructor(jsPsych: JsPsych);
21
- /**
22
- * Trial function called by jsPsych.
23
- *
24
- * @param display_element - DOM element where jsPsych content is being
25
- * rendered (set in initJsPsych and automatically made available to a
26
- * plugin's trial method via jsPsych core).
27
- */
28
- trial(display_element: HTMLElement): void;
29
- }
30
- 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";