@lookit/record 4.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lookit/record",
3
- "version": "4.1.0",
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.2.0",
45
- "@lookit/templates": "^2.1.0",
44
+ "@lookit/data": "^0.3.0",
45
+ "@lookit/templates": "^3.0.0",
46
46
  "jspsych": "^8.0.3"
47
47
  }
48
48
  }
@@ -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");
@@ -305,7 +305,11 @@ export class VideoConsentPlugin implements JsPsychPlugin<Info> {
305
305
  stop.addEventListener("click", async () => {
306
306
  stop.disabled = true;
307
307
  this.addMessage(display, this.uploadingMsg!);
308
- await this.recorder.stop(true);
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;
309
313
  this.recordFeed(display);
310
314
  this.getImg(display, "record-icon").style.visibility = "hidden";
311
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
+ }