@lookit/record 4.0.0 → 5.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 +199 -8
- package/dist/index.browser.js +257 -39
- package/dist/index.browser.js.map +1 -1
- package/dist/index.browser.min.js +16 -16
- package/dist/index.browser.min.js.map +1 -1
- package/dist/index.cjs +256 -38
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +185 -14
- package/dist/index.js +256 -38
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/consentVideo.spec.ts +9 -1
- package/src/consentVideo.ts +10 -2
- package/src/errors.ts +28 -0
- package/src/index.spec.ts +835 -17
- package/src/recorder.spec.ts +677 -73
- package/src/recorder.ts +191 -35
- package/src/start.ts +51 -5
- package/src/stop.ts +56 -5
- package/src/trial.ts +128 -16
- package/src/types.ts +21 -0
- package/src/utils.spec.ts +129 -0
- package/src/utils.ts +45 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lookit/record",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Recording extensions and plugins for CHS studies.",
|
|
5
5
|
"homepage": "https://github.com/lookit/lookit-jspsych#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"typescript": "^5.6.2"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"@lookit/data": "^0.
|
|
45
|
-
"@lookit/templates": "^
|
|
44
|
+
"@lookit/data": "^0.3.0",
|
|
45
|
+
"@lookit/templates": "^3.0.0",
|
|
46
46
|
"jspsych": "^8.0.3"
|
|
47
47
|
}
|
|
48
48
|
}
|
package/src/consentVideo.spec.ts
CHANGED
|
@@ -8,6 +8,7 @@ import recordFeed from "../hbs/record-feed.hbs";
|
|
|
8
8
|
import { VideoConsentPlugin } from "./consentVideo";
|
|
9
9
|
import { ElementNotFoundError } from "./errors";
|
|
10
10
|
import Recorder from "./recorder";
|
|
11
|
+
import type { StopOptions, StopResult } from "./types";
|
|
11
12
|
|
|
12
13
|
declare const window: LookitWindow;
|
|
13
14
|
|
|
@@ -288,6 +289,14 @@ test("playButton", () => {
|
|
|
288
289
|
});
|
|
289
290
|
|
|
290
291
|
test("stopButton", async () => {
|
|
292
|
+
// We need to mock the return values for Recorder.stop because it is called in the stop button's callback function
|
|
293
|
+
(
|
|
294
|
+
Recorder.prototype.stop as jest.Mock<StopResult, [StopOptions?]>
|
|
295
|
+
).mockImplementation(() => ({
|
|
296
|
+
stopped: Promise.resolve("mock-url"),
|
|
297
|
+
uploaded: Promise.resolve(),
|
|
298
|
+
}));
|
|
299
|
+
|
|
291
300
|
const jsPsych = initJsPsych();
|
|
292
301
|
const plugin = new VideoConsentPlugin(jsPsych);
|
|
293
302
|
const display = document.createElement("div");
|
|
@@ -310,7 +319,6 @@ test("stopButton", async () => {
|
|
|
310
319
|
.forEach((button) => expect(button.disabled).toBeFalsy());
|
|
311
320
|
expect(stopButton!.disabled).toBeTruthy();
|
|
312
321
|
expect(Recorder.prototype.stop).toHaveBeenCalledTimes(1);
|
|
313
|
-
expect(Recorder.prototype.reset).toHaveBeenCalledTimes(1);
|
|
314
322
|
expect(plugin["recordFeed"]).toHaveBeenCalledTimes(1);
|
|
315
323
|
expect(plugin["recordFeed"]).toHaveBeenCalledWith(display);
|
|
316
324
|
});
|
package/src/consentVideo.ts
CHANGED
|
@@ -59,6 +59,11 @@ const info = <const>{
|
|
|
59
59
|
consent_statement_text: { type: ParameterType.STRING, default: "" },
|
|
60
60
|
omit_injury_phrase: { type: ParameterType.BOOL, default: false },
|
|
61
61
|
},
|
|
62
|
+
data: {
|
|
63
|
+
chs_type: {
|
|
64
|
+
type: ParameterType.STRING,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
62
67
|
};
|
|
63
68
|
type Info = typeof info;
|
|
64
69
|
|
|
@@ -300,8 +305,11 @@ export class VideoConsentPlugin implements JsPsychPlugin<Info> {
|
|
|
300
305
|
stop.addEventListener("click", async () => {
|
|
301
306
|
stop.disabled = true;
|
|
302
307
|
this.addMessage(display, this.uploadingMsg!);
|
|
303
|
-
|
|
304
|
-
this.recorder.
|
|
308
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
309
|
+
const { stopped, uploaded } = this.recorder.stop({
|
|
310
|
+
maintain_container_size: true,
|
|
311
|
+
});
|
|
312
|
+
await stopped;
|
|
305
313
|
this.recordFeed(display);
|
|
306
314
|
this.getImg(display, "record-icon").style.visibility = "hidden";
|
|
307
315
|
this.addMessage(display, this.notRecordingMsg!);
|
package/src/errors.ts
CHANGED
|
@@ -154,6 +154,21 @@ export class S3UndefinedError extends Error {
|
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
+
/**
|
|
158
|
+
* Error thrown when a filename does not exist but is needed for upload or local
|
|
159
|
+
* download.
|
|
160
|
+
*/
|
|
161
|
+
export class NoFileNameError extends Error {
|
|
162
|
+
/**
|
|
163
|
+
* Provide information when the recorder attempts to upload/download the
|
|
164
|
+
* recording but there is no file name.
|
|
165
|
+
*/
|
|
166
|
+
public constructor() {
|
|
167
|
+
super("No filename found for recording.");
|
|
168
|
+
this.name = "NoFileNameError";
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
157
172
|
/**
|
|
158
173
|
* Error thrown when attempting to reset recorder, but its stream is still
|
|
159
174
|
* active.
|
|
@@ -209,3 +224,16 @@ export class ElementNotFoundError extends Error {
|
|
|
209
224
|
this.name = "ElementNotFoundError";
|
|
210
225
|
}
|
|
211
226
|
}
|
|
227
|
+
|
|
228
|
+
/** Thrown when the timeout duration is reached. */
|
|
229
|
+
export class TimeoutError extends Error {
|
|
230
|
+
/**
|
|
231
|
+
* String passed in with more info about the event that timed out.
|
|
232
|
+
*
|
|
233
|
+
* @param msg - Timeout error message string.
|
|
234
|
+
*/
|
|
235
|
+
public constructor(msg: string) {
|
|
236
|
+
super(`${msg}`);
|
|
237
|
+
this.name = "TimeoutError";
|
|
238
|
+
}
|
|
239
|
+
}
|