@lookit/record 3.0.1 → 4.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/index.browser.js +68 -31
- package/dist/index.browser.js.map +1 -1
- package/dist/index.browser.min.js +12 -12
- package/dist/index.browser.min.js.map +1 -1
- package/dist/index.cjs +67 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +25 -3
- package/dist/index.js +67 -30
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/consentVideo.spec.ts +38 -11
- package/src/consentVideo.ts +75 -18
- package/src/errors.ts +7 -27
- package/src/recorder.spec.ts +120 -0
- package/src/recorder.ts +28 -4
package/dist/index.cjs
CHANGED
|
@@ -8,7 +8,7 @@ var Handlebars = require('handlebars');
|
|
|
8
8
|
|
|
9
9
|
var _package = {
|
|
10
10
|
name: "@lookit/record",
|
|
11
|
-
version: "
|
|
11
|
+
version: "4.0.0",
|
|
12
12
|
description: "Recording extensions and plugins for CHS studies.",
|
|
13
13
|
homepage: "https://github.com/lookit/lookit-jspsych#readme",
|
|
14
14
|
bugs: {
|
|
@@ -50,7 +50,7 @@ var _package = {
|
|
|
50
50
|
},
|
|
51
51
|
peerDependencies: {
|
|
52
52
|
"@lookit/data": "^0.2.0",
|
|
53
|
-
"@lookit/templates": "^2.
|
|
53
|
+
"@lookit/templates": "^2.1.0",
|
|
54
54
|
jspsych: "^8.0.3"
|
|
55
55
|
}
|
|
56
56
|
};
|
|
@@ -143,21 +143,10 @@ class CreateURLError extends Error {
|
|
|
143
143
|
this.name = "CreateURLError";
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
|
-
class
|
|
147
|
-
constructor() {
|
|
148
|
-
super("
|
|
149
|
-
this.name = "
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
class ButtonNotFoundError extends Error {
|
|
153
|
-
constructor(id) {
|
|
154
|
-
super(`"${id}" button not found.`);
|
|
155
|
-
this.name = "ButtonNotFoundError";
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
class ImageNotFoundError extends Error {
|
|
159
|
-
constructor(id) {
|
|
160
|
-
super(`"${id}" image not found.`);
|
|
146
|
+
class ElementNotFoundError extends Error {
|
|
147
|
+
constructor(id, tag) {
|
|
148
|
+
super(`"${id}" ${tag} not found.`);
|
|
149
|
+
this.name = "ElementNotFoundError";
|
|
161
150
|
}
|
|
162
151
|
}
|
|
163
152
|
|
|
@@ -270,9 +259,9 @@ class Recorder {
|
|
|
270
259
|
this.recorder.stop();
|
|
271
260
|
this.stream.getTracks().map((t) => t.stop());
|
|
272
261
|
}
|
|
273
|
-
stop() {
|
|
262
|
+
stop(maintain_container_size = false) {
|
|
263
|
+
this.clearWebcamFeed(maintain_container_size);
|
|
274
264
|
this.stopTracks();
|
|
275
|
-
this.clearWebcamFeed();
|
|
276
265
|
if (!this.stopPromise) {
|
|
277
266
|
throw new NoStopPromiseError();
|
|
278
267
|
}
|
|
@@ -317,11 +306,20 @@ class Recorder {
|
|
|
317
306
|
link.click();
|
|
318
307
|
}
|
|
319
308
|
}
|
|
320
|
-
clearWebcamFeed() {
|
|
309
|
+
clearWebcamFeed(maintain_container_size) {
|
|
321
310
|
const webcam_feed_element = document.querySelector(
|
|
322
311
|
`#${this.webcam_element_id}`
|
|
323
312
|
);
|
|
324
313
|
if (webcam_feed_element) {
|
|
314
|
+
if (maintain_container_size) {
|
|
315
|
+
const parent_div = webcam_feed_element.parentElement;
|
|
316
|
+
if (parent_div) {
|
|
317
|
+
const width = webcam_feed_element.offsetWidth;
|
|
318
|
+
const height = webcam_feed_element.offsetHeight;
|
|
319
|
+
parent_div.style.height = `${height}px`;
|
|
320
|
+
parent_div.style.width = `${width}px`;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
325
323
|
webcam_feed_element.remove();
|
|
326
324
|
}
|
|
327
325
|
}
|
|
@@ -391,6 +389,11 @@ const _VideoConsentPlugin = class {
|
|
|
391
389
|
constructor(jsPsych) {
|
|
392
390
|
this.jsPsych = jsPsych;
|
|
393
391
|
this.video_container_id = "lookit-jspsych-video-container";
|
|
392
|
+
this.msg_container_id = "lookit-jspsych-video-msg-container";
|
|
393
|
+
this.uploadingMsg = null;
|
|
394
|
+
this.startingMsg = null;
|
|
395
|
+
this.recordingMsg = null;
|
|
396
|
+
this.notRecordingMsg = null;
|
|
394
397
|
this.jsPsych = jsPsych;
|
|
395
398
|
this.recorder = new Recorder(this.jsPsych);
|
|
396
399
|
}
|
|
@@ -402,13 +405,25 @@ const _VideoConsentPlugin = class {
|
|
|
402
405
|
this.stopButton(display);
|
|
403
406
|
this.playButton(display);
|
|
404
407
|
this.nextButton(display);
|
|
408
|
+
this.uploadingMsg = chsTemplates.translateString(
|
|
409
|
+
"exp-lookit-video-consent.Stopping-and-uploading"
|
|
410
|
+
);
|
|
411
|
+
this.startingMsg = chsTemplates.translateString(
|
|
412
|
+
"exp-lookit-video-consent.Starting-recorder"
|
|
413
|
+
);
|
|
414
|
+
this.recordingMsg = chsTemplates.translateString(
|
|
415
|
+
"exp-lookit-video-consent.Recording"
|
|
416
|
+
);
|
|
417
|
+
this.notRecordingMsg = chsTemplates.translateString(
|
|
418
|
+
"exp-lookit-video-consent.Not-recording"
|
|
419
|
+
);
|
|
405
420
|
}
|
|
406
421
|
getVideoContainer(display) {
|
|
407
422
|
const videoContainer = display.querySelector(
|
|
408
423
|
`div#${this.video_container_id}`
|
|
409
424
|
);
|
|
410
425
|
if (!videoContainer) {
|
|
411
|
-
throw new
|
|
426
|
+
throw new ElementNotFoundError(this.video_container_id, "div");
|
|
412
427
|
}
|
|
413
428
|
return videoContainer;
|
|
414
429
|
}
|
|
@@ -419,14 +434,31 @@ const _VideoConsentPlugin = class {
|
|
|
419
434
|
}
|
|
420
435
|
playbackFeed(display) {
|
|
421
436
|
const videoContainer = this.getVideoContainer(display);
|
|
422
|
-
this.recorder.insertPlaybackFeed(
|
|
437
|
+
this.recorder.insertPlaybackFeed(
|
|
438
|
+
videoContainer,
|
|
439
|
+
this.onPlaybackEnded(display)
|
|
440
|
+
);
|
|
423
441
|
}
|
|
424
|
-
|
|
442
|
+
getMessageContainer(display) {
|
|
443
|
+
const msgContainer = display.querySelector(
|
|
444
|
+
`div#${this.msg_container_id}`
|
|
445
|
+
);
|
|
446
|
+
if (!msgContainer) {
|
|
447
|
+
throw new ElementNotFoundError(this.msg_container_id, "div");
|
|
448
|
+
}
|
|
449
|
+
return msgContainer;
|
|
450
|
+
}
|
|
451
|
+
addMessage(display, message) {
|
|
452
|
+
const msgContainer = this.getMessageContainer(display);
|
|
453
|
+
msgContainer.innerHTML = message;
|
|
454
|
+
}
|
|
455
|
+
onPlaybackEnded(display) {
|
|
425
456
|
return () => {
|
|
426
457
|
const next = this.getButton(display, "next");
|
|
427
458
|
const play = this.getButton(display, "play");
|
|
428
459
|
const record = this.getButton(display, "record");
|
|
429
460
|
this.recordFeed(display);
|
|
461
|
+
this.addMessage(display, this.notRecordingMsg);
|
|
430
462
|
next.disabled = false;
|
|
431
463
|
play.disabled = false;
|
|
432
464
|
record.disabled = false;
|
|
@@ -435,14 +467,14 @@ const _VideoConsentPlugin = class {
|
|
|
435
467
|
getButton(display, id) {
|
|
436
468
|
const btn = display.querySelector(`button#${id}`);
|
|
437
469
|
if (!btn) {
|
|
438
|
-
throw new
|
|
470
|
+
throw new ElementNotFoundError(id, "button");
|
|
439
471
|
}
|
|
440
472
|
return btn;
|
|
441
473
|
}
|
|
442
474
|
getImg(display, id) {
|
|
443
475
|
const img = display.querySelector(`img#${id}`);
|
|
444
476
|
if (!img) {
|
|
445
|
-
throw new
|
|
477
|
+
throw new ElementNotFoundError(id, "img");
|
|
446
478
|
}
|
|
447
479
|
return img;
|
|
448
480
|
}
|
|
@@ -452,12 +484,14 @@ const _VideoConsentPlugin = class {
|
|
|
452
484
|
const play = this.getButton(display, "play");
|
|
453
485
|
const next = this.getButton(display, "next");
|
|
454
486
|
record.addEventListener("click", async () => {
|
|
487
|
+
this.addMessage(display, this.startingMsg);
|
|
455
488
|
record.disabled = true;
|
|
456
|
-
stop.disabled = false;
|
|
457
489
|
play.disabled = true;
|
|
458
490
|
next.disabled = true;
|
|
459
|
-
this.getImg(display, "record-icon").style.visibility = "visible";
|
|
460
491
|
await this.recorder.start(true, _VideoConsentPlugin.info.name);
|
|
492
|
+
this.getImg(display, "record-icon").style.visibility = "visible";
|
|
493
|
+
this.addMessage(display, this.recordingMsg);
|
|
494
|
+
stop.disabled = false;
|
|
461
495
|
});
|
|
462
496
|
}
|
|
463
497
|
playButton(display) {
|
|
@@ -475,11 +509,14 @@ const _VideoConsentPlugin = class {
|
|
|
475
509
|
const play = this.getButton(display, "play");
|
|
476
510
|
stop.addEventListener("click", async () => {
|
|
477
511
|
stop.disabled = true;
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
await this.recorder.stop();
|
|
512
|
+
this.addMessage(display, this.uploadingMsg);
|
|
513
|
+
await this.recorder.stop(true);
|
|
481
514
|
this.recorder.reset();
|
|
482
515
|
this.recordFeed(display);
|
|
516
|
+
this.getImg(display, "record-icon").style.visibility = "hidden";
|
|
517
|
+
this.addMessage(display, this.notRecordingMsg);
|
|
518
|
+
play.disabled = false;
|
|
519
|
+
record.disabled = false;
|
|
483
520
|
});
|
|
484
521
|
}
|
|
485
522
|
nextButton(display) {
|