aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/AudioBox.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/nodes/AudioBox.tsx')
-rw-r--r--src/client/views/nodes/AudioBox.tsx26
1 files changed, 12 insertions, 14 deletions
diff --git a/src/client/views/nodes/AudioBox.tsx b/src/client/views/nodes/AudioBox.tsx
index ea26cc43d..05b9fd14a 100644
--- a/src/client/views/nodes/AudioBox.tsx
+++ b/src/client/views/nodes/AudioBox.tsx
@@ -20,6 +20,8 @@ import { DocumentView } from "./DocumentView";
import { Docs } from "../../documents/Documents";
import { ComputedField } from "../../../new_fields/ScriptField";
+// testing testing
+
interface Window {
MediaRecorder: MediaRecorder;
}
@@ -46,6 +48,7 @@ export class AudioBox extends DocExtendableComponent<FieldViewProps, AudioDocume
_ele: HTMLAudioElement | null = null;
_recorder: any;
_recordStart = 0;
+ _stream: MediaStream | undefined;
public static START = 0;
@observable private static _scrubTime = 0;
@@ -137,12 +140,11 @@ export class AudioBox extends DocExtendableComponent<FieldViewProps, AudioDocume
}
recordAudioAnnotation = () => {
- let gumStream: any;
const self = this;
navigator.mediaDevices.getUserMedia({
audio: true
}).then(function (stream) {
- gumStream = stream;
+ self._stream = stream;
self._recorder = new MediaRecorder(stream);
self.dataDoc[self.props.fieldKey + "-recordingStart"] = new DateField(new Date());
AudioBox.START = new DateField(new Date()).date.getTime();
@@ -154,23 +156,16 @@ export class AudioBox extends DocExtendableComponent<FieldViewProps, AudioDocume
method: 'POST',
body: formData
});
- const json = await res.json();
- json.map(async (file: any) => {
- const path = file.result.accessPaths.agnostic.client;
- const url = Utils.prepend(path);
- // upload to server with known URL
- self.props.Document[self.props.fieldKey] = new AudioField(url);
- });
+ 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();
- console.log("RECORD START = " + self._recordStart);
runInAction(() => self.audioState = "recording");
setTimeout(self.updateRecordTime, 0);
self._recorder.start();
- setTimeout(() => {
- self.stopRecording();
- gumStream.getAudioTracks()[0].stop();
- }, 60 * 60 * 1000); // stop after an hour?
+ setTimeout(() => self._recorder && self.stopRecording(), 60 * 1000); // stop after an hour
});
}
@@ -183,8 +178,10 @@ export class AudioBox extends DocExtendableComponent<FieldViewProps, AudioDocume
stopRecording = action(() => {
this._recorder.stop();
+ this._recorder = undefined;
this.dataDoc.duration = (new Date().getTime() - this._recordStart) / 1000;
this.audioState = "paused";
+ this._stream?.getAudioTracks()[0].stop();
const ind = AudioBox.ActiveRecordings.indexOf(this.props.Document);
ind !== -1 && (AudioBox.ActiveRecordings.splice(ind, 1));
});
@@ -237,6 +234,7 @@ export class AudioBox extends DocExtendableComponent<FieldViewProps, AudioDocume
</audio>;
}
+ // line 226 is stop button but it doesn't do anything
render() {
const interactive = this.active() ? "-interactive" : "";
return <div className={`audiobox-container`} onContextMenu={this.specificContextMenu}