aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSam Wilkins <samwilkins333@gmail.com>2020-03-18 17:35:21 -0700
committerSam Wilkins <samwilkins333@gmail.com>2020-03-18 17:35:21 -0700
commit556da19d82b651b7a3372c5937f03ad55803ce1b (patch)
tree6fc86187fc1c13430f3b7ba6e855b959064696fd /src
parent1693e9daf1657c1fc45afa3fa14f0a0df0e01e13 (diff)
clean up audio
Diffstat (limited to 'src')
-rw-r--r--src/client/views/nodes/AudioBox.tsx42
-rw-r--r--src/server/DashUploadUtils.ts5
2 files changed, 18 insertions, 29 deletions
diff --git a/src/client/views/nodes/AudioBox.tsx b/src/client/views/nodes/AudioBox.tsx
index 017dc6286..03b2a2297 100644
--- a/src/client/views/nodes/AudioBox.tsx
+++ b/src/client/views/nodes/AudioBox.tsx
@@ -19,6 +19,7 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { DocumentView } from "./DocumentView";
import { Docs } from "../../documents/Documents";
import { ComputedField } from "../../../new_fields/ScriptField";
+import { Networking } from "../../Network";
// testing testing
@@ -138,33 +139,20 @@ export class AudioBox extends DocExtendableComponent<FieldViewProps, AudioDocume
}
}
- recordAudioAnnotation = () => {
- const self = this;
- navigator.mediaDevices.getUserMedia({
- audio: true
- }).then(function (stream) {
- self._stream = stream;
- self._recorder = new MediaRecorder(stream);
- self.dataDoc[self.props.fieldKey + "-recordingStart"] = new DateField(new Date());
- AudioBox.ActiveRecordings.push(self.props.Document);
- self._recorder.ondataavailable = async function (e: any) {
- const formData = new FormData();
- formData.append("file", e.data);
- const res = await fetch(Utils.prepend("/uploadFormData"), {
- method: 'POST',
- body: formData
- });
- const files = await res.json();
- const url = Utils.prepend(files[0].result.accessPaths.agnostic.client);
- // upload to server with known URL
- self.props.Document[self.props.fieldKey] = new AudioField(url);
- };
- self._recordStart = new Date().getTime();
- runInAction(() => self.audioState = "recording");
- setTimeout(self.updateRecordTime, 0);
- self._recorder.start();
- setTimeout(() => self._recorder && self.stopRecording(), 60 * 1000); // stop after an hour
- });
+ recordAudioAnnotation = async () => {
+ this._stream = await navigator.mediaDevices.getUserMedia({ audio: true });
+ this._recorder = new MediaRecorder(this._stream);
+ this.dataDoc[this.props.fieldKey + "-recordingStart"] = new DateField(new Date());
+ AudioBox.ActiveRecordings.push(this.props.Document);
+ this._recorder.ondataavailable = async (e: any) => {
+ const [{ result }] = await Networking.UploadFilesToServer(e.data);
+ this.props.Document[this.props.fieldKey] = new AudioField(Utils.prepend(result.accessPaths.agnostic.client));
+ };
+ this._recordStart = new Date().getTime();
+ runInAction(() => this.audioState = "recording");
+ setTimeout(this.updateRecordTime, 0);
+ this._recorder.start();
+ setTimeout(() => this._recorder && this.stopRecording(), 60 * 1000); // stop after an hour
}
specificContextMenu = (e: React.MouseEvent): void => {
diff --git a/src/server/DashUploadUtils.ts b/src/server/DashUploadUtils.ts
index bc5d1d95b..dd99ff746 100644
--- a/src/server/DashUploadUtils.ts
+++ b/src/server/DashUploadUtils.ts
@@ -193,9 +193,10 @@ export namespace DashUploadUtils {
};
};
- export async function MoveParsedFile(file: File, destination: Directory): Promise<Upload.FileResponse> {
+ export async function MoveParsedFile(file: File, destination: Directory, suffix: string | undefined = undefined): Promise<Upload.FileResponse> {
const { path: sourcePath } = file;
- const name = path.basename(sourcePath);
+ let name = path.basename(sourcePath);
+ suffix && (name += suffix);
return new Promise(resolve => {
const destinationPath = serverPathToFile(destination, name);
rename(sourcePath, destinationPath, error => {