From d13532ab66335d7ebba9c687746fc466ae5ec622 Mon Sep 17 00:00:00 2001 From: bobzel Date: Sun, 21 Mar 2021 00:39:14 -0400 Subject: upload screengrab video to server in mkv format ... can't yet play them. --- src/client/views/nodes/AudioBox.tsx | 1 - src/client/views/nodes/ScreenshotBox.tsx | 46 +++++++++++++++++++++++++------- src/server/DashUploadUtils.ts | 2 +- src/server/SharedMediaTypes.ts | 2 +- 4 files changed, 39 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/client/views/nodes/AudioBox.tsx b/src/client/views/nodes/AudioBox.tsx index ecc93ce67..c0b5476fa 100644 --- a/src/client/views/nodes/AudioBox.tsx +++ b/src/client/views/nodes/AudioBox.tsx @@ -23,7 +23,6 @@ import { ContextMenuProps } from "../ContextMenuItem"; import { ViewBoxAnnotatableComponent } from "../DocComponent"; import "./AudioBox.scss"; import { FieldView, FieldViewProps } from './FieldView'; -import { FormattedTextBoxComment } from "./formattedText/FormattedTextBoxComment"; import { LinkDocPreview } from "./LinkDocPreview"; declare class MediaRecorder { constructor(e: any); // whatever MediaRecorder has diff --git a/src/client/views/nodes/ScreenshotBox.tsx b/src/client/views/nodes/ScreenshotBox.tsx index a14d8ccae..94d00f429 100644 --- a/src/client/views/nodes/ScreenshotBox.tsx +++ b/src/client/views/nodes/ScreenshotBox.tsx @@ -18,7 +18,15 @@ import { ViewBoxBaseComponent } from "../DocComponent"; import { FieldView, FieldViewProps } from './FieldView'; import "./ScreenshotBox.scss"; import { CurrentUserUtils } from "../../util/CurrentUserUtils"; +import { Networking } from "../../Network"; +import { DocumentType } from "../../documents/DocumentTypes"; +import { VideoBox } from "./VideoBox"; +import { Id } from "../../../fields/FieldSymbols"; const path = require('path'); +declare class MediaRecorder { + constructor(e: any, options?: any); // whatever MediaRecorder has +} + type ScreenshotDocument = makeInterface<[typeof documentSchema]>; const ScreenshotDocument = makeInterface(documentSchema); @@ -119,12 +127,7 @@ export class ScreenshotBox extends ViewBoxBaseComponent this.Snapshot(), icon: "expand-arrows-alt" }); - subitems.push({ - description: "Screen Capture", event: (async () => { - runInAction(() => this._screenCapture = !this._screenCapture); - this._videoRef!.srcObject = !this._screenCapture ? undefined : await (navigator.mediaDevices as any).getDisplayMedia({ video: true }); - }), icon: "expand-arrows-alt" - }); + subitems.push({ description: "Screen Capture", event: this.toggleRecording, icon: "expand-arrows-alt" }); ContextMenu.Instance.addItem({ description: "Options...", subitems: subitems, icon: "video" }); } } @@ -142,16 +145,42 @@ export class ScreenshotBox extends ViewBoxBaseComponent; } + _chunks: any; + _recorder: any; + toggleRecording = action(async () => { this._screenCapture = !this._screenCapture; - this._videoRef!.srcObject = !this._screenCapture ? undefined : await (navigator.mediaDevices as any).getDisplayMedia({ video: true }); + if (this._screenCapture) { + const stream = !this._screenCapture ? undefined : await (navigator.mediaDevices as any).getDisplayMedia({ video: true }); + this._videoRef!.srcObject = stream; + this._recorder = new MediaRecorder(stream, { + audioBitsPerSecond: 128000, + videoBitsPerSecond: 2500000, + mimeType: 'video/webm' + }); + this._chunks = []; + this._recorder.ondataavailable = (e: any) => this._chunks.push(e.data); + this._recorder.onstop = async (e: any) => { + const file = new File([this._chunks], `${this.rootDoc[Id]}.mkv`, { type: this._chunks[0].type, lastModified: Date.now() }); + const [{ result }] = await Networking.UploadFilesToServer(file); + if (!(result instanceof Error)) { + this.dataDoc.type = DocumentType.VID; + this.layoutDoc.layout = VideoBox.LayoutString(this.fieldKey); + this.props.Document[this.props.fieldKey] = new VideoField(Utils.prepend(result.accessPaths.agnostic.client)); + console.log(this.props.Document[this.props.fieldKey]); + } else alert("video conversion failed") + }; + this._recorder.start(); + } else { + this._recorder.stop(); + } }); private get uIButtons() { return (
-
, +
@@ -164,7 +193,6 @@ export class ScreenshotBox extends ViewBoxBaseComponent [this.content]; render() { return (