Skip to content

Commit 0ae08df

Browse files
committed
perf(collaboration): update presence via awareness fields without socket tear down
1 parent 013f198 commit 0ae08df

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/hooks/useCollaboration.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// @ts-nocheck
21
import { useEffect, useRef, useState } from 'react';
32
import * as Y from 'yjs';
43
import { WebsocketProvider } from 'y-websocket';
@@ -141,7 +140,16 @@ export function useCollaboration(roomId: string, user: CollaborationUser, websoc
141140
strokesRef.current = null;
142141
chatRef.current = null;
143142
};
144-
}, [roomId, user.id, user.name, user.avatar, user.color, websocketEndpoint]);
143+
}, [roomId, user.id, websocketEndpoint]);
144+
145+
useEffect(() => {
146+
const provider = providerRef.current;
147+
if (!provider) return;
148+
provider.awareness.setLocalStateField('user', {
149+
...user,
150+
isActive: true,
151+
});
152+
}, [user.name, user.avatar, user.color]);
145153

146154
const updateText = (value: string) => {
147155
if (!yTextRef.current) {

0 commit comments

Comments
 (0)