diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/client/util/RecordingApi.ts | 81 | ||||
-rw-r--r-- | src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx | 17 |
2 files changed, 56 insertions, 42 deletions
diff --git a/src/client/util/RecordingApi.ts b/src/client/util/RecordingApi.ts index 12ca07d67..a8740a5bd 100644 --- a/src/client/util/RecordingApi.ts +++ b/src/client/util/RecordingApi.ts @@ -4,14 +4,20 @@ import { NumCast } from "../../fields/Types"; import { Doc } from "../../fields/Doc"; import { VideoBox } from "../views/nodes/VideoBox"; import { isArray } from "lodash"; +import { SelectionManager } from "./SelectionManager"; +import { DocumentDecorations } from "../views/DocumentDecorations"; +import { DocumentManager } from "./DocumentManager"; +import { CollectionDockingView } from "../views/collections/CollectionDockingView"; type Movement = { time: number, panX: number, panY: number, scale: number, + docId: String, } + export type Presentation = { movements: Movement[] | null, totalTime: number, @@ -28,6 +34,8 @@ export class RecordingApi { private currentPresentation: Presentation; private tracking: boolean; private absoluteStart: number; + // instance variable for holding the FFViews and their disposers + private recordingFFViews: Map<String, IReactionDisposer> | null; // create static instance and getter for global use @@ -43,8 +51,7 @@ export class RecordingApi { this.absoluteStart = -1; // used for tracking movements in the view frame - this.disposeFunc = null; - this.recordingFFView = null; + this.recordingFFViews = null; // for now, set playFFView this.playFFView = null; @@ -56,7 +63,31 @@ export class RecordingApi { return this.currentPresentation.movements === null } + private addRecordingFFView(doc: Doc, docId: String): void { + const disposeFunc = reaction( + () => ({ x: NumCast(doc.panX, -1), y: NumCast(doc.panY, -1), scale: NumCast(doc.viewScale, 0)}), + (res) => (res.x !== -1 && res.y !== -1 && this.tracking) && this.trackMovements(res.x, res.y, docId, res.scale), + ); + + console.log('adding dispose func : docId', docId, 'doc', doc); + this.recordingFFViews?.set(docId, disposeFunc); + } + public start = (meta?: Object) => { + // init the dispose funcs + this.recordingFFViews = new Map(); + // look over all open tabs and only track free form docs + for (const { contentItem, DashDoc } of CollectionDockingView.Instance.tabMap) { + if ('viewType' in DashDoc && DashDoc.viewType === 'freeform') { + const docId = contentItem.config.props.documentId; + // remove the proxy on the DashDoc by using the spread operator + this.addRecordingFFView(DashDoc, docId); + } + } + + console.log(this.recordingFFViews); + + // update the presentation mode Doc.UserDoc().presentationMode = 'recording'; @@ -79,7 +110,7 @@ export class RecordingApi { if (this.nullPresentation || !this.tracking) return null; // set the previus recording view to the play view - this.playFFView = this.recordingFFView; + // this.playFFView = this.recordingFFView; // ensure we add the endTime now that they are done recording const cpy = { ...this.currentPresentation, totalTime: new Date().getTime() - this.absoluteStart }; @@ -100,7 +131,7 @@ export class RecordingApi { public clear = (): void => { // clear the disposeFunc if we are done (not tracking) if (!this.tracking) { - this.removeRecordingFFView(); + this.removeAllRecordingFFViews(); // update the presentation mode now that we are done tracking Doc.UserDoc().presentationMode = 'none'; } @@ -112,13 +143,16 @@ export class RecordingApi { this.absoluteStart = -1 } - // call on dispose function to stop tracking movements - public removeRecordingFFView = (): void => { - this.disposeFunc?.(); - this.disposeFunc = null; + private removeAllRecordingFFViews = () => { + if (this.recordingFFViews === null) { console.warn('removeFFView on null RecordingApi'); return; } + + for (const [id, disposeFunc] of this.recordingFFViews) { + disposeFunc(); + this.recordingFFViews.delete(id); + } } - private trackMovements = (panX: number, panY: number, scale: number = 0) => { + private trackMovements = (panX: number, panY: number, docId: String, scale: number = 0) => { // ensure we are recording if (!this.tracking) { console.error('[recordingApi.ts] trackMovements(): tracking is false') @@ -133,32 +167,12 @@ export class RecordingApi { // get the time const time = new Date().getTime() - this.absoluteStart // make new movement object - const movement: Movement = { time, panX, panY, scale } + const movement: Movement = { time, panX, panY, scale, docId } // add that movement to the current presentation data's movement array this.currentPresentation.movements && this.currentPresentation.movements.push(movement) } - // instance variable for the FFView - private disposeFunc: IReactionDisposer | null; - private recordingFFView: CollectionFreeFormView | null; - - // set the FFView that will be used in a reaction to track the movements - public setRecordingFFView = (view: CollectionFreeFormView): void => { - // set the view to the current view - if (view === this.recordingFFView || view == null) return; - - // this.recordingFFView = view; - // set the reaction to track the movements - this.disposeFunc = reaction( - () => ({ x: NumCast(view.Document.panX, -1), y: NumCast(view.Document.panY, -1), scale: NumCast(view.Document.viewScale, -1) }), - (res) => (res.x !== -1 && res.y !== -1 && this.tracking) && this.trackMovements(res.x, res.y, res.scale) - ) - - // for now, set the most recent recordingFFView to the playFFView - this.recordingFFView = view; - } - // TODO: extract this into different class with pause and resume recording // TODO: store the FFview with the movements private playFFView: CollectionFreeFormView | null; @@ -269,17 +283,14 @@ export class RecordingApi { return { movements: combinedMovements, totalTime: sumTime, meta: combinedMetas }; } - // Unfinished code for tracing multiple free form views - // export let pres: Map<CollectionFreeFormView, IReactionDisposer> = new Map() - - // export function AddRecordingFFView(ffView: CollectionFreeFormView): void { + // public AddRecordingFFView(ffView: Doc): void { // pres.set(ffView, // reaction(() => ({ x: ffView.panX, y: ffView.panY }), // (pt) => RecordingApi.trackMovements(ffView, pt.x, pt.y))) // ) // } - // export function RemoveRecordingFFView(ffView: CollectionFreeFormView): void { + // public RemoveRecordingFFView(ffView: CollectionFreeFormView): void { // const disposer = pres.get(ffView); // disposer?.(); // pres.delete(ffView) diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx index 5534ddd35..33474bc4b 100644 --- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx +++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx @@ -1006,14 +1006,17 @@ export class CollectionFreeFormView extends CollectionSubView<Partial<collection @action setPan(panX: number, panY: number, panTime: number = 0, clamp: boolean = false) { // set the current respective FFview to the tab being panned. - (Doc.UserDoc()?.presentationMode === 'recording') && RecordingApi.Instance.setRecordingFFView(this); + // if (Doc.UserDoc()?.presentationMode === 'recording') { + // // RecordingApi.Instance.setRecordingFFView(this); + // console.log('setRecordingFFView', this); + // } // TODO: make this based off the specific recording FFView - (Doc.UserDoc()?.presentationMode === 'none') && RecordingApi.Instance.setPlayFFView(this); - if (Doc.UserDoc()?.presentationMode === 'watching') { - RecordingApi.Instance.pauseVideoAndMovements(); - Doc.UserDoc().presentationMode = 'none'; - // RecordingApi.Instance.pauseMovements() - } + // (Doc.UserDoc()?.presentationMode === 'none') && RecordingApi.Instance.setPlayFFView(this); + // if (Doc.UserDoc()?.presentationMode === 'watching') { + // RecordingApi.Instance.pauseVideoAndMovements(); + // Doc.UserDoc().presentationMode = 'none'; + // // RecordingApi.Instance.pauseMovements() + // } if (!this.isAnnotationOverlay && clamp) { // this section wraps the pan position, horizontally and/or vertically whenever the content is panned out of the viewing bounds |