@@ -7,7 +7,7 @@ import useUserStore from "@/store/useUserStore";
77export interface AwarenessState {
88 cursor : XYPosition | null ;
99 color : string ;
10- clientId : number ;
10+ clientId : string ;
1111}
1212
1313interface CollaborativeCursorsProps {
@@ -25,6 +25,7 @@ export function useCollaborativeCursors({
2525 new Map ( ) ,
2626 ) ;
2727 const { currentUser } = useUserStore ( ) ;
28+ const { color, clientId } = currentUser ;
2829
2930 useEffect ( ( ) => {
3031 const wsProvider = new SocketIOProvider (
@@ -46,23 +47,25 @@ export function useCollaborativeCursors({
4647
4748 wsProvider . awareness . setLocalState ( {
4849 cursor : null ,
49- color : currentUser . color ,
50- clientId : currentUser . clientId ,
50+ color,
51+ clientId,
5152 } ) ;
5253
5354 wsProvider . awareness . on ( "change" , ( ) => {
5455 const states = new Map (
5556 Array . from (
5657 wsProvider . awareness . getStates ( ) as Map < number , AwarenessState > ,
57- ) . filter ( ( [ , state ] ) => state . cursor !== null ) ,
58+ ) . filter (
59+ ( [ , state ] ) => state . clientId !== clientId && state . cursor !== null ,
60+ ) ,
5861 ) ;
5962 setCursors ( states ) ;
6063 } ) ;
6164
6265 return ( ) => {
6366 wsProvider . destroy ( ) ;
6467 } ;
65- } , [ ydoc , roomName ] ) ;
68+ } , [ ydoc , roomName , color , clientId ] ) ;
6669
6770 const updateCursorPosition = useCallback (
6871 ( x : number | null , y : number | null ) => {
@@ -75,11 +78,11 @@ export function useCollaborativeCursors({
7578
7679 provider . current . awareness . setLocalState ( {
7780 cursor,
78- color : currentUser . color ,
79- clientId : currentUser . clientId ,
81+ color,
82+ clientId,
8083 } ) ;
8184 } ,
82- [ flowInstance ] ,
85+ [ flowInstance , color , clientId ] ,
8386 ) ;
8487
8588 const handleMouseMove = useCallback (
0 commit comments