diff options
Diffstat (limited to 'src/client/util')
-rw-r--r-- | src/client/util/RecordingApi.ts | 53 |
1 files changed, 28 insertions, 25 deletions
diff --git a/src/client/util/RecordingApi.ts b/src/client/util/RecordingApi.ts index ab6935e3b..009652f6e 100644 --- a/src/client/util/RecordingApi.ts +++ b/src/client/util/RecordingApi.ts @@ -25,7 +25,7 @@ export class RecordingApi { // instance variables private currentPresentation: Presentation; - private isRecording: boolean; + private tracking: boolean; private absoluteStart: number; @@ -38,7 +38,7 @@ export class RecordingApi { // init the instance variables this.currentPresentation = RecordingApi.NULL_PRESENTATION - this.isRecording = false; + this.tracking = false; this.absoluteStart = -1; // used for tracking movements in the view frame @@ -57,58 +57,61 @@ export class RecordingApi { return this.currentPresentation.movements === null } - public start = (meta?: Object): Error | undefined => { + public start = (meta?: Object) => { // check if already init a presentation 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()') + console.trace('[recordingApi.ts] start() failed: current presentation data exists. please call clear() first.') } // update the presentation mode - Doc.UserDoc().presentationMode = 'recording' + Doc.UserDoc().presentationMode = 'recording'; // (1a) get start date for presenation - const startDate = new Date() + const startDate = new Date(); // (1b) set start timestamp to absolute timestamp - this.absoluteStart = startDate.getTime() + this.absoluteStart = startDate.getTime(); // (2) assign meta content if it exists this.currentPresentation.meta = meta || {} // (3) assign start date to currentPresenation this.currentPresentation.movements = [] - // (4) set isRecording true to allow trackMovements - this.isRecording = true + // (4) set tracking true to allow trackMovements + this.tracking = true } /* stops the video and returns the presentatation; if no presentation, returns undefined */ - public getPresentation = (): undefined | Presentation => { + public* yieldPresentation(clearData: boolean = true): Generator<Presentation | null> { // TODO: maybe archive the data? - if (this.isRecording) console.warn('[recordingApi.ts] getPresentation() : currently recording presentation.'); + // if (this.tracking) console.warn('[recordingApi.ts] getPresentation() : currently recording presentation.'); // update the presentation mode - Doc.UserDoc().presentationMode = 'none'; + // 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 }; + yield { ...this.currentPresentation, totalTime: new Date().getTime() - this.absoluteStart }; + + // reset the current presentation + clearData && this.clear(); } public stop = (): void => { - // make is recording false - this.isRecording = false + // make is tracking false + this.tracking = false } public clear = (): void => { + // clear the disposeFunc if we are done (not recording) + if (!this.tracking) + this.removeRecordingFFView() // clear presenation data this.currentPresentation = RecordingApi.NULL_PRESENTATION // clear isRecording - this.isRecording = false + // this.tracking = false // clear absoluteStart this.absoluteStart = -1 - // clear the disposeFunc - this.removeRecordingFFView() } @@ -124,7 +127,7 @@ export class RecordingApi { // return new Error('[recordingApi.ts] pause(): no presentation') // } // // don't allow track movments - // this.isRecording = false + // this.tracking = false // // set adjust absoluteStart to add the time difference // const timestamp = new Date().getTime() @@ -132,14 +135,14 @@ export class RecordingApi { // } // public resume = () => { - // this.isRecording = true + // this.tracking = 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 - if (!this.isRecording) { + if (!this.tracking) { return new Error('[recordingApi.ts] trackMovements()') } // check to see if the presetation is init @@ -171,7 +174,7 @@ export class RecordingApi { // 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.isRecording) && this.trackMovements(res.x, res.y, res.scale) + (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 @@ -262,11 +265,11 @@ export class RecordingApi { // 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); + console.table(presentations); if (presentations.length === 0) return RecordingApi.NULL_PRESENTATION; const firstPresentation = presentations[0]; - let sumTime = presentations[0].totalTime; + let sumTime = firstPresentation.totalTime; let combinedPresentations = { ...firstPresentation } presentations.forEach((presentation, i) => { // already consider the first presentation |