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.tsx79
1 files changed, 37 insertions, 42 deletions
diff --git a/src/client/views/nodes/AudioBox.tsx b/src/client/views/nodes/AudioBox.tsx
index 4b1ab9d30..05dd64b68 100644
--- a/src/client/views/nodes/AudioBox.tsx
+++ b/src/client/views/nodes/AudioBox.tsx
@@ -16,7 +16,7 @@ import { makeInterface } from "../../../fields/Schema";
import { ComputedField } from "../../../fields/ScriptField";
import { Cast, NumCast } from "../../../fields/Types";
import { AudioField, nullAudio } from "../../../fields/URLField";
-import { emptyFunction, formatTime, Utils } from "../../../Utils";
+import { emptyFunction, formatTime } from "../../../Utils";
import { DocUtils } from "../../documents/Documents";
import { Networking } from "../../Network";
import { CurrentUserUtils } from "../../util/CurrentUserUtils";
@@ -163,7 +163,7 @@ export class AudioBox extends ViewBoxAnnotatableComponent<
: undefined)
) || this.rootDoc
);
- };
+ }
componentWillUnmount() {
Object.values(this._disposers).forEach((disposer) => disposer?.());
@@ -240,7 +240,7 @@ export class AudioBox extends ViewBoxAnnotatableComponent<
this.layoutDoc._currentTimecode = htmlEle.currentTime;
}
- };
+ }
// pause play back
Pause = action(() => {
@@ -252,7 +252,7 @@ export class AudioBox extends ViewBoxAnnotatableComponent<
playFromTime = (absoluteTime: number) => {
this.recordingStart &&
this.playFrom((absoluteTime - this.recordingStart) / 1000);
- };
+ }
// play back the audio from time
@action
@@ -277,7 +277,7 @@ export class AudioBox extends ViewBoxAnnotatableComponent<
this._play = setTimeout(
() => {
this._ended = fullPlay ? true : this._ended;
- this.Pause()
+ this.Pause();
},
(end - start) * 1000
); // use setTimeout to play a specific duration
@@ -286,7 +286,7 @@ export class AudioBox extends ViewBoxAnnotatableComponent<
this.Pause();
}
}
- };
+ }
// update the recording time
updateRecordTime = () => {
@@ -299,7 +299,7 @@ export class AudioBox extends ViewBoxAnnotatableComponent<
(new Date().getTime() - this._recordStart - this.pauseTime) / 1000;
}
}
- };
+ }
// starts recording
recordAudioAnnotation = async () => {
@@ -312,9 +312,7 @@ export class AudioBox extends ViewBoxAnnotatableComponent<
this._recorder.ondataavailable = async (e: any) => {
const [{ result }] = await Networking.UploadFilesToServer(e.data);
if (!(result instanceof Error)) {
- this.props.Document[this.props.fieldKey] = new AudioField(
- Utils.prepend(result.accessPaths.agnostic.client)
- );
+ this.props.Document[this.props.fieldKey] = new AudioField(result.accessPaths.agnostic.client);
}
};
this._recordStart = new Date().getTime();
@@ -322,7 +320,7 @@ export class AudioBox extends ViewBoxAnnotatableComponent<
setTimeout(this.updateRecordTime, 0);
this._recorder.start();
setTimeout(() => this._recorder && this.stopRecording(), 60 * 60 * 1000); // stop after an hour
- };
+ }
// context menu
specificContextMenu = (e: React.MouseEvent): void => {
@@ -355,7 +353,7 @@ export class AudioBox extends ViewBoxAnnotatableComponent<
subitems: funcs,
icon: "asterisk",
});
- };
+ }
// stops the recording
stopRecording = action(() => {
@@ -378,12 +376,12 @@ export class AudioBox extends ViewBoxAnnotatableComponent<
this._recorder ? this.stopRecording() : this.recordAudioAnnotation();
e.stopPropagation();
}
- };
+ }
// for play button
Play = (e?: any) => {
let start;
- if (this._ended || this._ele!.currentTime == this.duration) {
+ if (this._ended || this._ele!.currentTime === this.duration) {
start = this._trimStart;
this._ended = false;
}
@@ -393,7 +391,7 @@ export class AudioBox extends ViewBoxAnnotatableComponent<
this.playFrom(start, this._trimEnd, true);
e?.stopPropagation?.();
- };
+ }
// creates a text document for dictation
onFile = (e: any) => {
@@ -415,14 +413,14 @@ export class AudioBox extends ViewBoxAnnotatableComponent<
);
this.props.addDocument?.(newDoc);
e.stopPropagation();
- };
+ }
// ref for updating time
setRef = (e: HTMLAudioElement | null) => {
e?.addEventListener("timeupdate", this.timecodeChanged);
e?.addEventListener("ended", this.Pause);
this._ele = e;
- };
+ }
// returns the path of the audio file
@computed get path() {
@@ -433,16 +431,10 @@ export class AudioBox extends ViewBoxAnnotatableComponent<
// returns the html audio element
@computed get audio() {
- return (
- <audio
- ref={this.setRef}
- className={`audiobox-control${this.isContentActive() ? "-interactive" : ""
- }`}
- >
- <source src={this.path} type="audio/mpeg" />
- Not supported.
- </audio>
- );
+ return <audio ref={this.setRef} className={`audiobox-control${this.props.isContentActive() ? "-interactive" : ""}`}>
+ <source src={this.path} type="audio/mpeg" />
+ Not supported.
+ </audio>;
}
// pause the time during recording phase
@@ -452,7 +444,7 @@ export class AudioBox extends ViewBoxAnnotatableComponent<
this._paused = true;
this._recorder.pause();
e.stopPropagation();
- };
+ }
// continue the recording
@action
@@ -461,17 +453,18 @@ export class AudioBox extends ViewBoxAnnotatableComponent<
this._paused = false;
this._recorder.resume();
e.stopPropagation();
- };
+ }
playing = () => this.mediaState === "playing";
playLink = (link: Doc) => {
const stack = this._stackedTimeline.current;
if (link.annotationOn === this.rootDoc) {
- if (!this.layoutDoc.dontAutoPlayFollowedLinks)
+ if (!this.layoutDoc.dontAutoPlayFollowedLinks) {
this.playFrom(stack?.anchorStart(link) || 0, stack?.anchorEnd(link));
- else
+ } else {
this._ele!.currentTime = this.layoutDoc._currentTimecode =
stack?.anchorStart(link) || 0;
+ }
} else {
this.links
.filter((l) => l.anchor1 === link || l.anchor2 === link)
@@ -480,17 +473,18 @@ export class AudioBox extends ViewBoxAnnotatableComponent<
const startTime = stack?.anchorStart(la1) || stack?.anchorStart(la2);
const endTime = stack?.anchorEnd(la1) || stack?.anchorEnd(la2);
if (startTime !== undefined) {
- if (!this.layoutDoc.dontAutoPlayFollowedLinks)
+ if (!this.layoutDoc.dontAutoPlayFollowedLinks) {
endTime
? this.playFrom(startTime, endTime)
: this.playFrom(startTime);
- else
+ } else {
this._ele!.currentTime = this.layoutDoc._currentTimecode =
startTime;
+ }
}
});
}
- };
+ }
// shows trim controls
@action
@@ -502,7 +496,7 @@ export class AudioBox extends ViewBoxAnnotatableComponent<
this.Pause();
}
this._trimming = true;
- };
+ }
// hides trim controls and displays new clip
@action
@@ -514,7 +508,7 @@ export class AudioBox extends ViewBoxAnnotatableComponent<
this.layoutDoc.clipEnd = this._trimEnd;
this._trimming = false;
this.setAnchorTime(Math.max(Math.min(this._trimEnd, this._ele!.currentTime), this._trimStart));
- };
+ }
@action
setStartTrim = (newStart: number) => {
@@ -530,14 +524,14 @@ export class AudioBox extends ViewBoxAnnotatableComponent<
timelineWhenChildContentsActiveChanged = (isActive: boolean) =>
this.props.whenChildContentsActiveChanged(
runInAction(() => (this._isAnyChildContentActive = isActive))
- );
+ )
timelineScreenToLocal = () =>
this.props
.ScreenToLocalTransform()
.translate(
-AudioBox.playheadWidth,
(-(100 - this.heightPercent) / 200) * this.props.PanelHeight()
- );
+ )
setAnchorTime = (time: number) => {
(this._ele!.currentTime = this.layoutDoc._currentTimecode = time);
}
@@ -545,7 +539,7 @@ export class AudioBox extends ViewBoxAnnotatableComponent<
timelineHeight = () =>
(((this.props.PanelHeight() * this.heightPercent) / 100) *
this.heightPercent) /
- 100; // panelHeight * heightPercent is player height. * heightPercent is timeline height (as per css inline)
+ 100 // panelHeight * heightPercent is player height. * heightPercent is timeline height (as per css inline)
timelineWidth = () => this.props.PanelWidth() - AudioBox.playheadWidth;
@computed get renderTimeline() {
return (
@@ -572,7 +566,8 @@ export class AudioBox extends ViewBoxAnnotatableComponent<
ScreenToLocalTransform={this.timelineScreenToLocal}
Play={this.Play}
Pause={this.Pause}
- isContentActive={this.isContentActive}
+ isContentActive={this.props.isContentActive}
+ isAnyChildContentActive={this.isAnyChildContentActive}
playLink={this.playLink}
PanelWidth={this.timelineWidth}
PanelHeight={this.timelineHeight}
@@ -588,7 +583,7 @@ export class AudioBox extends ViewBoxAnnotatableComponent<
render() {
const interactive =
- SnappingManager.GetIsDragging() || this.isContentActive()
+ SnappingManager.GetIsDragging() || this.props.isContentActive()
? "-interactive"
: "";
return (
@@ -656,7 +651,7 @@ export class AudioBox extends ViewBoxAnnotatableComponent<
className="audiobox-controls"
style={{
pointerEvents:
- this._isAnyChildContentActive || this.isContentActive()
+ this._isAnyChildContentActive || this.props.isContentActive()
? "all"
: "none",
}}