Vizel API / core/src / createVizelCollaborationHandlers
Function: createVizelCollaborationHandlers()
ts
function createVizelCollaborationHandlers(
getProvider,
options,
onStateChange): object;Defined in: packages/core/src/collaboration.ts:130
Create collaboration handlers for tracking provider state and managing lifecycle.
The handlers set up event listeners on the Yjs provider to track connection state, sync status, and peer count. Call subscribe() to start listening and use the returned cleanup function to stop.
Parameters
| Parameter | Type | Description |
|---|---|---|
getProvider | () => | VizelYjsProvider | null | undefined | Function that returns the Yjs provider instance |
options | VizelCollaborationOptions | Collaboration options including user info and callbacks |
onStateChange | (state) => void | Callback to update reactive state |
Returns
Collaboration control methods
connect
ts
connect: () => void;Connect to the collaboration server
Returns
void
disconnect
ts
disconnect: () => void;Disconnect from the collaboration server
Returns
void
subscribe
ts
subscribe: () => () => void;Subscribe to provider events. Returns an unsubscribe function.
Returns
() => void
updateUser
ts
updateUser: (user) => void;Update the current user's cursor information
Parameters
| Parameter | Type |
|---|---|
user | VizelCollaborationUser |
Returns
void
Example
ts
const handlers = createVizelCollaborationHandlers(
() => wsProvider,
{ user: { name: "Alice", color: "#ff0000" } },
(partial) => Object.assign(state, partial)
);
// Start listening to provider events
const unsubscribe = handlers.subscribe();
// Later, clean up
unsubscribe();