diff options
Diffstat (limited to 'src/client/util/RecordingApi.ts')
-rw-r--r-- | src/client/util/RecordingApi.ts | 153 |
1 files changed, 96 insertions, 57 deletions
diff --git a/src/client/util/RecordingApi.ts b/src/client/util/RecordingApi.ts index 021feee9a..ab6935e3b 100644 --- a/src/client/util/RecordingApi.ts +++ b/src/client/util/RecordingApi.ts @@ -3,8 +3,6 @@ import { IReactionDisposer, observable, reaction } from "mobx"; import { NumCast } from "../../fields/Types"; import { Doc } from "../../fields/Doc"; import { VideoBox } from "../views/nodes/VideoBox"; -import { scaleDiverging } from "d3-scale"; -import { Transform } from "./Transform"; type Movement = { time: number, @@ -13,17 +11,17 @@ type Movement = { scale: number, } -type Presentation = { - movements: Array<Movement> | null - meta: Object, +export type Presentation = { + movements: Movement[] | null, + totalTime: number, + meta: any, } export class RecordingApi { - private static NULL_PRESENTATION: Presentation = { - movements: null, - meta: {}, - } + private static get NULL_PRESENTATION(): Presentation { + return { movements: null, meta: {}, totalTime: -1,} + } // instance variables private currentPresentation: Presentation; @@ -50,6 +48,8 @@ export class RecordingApi { // for now, set playFFView this.playFFView = null; this.timers = null; + + // put a pointerdown event on the doucment to see what the target } // little helper :) @@ -59,8 +59,9 @@ export class RecordingApi { public start = (meta?: Object): Error | undefined => { // check if already init a presentation - if (!this.isInitPresenation) { - console.error('[recordingApi.ts] start() failed: current presentation data exists. please call clear() first.') + if (!this.isInitPresenation) { + console.log(this.currentPresentation) + console.trace('[recordingApi.ts] start() failed: current presentation data exists. please call clear() first.') return new Error('[recordingApi.ts] start()') } @@ -80,50 +81,61 @@ export class RecordingApi { this.isRecording = true } - public clear = (): Error | Presentation => { + /* stops the video and returns the presentatation; if no presentation, returns undefined */ + public getPresentation = (): undefined | Presentation => { // TODO: maybe archive the data? - if (this.isRecording) { - console.error('[recordingApi.ts] clear() failed: currently recording presentation. call pause() first') - return new Error('[recordingApi.ts] clear()') - } - - // update the presentation mode - Doc.UserDoc().presentationMode = 'none' - // set the previus recording view to the play view - this.playFFView = this.recordingFFView - - const presCopy = { ...this.currentPresentation } - - // clear presenation data - this.currentPresentation = RecordingApi.NULL_PRESENTATION - // clear isRecording - this.isRecording = false - // clear absoluteStart - this.absoluteStart = -1 - // clear the disposeFunc - this.removeRecordingFFView() - - return presCopy; + if (this.isRecording) console.warn('[recordingApi.ts] getPresentation() : currently recording presentation.'); + + // update the presentation mode + Doc.UserDoc().presentationMode = 'none'; + // set the previus recording view to the play view + this.playFFView = this.recordingFFView; + + // ensure we add the endTime now that they are done recording + return { ...this.currentPresentation, totalTime: new Date().getTime() - this.absoluteStart }; + } + + public stop = (): void => { + // make is recording false + this.isRecording = false + } + + public clear = (): void => { + // clear presenation data + this.currentPresentation = RecordingApi.NULL_PRESENTATION + // clear isRecording + this.isRecording = false + // clear absoluteStart + this.absoluteStart = -1 + // clear the disposeFunc + this.removeRecordingFFView() + } + + + // call on dispose function to stop tracking movements + public removeRecordingFFView = (): void => { + this.disposeFunc?.(); + this.disposeFunc = null; } - public pause = (): Error | undefined => { - if (this.isInitPresenation) { - console.error('[recordingApi.ts] pause() failed: no presentation started. try calling init() first') - return new Error('[recordingApi.ts] pause(): no presentation') - } - // don't allow track movments - this.isRecording = false - - // set adjust absoluteStart to add the time difference - const timestamp = new Date().getTime() - this.absoluteStart = timestamp - this.absoluteStart - } + // public pause = (): Error | undefined => { + // if (this.isInitPresenation) { + // console.error('[recordingApi.ts] pause() failed: no presentation started. try calling init() first') + // return new Error('[recordingApi.ts] pause(): no presentation') + // } + // // don't allow track movments + // this.isRecording = false + + // // set adjust absoluteStart to add the time difference + // const timestamp = new Date().getTime() + // this.absoluteStart = timestamp - this.absoluteStart + // } - public resume = () => { - this.isRecording = true - // set absoluteStart to the difference in time - this.absoluteStart = new Date().getTime() - this.absoluteStart - } + // public resume = () => { + // this.isRecording = true + // // set absoluteStart to the difference in time + // this.absoluteStart = new Date().getTime() - this.absoluteStart + // } private trackMovements = (panX: number, panY: number, scale: number = 0): Error | undefined => { // ensure we are recording @@ -134,6 +146,8 @@ export class RecordingApi { if (this.isInitPresenation) { return new Error('[recordingApi.ts] trackMovements(): no presentation') } + + console.log('track movment') // get the time const time = new Date().getTime() - this.absoluteStart @@ -164,12 +178,6 @@ export class RecordingApi { this.recordingFFView = view; } - // call on dispose function to stop tracking movements - public removeRecordingFFView = (): void => { - this.disposeFunc?.(); - this.disposeFunc = null; - } - // TODO: extract this into different class with pause and resume recording // TODO: store the FFview with the movements private playFFView: CollectionFreeFormView | null; @@ -250,6 +258,37 @@ export class RecordingApi { }, timeDiff) }) } + + // make a public method that concatenates the movements of the an array of presentations into one array + // TODO: consider the meta data of the presentations + public concatPresentations = (presentations: Presentation[]): Presentation => { + console.info(presentations); + if (presentations.length === 0) return RecordingApi.NULL_PRESENTATION; + const firstPresentation = presentations[0]; + + let sumTime = presentations[0].totalTime; + let combinedPresentations = { ...firstPresentation } + presentations.forEach((presentation, i) => { + // already consider the first presentation + if (i === 0) return; + + const { movements, totalTime } = presentation; + if (movements === null) return; + + // add the summed time to the movements + const addedTimeMovements = movements.map(move => { return { ...move, time: move.time + sumTime } }); + // concat the movements already in the combined presentation with these new ones + const newMovements = [...combinedPresentations.movements || [], ...addedTimeMovements]; + + combinedPresentations = { ...combinedPresentations, movements: newMovements } + + // update the totalTime + sumTime += totalTime; + }); + + // return the combined presentation with the updated total summed time + return { ...combinedPresentations, totalTime: sumTime }; + } // Unfinished code for tracing multiple free form views // export let pres: Map<CollectionFreeFormView, IReactionDisposer> = new Map() |