Skip to content

Commit

Permalink
more frameloader cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ritch committed Sep 25, 2024
1 parent 0a136c2 commit 47fce10
Showing 1 changed file with 5 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,62 +1,38 @@
import React, {
forwardRef,
useCallback,
useEffect,
useMemo,
useRef,
useState,
} from "react";
import React, { useEffect, useRef, useState } from "react";
import { ObjectSchemaType, ViewPropsType } from "../utils/types";
import {
DEFAULT_FRAME_NUMBER,
GLOBAL_TIMELINE_ID,
} from "@fiftyone/playback/src/lib/constants";
import { BufferManager, BufferRange } from "@fiftyone/utilities";
import { usePanelEvent } from "@fiftyone/operators";
import {
usePanelId,
usePanelState,
useSetPanelStateById,
} from "@fiftyone/spaces";
import { usePanelId, useSetPanelStateById } from "@fiftyone/spaces";
import { useTimeline } from "@fiftyone/playback/src/lib/use-timeline";
import _ from "lodash";
import { useDefaultTimelineName } from "@fiftyone/playback/src/lib/use-default-timeline-name";

export default function FrameLoaderView(props: ViewPropsType) {
const { schema, path, data } = props;
const { view = {} } = schema;
const { on_load_range, timeline_id, target } = view;
const { properties } = schema as ObjectSchemaType;
const panelId = usePanelId();
const [myLocalFrameNumber, setMyLocalFrameNumber] =
React.useState(DEFAULT_FRAME_NUMBER);
const triggerEvent = usePanelEvent();
const setPanelState = useSetPanelStateById(true);
const localIdRef = React.useRef<string>();
const bufm = useRef(new BufferManager());

useEffect(() => {
localIdRef.current = Math.random().toString(36).substring(7);
// console.log("localIdRef", localIdRef.current);
if (data?.frames)
// console.log("dispatching frames-loaded", localIdRef.current);
dispatchEvent(
window.dispatchEvent(
new CustomEvent(`frames-loaded`, {
detail: { localId: localIdRef.current },
})
);
}, [data?.signature]); // remove this JSON.strignify
}, [data?.signature]);

const loadRange = React.useCallback(
async (range: BufferRange) => {
if (on_load_range) {
// if (!bufm.current.containsRange(range)) {
// // only trigger event if the range is not already in the buffer
// await triggerEvent(panelId, {
// params: { range },
// operator: on_load_range,
// });
// }
const unp = bufm.current.getUnprocessedBufferRange(range);
const isProcessed = unp === null;

Expand All @@ -66,15 +42,13 @@ export default function FrameLoaderView(props: ViewPropsType) {
operator: on_load_range,
});
}
console.log("loading range", range);

return new Promise<void>((resolve) => {
window.addEventListener(`frames-loaded`, (e) => {
// console.log("frames loaded", e, {'current': localIdRef.current, 'detail': e.detail.localId});
if (
e instanceof CustomEvent &&
e.detail.localId === localIdRef.current
) {
// console.log("resolving");
bufm.current.addNewRange(range);
resolve();
}
Expand All @@ -89,8 +63,6 @@ export default function FrameLoaderView(props: ViewPropsType) {

const myRenderFrame = React.useCallback(
(frameNumber: number) => {
setMyLocalFrameNumber(frameNumber);
// console.log("rendering frame", frameNumber, props);
setPanelState(panelId, (current) => {
const currentData = current.data ? _.cloneDeep(current.data) : {}; // Clone the object
const currentFrameData = _.get(currentData, path, { frames: [] })
Expand Down

0 comments on commit 47fce10

Please sign in to comment.