aboutsummaryrefslogtreecommitdiff
path: root/src/client/util/ReplayMovements.ts
diff options
context:
space:
mode:
authorNathan-SR <144961007+Nathan-SR@users.noreply.github.com>2024-05-09 00:02:30 -0400
committerNathan-SR <144961007+Nathan-SR@users.noreply.github.com>2024-05-09 00:02:30 -0400
commit2f5f13946cf0a1ec87efddbfbbc6a9fd878da924 (patch)
treeea9ec90561f73ed1c977e0538699c5f53b3c4712 /src/client/util/ReplayMovements.ts
parent0766ba00727e9e13ced2e16cfb049d49711fa738 (diff)
parentfa4d377b53c9ca31d8900d9c11bd25be57025962 (diff)
Merge branch 'nathan-starter' of https://github.com/brown-dash/Dash-Web into nathan-starter
Diffstat (limited to 'src/client/util/ReplayMovements.ts')
-rw-r--r--src/client/util/ReplayMovements.ts51
1 files changed, 31 insertions, 20 deletions
diff --git a/src/client/util/ReplayMovements.ts b/src/client/util/ReplayMovements.ts
index 530fcf211..c5afe549c 100644
--- a/src/client/util/ReplayMovements.ts
+++ b/src/client/util/ReplayMovements.ts
@@ -1,16 +1,17 @@
import { IReactionDisposer, makeObservable, observable, reaction } from 'mobx';
import { Doc, IdToDoc } from '../../fields/Doc';
-import { CollectionDockingView } from '../views/collections/CollectionDockingView';
import { CollectionFreeFormView } from '../views/collections/collectionFreeForm';
+import { DocumentView } from '../views/nodes/DocumentView';
import { OpenWhereMod } from '../views/nodes/OpenWhere';
-import { VideoBox } from '../views/nodes/VideoBox';
+import { SnappingManager } from './SnappingManager';
import { Movement, Presentation } from './TrackMovements';
-import { DocumentView } from '../views/nodes/DocumentView';
+import { ViewBoxInterface } from '../views/ViewBoxInterface';
+import { StrCast } from '../../fields/Types';
export class ReplayMovements {
private timers: NodeJS.Timeout[] | null;
private videoBoxDisposeFunc: IReactionDisposer | null;
- private videoBox: VideoBox | null;
+ private videoBox: ViewBoxInterface<any> | null;
private isPlaying: boolean;
// create static instance and getter for global use
@@ -29,6 +30,22 @@ export class ReplayMovements {
this.videoBoxDisposeFunc = null;
this.videoBox = null;
this.isPlaying = false;
+
+ reaction(
+ () => SnappingManager.UserPanned,
+ () => {
+ if (Doc.UserDoc()?.presentationMode === 'watching') this.pauseFromInteraction();
+ }
+ );
+ reaction(
+ () => DocumentView.Selected().slice(),
+ selviews => {
+ const selVideo = selviews.find(dv => dv.ComponentView?.playFrom);
+ if (selVideo?.ComponentView?.Play) {
+ this.setVideoBox(selVideo.ComponentView);
+ } else this.removeVideoBox();
+ }
+ );
}
// pausing movements will dispose all timers that are planned to replay the movements
@@ -45,18 +62,16 @@ export class ReplayMovements {
this.timers?.map(timer => clearTimeout(timer));
};
- setVideoBox = async (videoBox: VideoBox) => {
- // console.info('setVideoBox', videoBox);
+ setVideoBox = async (videoBox: ViewBoxInterface<any>) => {
if (this.videoBox !== null) {
console.warn('setVideoBox on already videoBox');
}
- if (this.videoBoxDisposeFunc !== null) {
- console.warn('setVideoBox on already videoBox dispose func');
- this.videoBoxDisposeFunc();
- }
+ this.videoBoxDisposeFunc?.();
+
+ const data = StrCast(videoBox.dataDoc?.[videoBox.fieldKey + '_presentation']);
+ const presentation = data ? JSON.parse(data) : null;
- const { presentation } = videoBox;
- if (presentation == null) {
+ if (presentation === null) {
console.warn('setVideoBox on null videoBox presentation');
return;
}
@@ -64,18 +79,14 @@ export class ReplayMovements {
this.loadPresentation(presentation);
this.videoBoxDisposeFunc = reaction(
- () => ({ playing: videoBox._playing, timeViewed: videoBox.player?.currentTime || 0 }),
+ () => ({ playing: videoBox.IsPlaying?.(), timeViewed: videoBox.PlayerTime?.() || 0 }),
({ playing, timeViewed }) => (playing ? this.playMovements(presentation, timeViewed) : this.pauseMovements())
);
this.videoBox = videoBox;
};
removeVideoBox = () => {
- if (this.videoBoxDisposeFunc == null) {
- console.warn('removeVideoBox on null videoBox');
- return;
- }
- this.videoBoxDisposeFunc();
+ this.videoBoxDisposeFunc?.();
this.videoBox = null;
this.videoBoxDisposeFunc = null;
@@ -83,7 +94,7 @@ export class ReplayMovements {
// should be called from interacting with the screen
pauseFromInteraction = () => {
- this.videoBox?.Pause();
+ this.videoBox?.Pause?.();
this.pauseMovements();
};
@@ -117,7 +128,7 @@ export class ReplayMovements {
return undefined;
}
// console.log('openTab', docId, doc);
- CollectionDockingView.AddSplit(doc, OpenWhereMod.right);
+ DocumentView.addSplit(doc, OpenWhereMod.right);
const docView = DocumentView.getDocumentView(doc);
// BUG - this returns undefined if the doc is already open
return docView?.ComponentView as CollectionFreeFormView;