Skip to content

Commit

Permalink
Change package name to record
Browse files Browse the repository at this point in the history
  • Loading branch information
okaycj committed May 8, 2024
1 parent bf94fd0 commit 8e368b5
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 28 deletions.
45 changes: 30 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
4 changes: 2 additions & 2 deletions packages/video/package.json → packages/record/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@lookit/video",
"name": "@lookit/record",
"version": "0.0.1",
"description": "Video extensions for lookit studies.",
"description": "Recording extensions and plugins for CHS studies.",
"homepage": "https://github.com/lookit/lookit-jspsych#readme",
"bugs": {
"url": "https://github.com/lookit/lookit-jspsych/issues"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { makeRollupConfig } from "@jspsych/config/rollup";
// This package name needs to be unique
export default makeRollupConfig("chsVideo");
export default makeRollupConfig("chsRecord");
12 changes: 12 additions & 0 deletions packages/record/src/error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/** Error thrown when recorder is null. */
export class RecorderInitializeError extends Error {
/**
* When there isn't a recorder, provide the user with an explanation of what
* they could do to resolve the issue.
*/
public constructor() {
const message = "Neither camera nor microphone has been initialized.";
super(message);
this.name = "RecorderInitializeError";
}
}
File renamed without changes.
File renamed without changes.
36 changes: 27 additions & 9 deletions packages/video/src/recorder.ts → packages/record/src/recorder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import autoBind from "auto-bind";
import { JsPsych } from "jspsych";
import { RecorderInitializeError } from "./error";

/** Recorder handles state of recording and data storage. */
/** Recorder handles the state of recording and data storage. */
export default class Recorder {
private blobs: Blob[] = [];

Expand All @@ -17,41 +18,58 @@ export default class Recorder {
/**
* Get recorder from jsPsydh plugin API.
*
* If camera recorder hasn't been initialized, then return the microphone
* recorder.
*
* @returns MediaRecorder from the plugin API.
*/
private get recorder() {
return this.jsPsych.pluginAPI.getCameraRecorder();
return (
this.jsPsych.pluginAPI.getCameraRecorder() ||
this.jsPsych.pluginAPI.getMicrophoneRecorder()
);
}

/**
* Get stream from jsPsydh plugin API.
* Get stream from either recorder.
*
* @returns MediaStream from the plugin API.
*/
private get stream() {
return this.jsPsych.pluginAPI.getCameraStream();
return this.recorder.stream;
}

/** Start recording. Also, adds event listeners for handling data. */
/**
* Start recording. Also, adds event listeners for handling data and checks
* for recorder initialization.
*/
public start() {
this.initializeCheck();
this.recorder.addEventListener("dataavailable", this.handleDataAvailable);
this.recorder.addEventListener("stop", this.handleStop);
this.recorder.start();
}

/** Stop recording and camera. */
/** Stop recording and camera/microphone. */
public stop() {
this.recorder.stop();
this.stream.getTracks().map((t: MediaStreamTrack) => t.stop());
this.stream.getTracks().map((t) => t.stop());
}

/** Throw Error if there isn't a recorder provided by jsPsych. */
private initializeCheck() {
if (!this.recorder) {
throw new RecorderInitializeError();
}
}

/** Handle recorder's stop event. */
/** Handle the recorder's stop event. */
private async handleStop() {
await this.download();
}

/**
* Function ran at each time slice and when recorder has stopped.
* Function ran at each time slice and when the recorder stopped.
*
* @param event - Event containing blob data.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class StartRecordPlugin implements JsPsychPlugin<Info> {
}

/** Trial function called by jsPsych. */
public trial(): void {
public trial() {
this.recorder.start();
setTimeout(() => this.jsPsych.finishTrial(), 1000);
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 8e368b5

Please sign in to comment.