This commit is contained in:
@@ -16,6 +16,7 @@ export interface UseYjsBindingOptions {
|
||||
userName: string;
|
||||
userColor: string;
|
||||
enabled?: boolean;
|
||||
token?: string;
|
||||
}
|
||||
|
||||
export interface UseYjsBindingResult {
|
||||
@@ -44,7 +45,7 @@ export interface UseYjsBindingResult {
|
||||
const DEFAULT_WS_URL = `wss://${window.location.host}`;
|
||||
|
||||
export function useYjsBinding(opts: UseYjsBindingOptions): UseYjsBindingResult {
|
||||
const { docName, wsUrl = DEFAULT_WS_URL, userId, userName, userColor, enabled = true } = opts;
|
||||
const { docName, wsUrl = DEFAULT_WS_URL, userId, userName, userColor, enabled = true, token } = opts;
|
||||
|
||||
const yjsDocRef = useRef<YjsDocument | null>(null);
|
||||
const providerRef = useRef<WebSocketProvider | null>(null);
|
||||
@@ -92,7 +93,7 @@ export function useYjsBinding(opts: UseYjsBindingOptions): UseYjsBindingResult {
|
||||
const unbindLocal = provider.bindLocalUpdates();
|
||||
|
||||
// Connect
|
||||
provider.connect();
|
||||
provider.connect(token);
|
||||
syncState();
|
||||
|
||||
// Cleanup
|
||||
@@ -107,7 +108,7 @@ export function useYjsBinding(opts: UseYjsBindingOptions): UseYjsBindingResult {
|
||||
providerRef.current = null;
|
||||
awarenessRef.current = null;
|
||||
};
|
||||
}, [docName, wsUrl, userId, userName, userColor, enabled]);
|
||||
}, [docName, wsUrl, userId, userName, userColor, enabled, token]);
|
||||
|
||||
// Mutators
|
||||
const setElement = useCallback((el: CADElement) => {
|
||||
|
||||
Reference in New Issue
Block a user