From 4574b7f03ccc85c4bebdbfd9475788456086704f Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Thu, 8 Aug 2024 12:27:40 -0400
Subject: many changes to add typing in place of 'any's etc

---
 src/client/views/nodes/ScreenshotBox.tsx | 35 ++++++++++++++++----------------
 1 file changed, 18 insertions(+), 17 deletions(-)

(limited to 'src/client/views/nodes/ScreenshotBox.tsx')

diff --git a/src/client/views/nodes/ScreenshotBox.tsx b/src/client/views/nodes/ScreenshotBox.tsx
index 9ef1071f7..6289470b6 100644
--- a/src/client/views/nodes/ScreenshotBox.tsx
+++ b/src/client/views/nodes/ScreenshotBox.tsx
@@ -20,7 +20,7 @@ import { DocumentType } from '../../documents/DocumentTypes';
 import { Docs } from '../../documents/Documents';
 import { CaptureManager } from '../../util/CaptureManager';
 import { SettingsManager } from '../../util/SettingsManager';
-import { TrackMovements } from '../../util/TrackMovements';
+import { Movement, TrackMovements } from '../../util/TrackMovements';
 import { ContextMenu } from '../ContextMenu';
 import { ViewBoxAnnotatableComponent } from '../DocComponent';
 import { DocViewUtils } from '../DocViewUtils';
@@ -31,10 +31,11 @@ import { FieldView, FieldViewProps } from './FieldView';
 import './ScreenshotBox.scss';
 import { VideoBox } from './VideoBox';
 import { FormattedTextBox } from './formattedText/FormattedTextBox';
+import { IconProp } from '@fortawesome/fontawesome-svg-core';
 
-declare class MediaRecorder {
-    constructor(e: any, options?: any); // whatever MediaRecorder has
-}
+// declare class MediaRecorder {
+//     constructor(e: any, options?: any); // whatever MediaRecorder has
+// }
 
 // interface VideoTileProps {
 //     raised: { coord: Vector2, off: Vector3 }[];
@@ -117,8 +118,8 @@ export class ScreenshotBox extends ViewBoxAnnotatableComponent<FieldViewProps>()
     public static LayoutString(fieldKey: string) {
         return FieldView.LayoutString(ScreenshotBox, fieldKey);
     }
-    private _audioRec: any;
-    private _videoRec: any;
+    private _audioRec: MediaRecorder | undefined;
+    private _videoRec: MediaRecorder | undefined;
     @observable private _videoRef: HTMLVideoElement | null = null;
     @observable _screenCapture = false;
     @computed get recordingStart() {
@@ -136,7 +137,7 @@ export class ScreenshotBox extends ViewBoxAnnotatableComponent<FieldViewProps>()
     };
 
     videoLoad = () => {
-        const aspect = this._videoRef!.videoWidth / this._videoRef!.videoHeight;
+        const aspect = (this._videoRef?.videoWidth || 0) / (this._videoRef?.videoHeight || 1);
         const nativeWidth = Doc.NativeWidth(this.layoutDoc);
         const nativeHeight = Doc.NativeHeight(this.layoutDoc);
         if (!nativeWidth || !nativeHeight) {
@@ -166,7 +167,7 @@ export class ScreenshotBox extends ViewBoxAnnotatableComponent<FieldViewProps>()
     }
 
     specificContextMenu = (): void => {
-        const subitems = [{ description: 'Screen Capture', event: this.toggleRecording, icon: 'expand-arrows-alt' as any }];
+        const subitems = [{ description: 'Screen Capture', event: this.toggleRecording, icon: 'expand-arrows-alt' as IconProp }];
         ContextMenu.Instance.addItem({ description: 'Options...', subitems, icon: 'video' });
     };
 
@@ -221,29 +222,29 @@ export class ScreenshotBox extends ViewBoxAnnotatableComponent<FieldViewProps>()
     Pause = () => this._screenCapture && this.toggleRecording();
 
     toggleRecording = async () => {
-        if (!this._screenCapture) {
+        if (!this._screenCapture && this._videoRef) {
             this._audioRec = new MediaRecorder(await navigator.mediaDevices.getUserMedia({ audio: true }));
-            const audChunks: any = [];
-            this._audioRec.ondataavailable = (e: any) => audChunks.push(e.data);
+            const audChunks: Blob[] = [];
+            this._audioRec.ondataavailable = e => audChunks.push(e.data);
             this._audioRec.onstop = async () => {
-                const [{ result }] = await Networking.UploadFilesToServer(audChunks.map((file: any) => ({ file })));
+                const [{ result }] = await Networking.UploadFilesToServer(audChunks.map(file => ({ file })));
                 if (!(result instanceof Error)) {
                     this.dataDoc[this._props.fieldKey + '_audio'] = new AudioField(result.accessPaths.agnostic.client);
                 }
             };
-            this._videoRef!.srcObject = await (navigator.mediaDevices as any).getDisplayMedia({ video: true });
-            this._videoRec = new MediaRecorder(this._videoRef!.srcObject);
-            const vidChunks: any = [];
+            this._videoRef.srcObject = await navigator.mediaDevices.getDisplayMedia({ video: true });
+            this._videoRec = new MediaRecorder(this._videoRef.srcObject);
+            const vidChunks: Blob[] = [];
             this._videoRec.onstart = () => {
                 if (this.dataDoc[this._props.fieldKey + '_trackScreen']) TrackMovements.Instance.start();
                 this.dataDoc[this._props.fieldKey + '_recordingStart'] = new DateField(new Date());
             };
-            this._videoRec.ondataavailable = (e: any) => vidChunks.push(e.data);
+            this._videoRec.ondataavailable = e => vidChunks.push(e.data);
             this._videoRec.onstop = async () => {
                 const presentation = TrackMovements.Instance.yieldPresentation();
                 if (presentation?.movements) {
                     const presCopy = { ...presentation };
-                    presCopy.movements = presentation.movements.map(movement => ({ ...movement, doc: movement.doc[Id] })) as any;
+                    presCopy.movements = presentation.movements.map(movement => ({ ...movement, doc: (movement.doc as Doc)[Id] }) as Movement);
                     this.dataDoc[this.fieldKey + '_presentation'] = JSON.stringify(presCopy);
                 }
                 TrackMovements.Instance.finish();
-- 
cgit v1.2.3-70-g09d2

