-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change type of sessionRecorder to "unknown"
To facilitate the typing for our window storage, I've added an interface that extends Window. Additionally, there's a new script in the root of this repo that will clean out "dist" directories.
- Loading branch information
Showing
13 changed files
with
1,311 additions
and
110 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ export default class Recorder { | |
private localDownload: boolean = false; | ||
private s3?: lookitS3; | ||
private fileNameStr: string; | ||
private stopPromise: Promise<void> | null = null; | ||
private stopPromise?: Promise<void>; | ||
|
||
/** | ||
* Recorder for online experiments. | ||
|
@@ -52,7 +52,7 @@ export default class Recorder { | |
*/ | ||
public get filename() { | ||
return this.fileNameStr; | ||
}; | ||
} | ||
|
||
/** | ||
* Get stream from either recorder. | ||
|
@@ -72,17 +72,17 @@ export default class Recorder { | |
this.recorder.addEventListener("dataavailable", this.handleDataAvailable); | ||
// create a stop promise and pass the resolve function as an argument to the stop event callback, | ||
// so that the stop event handler can resolve the stop promise | ||
this.stopPromise = new Promise((resolve, reject) => { | ||
this.stopPromise = new Promise((resolve) => { | ||
this.recorder.addEventListener("stop", this.handleStop(resolve)); | ||
}) | ||
}); | ||
if (!this.localDownload) { | ||
await this.s3?.createUpload(); | ||
} | ||
this.recorder.start(); | ||
} | ||
|
||
/** Stop recording and camera/microphone. */ | ||
Check failure on line 84 in packages/record/src/recorder.ts GitHub Actions / Build, lint, and test on Node.js 20
|
||
public async stop() { | ||
public stop() { | ||
this.recorder.stop(); | ||
this.stream.getTracks().map((t) => t.stop()); | ||
return this.stopPromise; | ||
|
@@ -96,15 +96,15 @@ export default class Recorder { | |
} | ||
|
||
/** Handle the recorder's stop event. */ | ||
Check failure on line 98 in packages/record/src/recorder.ts GitHub Actions / Build, lint, and test on Node.js 20
|
||
private handleStop(resolve: { (value: void | PromiseLike<void>): void; }) { | ||
private handleStop(resolve: { (value: void | PromiseLike<void>): void }) { | ||
return async () => { | ||
if (this.localDownload) { | ||
await this.download(); | ||
} else { | ||
await this.s3?.completeUpload(); | ||
} | ||
resolve(); | ||
} | ||
}; | ||
} | ||
|
||
/** | ||
|
@@ -164,7 +164,8 @@ export default class Recorder { | |
* Function to create a video recording filename. | ||
* | ||
* @param prefix - (string): Start of the file name for the video recording. | ||
* @returns Filename string, including the prefix, date/time and webm extension. | ||
* @returns Filename string, including the prefix, date/time and webm | ||
* extension. | ||
*/ | ||
private createFilename(prefix: string) { | ||
return `${prefix}_${new Date().getTime()}.webm`; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
import { JsPsych, JsPsychPlugin } from "jspsych"; | ||
import Recorder from "./recorder"; | ||
import RecorderType from "@lookit/record/dist/recorder"; | ||
import { NoSessionRecordingError } from "./error"; | ||
import Recorder from "./recorder"; | ||
|
||
import { LookitWindow } from "@lookit/data/dist/types"; | ||
|
||
declare let window: LookitWindow; | ||
|
||
const info = <const>{ name: "stop-record-plugin", parameters: {} }; | ||
type Info = typeof info; | ||
|
||
/** Stop recording. Used by researchers who want to record across trials. */ | ||
export default class StopRecordPlugin implements JsPsychPlugin<Info> { | ||
public static readonly info = info; | ||
private recorder: RecorderType; | ||
private recorder: Recorder; | ||
|
||
/** | ||
* Plugin used to stop recording. | ||
|
@@ -18,18 +21,21 @@ export default class StopRecordPlugin implements JsPsychPlugin<Info> { | |
*/ | ||
public constructor(private jsPsych: JsPsych) { | ||
if (window.chs.sessionRecorder) { | ||
this.recorder = window.chs.sessionRecorder; | ||
this.recorder = window.chs.sessionRecorder as Recorder; | ||
} else { | ||
throw new NoSessionRecordingError(); | ||
} | ||
} | ||
|
||
/** Trial function called by jsPsych. */ | ||
/** | ||
* Trial function called by jsPsych. | ||
* @param display_element | ||
Check failure on line 32 in packages/record/src/stop.ts GitHub Actions / Build, lint, and test on Node.js 20
|
||
*/ | ||
public trial(display_element: HTMLElement): void { | ||
display_element.innerHTML = '<div>Uploading video, please wait...</div>'; | ||
this.recorder.stop().then(() => { | ||
display_element.innerHTML = "<div>Uploading video, please wait...</div>"; | ||
this.recorder.stop()?.then(() => { | ||
window.chs.sessionRecorder = null; | ||
display_element.innerHTML = ''; | ||
display_element.innerHTML = ""; | ||
this.jsPsych.finishTrial(); | ||
}); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters