Skip to content

Commit

Permalink
Merge pull request #394 from lookit/develop
Browse files Browse the repository at this point in the history
await recorder stop promise (#393)
  • Loading branch information
becky-gilbert authored Jun 20, 2024
2 parents a5adee4 + 52949c5 commit c122892
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
4 changes: 3 additions & 1 deletion app/components/exp-lookit-video-assent/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
<div id="recorder" class="col-xs-12"></div>
</div>

{{#if recorderInitializing}} ({{t "please wait, setting up" }}...)
{{#if recorderInitializing}}

({{t "please wait, setting up" }}...)

{{else}}

Expand Down
6 changes: 5 additions & 1 deletion app/mixins/video-record.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,10 @@ export default Ember.Mixin.create({
$('.video-record-mixin-wait-for-video-text').html(`${expFormat(this.get('waitForUploadMessage'))}`);
this.showWaitForVideoCover();
}
return recorder.stop(this.get('maxUploadSeconds') * 1000);
return recorder.stop(this.get('maxUploadSeconds') * 1000)
.catch((e) => {
throw new Error(`Error stopping recorder and uploading: ${e}`);
});
} else {
// reject the promise because the recorder is in one of the following states:
// - doesn't exist, or is not recording, or has been destroyed
Expand Down Expand Up @@ -444,6 +447,7 @@ export default Ember.Mixin.create({
.catch((err) => {
console.error(`Error playing video: ${err.name}: ${err.message}`);
console.trace();
throw new Error('Error playing video');
});
},

Expand Down
10 changes: 9 additions & 1 deletion app/services/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ class S3 {
Bucket: this.env.bucket,
Key: this.key,
ContentType: "video/webm",
}).promise();
}).promise()
.catch((e) => {
this.logRecordingEvent(`Error creating upload: ${e}`);
throw new Error(`Error creating upload: ${e}`);
});
this.uploadId = createResponse.UploadId;
this.logRecordingEvent(`Connection established.`);
}
Expand Down Expand Up @@ -81,6 +85,10 @@ class S3 {
}).promise()
.then((resp) => {
this.logRecordingEvent(`Upload complete: ${resp.Location}`);
})
.catch((e) => {
this.logRecordingEvent(`Error completing upload: ${e}`);
throw new Error(`Error completing upload: ${e}`);
});
}

Expand Down
15 changes: 8 additions & 7 deletions app/services/video-recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,14 +347,14 @@ const VideoRecorder = Ember.Object.extend({
resolve(); // skip mic check and resolve the install promise
}
} else {
reject();
reject(new Error(`Mic check error: no input stream.`));
}
};

const catch_install_error = (err) => {
console.error(`Recorder installation error:\n${err.name}: ${err.message}`);
console.trace();
return reject();
throw new Error(`Recorder installation error: ${err}`);
}

navigator.mediaDevices.getUserMedia({audio: {noiseSuppression: true}, video: {width: 1280, height: 720, frameRate: 30}})
Expand Down Expand Up @@ -458,12 +458,13 @@ const VideoRecorder = Ember.Object.extend({
var recorder = this.get('recorder');
if (recorder) {
try {
recorder.stopRecording();
await recorder.stopRecording();
_this.get('recorder').onRecordingStopped.call(_this);
await this.get('s3').completeUpload();
_this._onUploadDone(this.get('recorderId'), this.get('s3').key); // clears the upload timeout, sets isUploaded to true, resolves stop promise
} catch (e) {
console.warn(`Error stopping video ${_this.get('videoName')}: ${e}`);
throw new Error('Error stopping video.');
}
}
return _stopPromise;
Expand All @@ -477,7 +478,7 @@ const VideoRecorder = Ember.Object.extend({
*/
pause() {
this.get('recorder').getState().then((curr_state) => {
return new RSVP.Promise((resolve, reject) => {
return new RSVP.Promise((resolve) => {
if (curr_state == "recording") {
this.get('recorder').pauseRecording()
.then(() => {
Expand All @@ -486,7 +487,7 @@ const VideoRecorder = Ember.Object.extend({
.catch((err) => {
console.error(`Error pausing recorder:\n${err.name}: ${err.message}`);
console.trace();
reject();
throw new Error('Error pausing recorder');
});
} else {
resolve();
Expand All @@ -503,7 +504,7 @@ const VideoRecorder = Ember.Object.extend({
*/
resume() {
this.get('recorder').getState().then((curr_state) => {
return new RSVP.Promise((resolve, reject) => {
return new RSVP.Promise((resolve) => {
if (curr_state == "paused") {
this.get('recorder').resumeRecording()
.then(() => {
Expand All @@ -512,7 +513,7 @@ const VideoRecorder = Ember.Object.extend({
.catch((err) => {
console.error(`Error resuming recording:\n${err.name}: ${err.message}`);
console.trace();
reject();
throw new Error('Error resuming recorder');
});
} else {
resolve();
Expand Down

0 comments on commit c122892

Please sign in to comment.