Skip to content

Commit 4d1e8de

Browse files
committed
feat: 워크 스페이스에 따른 Y.Doc, 소켓룸 분리
1 parent 637af0c commit 4d1e8de

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

apps/frontend/src/app/App.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,24 @@ import { CanvasView } from "@/widgets/CanvasView";
66
import { EditorView } from "@/widgets/EditorView";
77
import { PageSideBarView } from "@/widgets/PageSideBarView";
88
import { CanvasToolsView } from "@/widgets/CanvasToolsView";
9+
import { useWorkspace } from "@/shared/lib/useWorkspace";
10+
import { useEffect } from "react";
11+
import * as Y from "yjs";
12+
import useYDocStore from "@/shared/model/ydocStore";
913

1014
const queryClient = new QueryClient();
1115

1216
function App() {
1317
useSyncedUsers();
1418

19+
const workspace = useWorkspace();
20+
const { setYDoc } = useYDocStore();
21+
22+
useEffect(() => {
23+
const doc = new Y.Doc({ guid: workspace });
24+
setYDoc(doc);
25+
}, [workspace, setYDoc]);
26+
1527
return (
1628
<QueryClientProvider client={queryClient}>
1729
<div className="fixed inset-0 bg-white">

apps/frontend/src/features/canvas/model/useCanvas.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import { createSocketIOProvider } from "@/shared/api/socketProvider";
2121
import { useCollaborativeCursors } from "./useCollaborativeCursors";
2222
import { getSortedNodes } from "./sortNodes";
2323
import { usePageStore } from "@/features/pageSidebar/model/pageStore";
24+
import { useWorkspace } from "@/shared/lib/useWorkspace";
25+
2426
export interface YNode extends Node {
2527
isHolding: boolean;
2628
}
@@ -32,10 +34,12 @@ export const useCanvas = () => {
3234
const queryClient = useQueryClient();
3335
const { ydoc } = useYDocStore();
3436

37+
const workspace = useWorkspace();
38+
3539
const { cursors, handleMouseMove, handleNodeDrag, handleMouseLeave } =
3640
useCollaborativeCursors({
3741
ydoc,
38-
roomName: "flow-room",
42+
roomName: `flow-room-${workspace}`,
3943
});
4044

4145
const provider = useRef<SocketIOProvider>();

apps/frontend/src/features/canvas/model/useCollaborativeCursors.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { useReactFlow, type XYPosition } from "@xyflow/react";
66
import { createSocketIOProvider } from "@/shared/api/socketProvider";
77
import { useUserStore } from "@/entities/user/model";
88

9+
import { useWorkspace } from "@/shared/lib/useWorkspace";
10+
911
export interface AwarenessState {
1012
cursor: XYPosition | null;
1113
color: string;
@@ -28,9 +30,10 @@ export function useCollaborativeCursors({
2830
);
2931
const { currentUser } = useUserStore();
3032
const { color, clientId } = currentUser;
33+
const workspace = useWorkspace();
3134

3235
useEffect(() => {
33-
const wsProvider = createSocketIOProvider("flow-room", ydoc);
36+
const wsProvider = createSocketIOProvider(`flow-room-${workspace}`, ydoc);
3437
provider.current = wsProvider;
3538

3639
wsProvider.awareness.setLocalState({

0 commit comments

Comments
 (0)