Skip to content

Commit

Permalink
Fix for extremely minor sync issue
Browse files Browse the repository at this point in the history
  • Loading branch information
spaaaacccee committed May 10, 2024
1 parent bb4996e commit 8aea00c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
1 change: 1 addition & 0 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function App() {
<Fade in>
<Stack
sx={{
WebkitAppRegion: "drag",
background: (t) => t.palette.background.paper,
width: "100vw",
height: "100vh",
Expand Down
2 changes: 2 additions & 0 deletions client/src/hooks/usePlaybackState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export function usePlaybackState(key?: string) {
canStepBackward: ready && !playing && step > 0,
};

console.log(layer);

const pause = (n = 0) => {
// notify("Playback paused");
setPlaybackState({ playback: "paused", step: stepBy(n) });
Expand Down
9 changes: 5 additions & 4 deletions client/src/layers/trace/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,11 @@ export const controller = {
view: "main",
});
useEffect(() => {
produce((l) =>
set(l, "source.playbackTo", trace?.content?.events?.length ?? 0)
);
}, [trace?.content?.events?.length]);
produce((l) => {
console.log(trace?.content?.events?.length);
return set(l, "source.playbackTo", trace?.content?.events?.length ?? 0);
});
}, [trace?.key, trace?.lastModified]);
useEffectWhen(
async () => {
const parsedTrace = await parseTrace();
Expand Down
22 changes: 15 additions & 7 deletions client/src/services/SyncService.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useEffectWhen } from "hooks/useEffectWhen";
import { useEffect, useSyncExternalStore } from "react";
import { throttle } from "lodash";
import { useEffect, useMemo, useSyncExternalStore } from "react";
import { usePrevious } from "react-use";
import { Layers, useLayers } from "slices/layers";
import { Settings, useSettings } from "slices/settings";
import sysend from "sysend";
import { instance, participant } from "./SyncParticipant";
import { usePrevious } from "react-use";
import { merge } from "lodash";

export function useSyncStatus() {
return useSyncExternalStore(
Expand All @@ -30,7 +30,6 @@ export function SyncService() {
const {
isPrimary,
isOnly,
loading,
participants: participants,
peers,
} = useSyncStatus();
Expand All @@ -50,7 +49,7 @@ export function SyncService() {
participants.includes(initiator) &&
c3 !== c2
)
setLayers((prev) => merge(prev, state.layers ?? prev), true);
setLayers((prev) => state.layers ?? prev, true);
});
return () => {
sysend.off("settings");
Expand All @@ -72,11 +71,20 @@ export function SyncService() {
[c1, peers.length]
);
const previous = usePrevious(c2);
const broadCastLayers = useMemo(
() =>
throttle(
(...args: Parameters<typeof sysend.broadcast<SyncedData>>) =>
sysend.broadcast(...args),
300
),
[]
);
// Any changes
useEffectWhen(
() => {
if (previous && participants.length) {
sysend.broadcast<SyncedData>("layers", {
broadCastLayers("layers", {
initiator: instance,
state: { layers },
commit: c2,
Expand All @@ -90,7 +98,7 @@ export function SyncService() {
useEffectWhen(
() => {
if (!isOnly && isPrimary) {
sysend.broadcast<SyncedData>("layers", {
broadCastLayers("layers", {
initiator: instance,
state: { layers },
commit: c2,
Expand Down

0 comments on commit 8aea00c

Please sign in to comment.