Skip to content

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

ParameterTypeDescription
getProvider() => | VizelYjsProvider | null | undefinedFunction that returns the Yjs provider instance
optionsVizelCollaborationOptionsCollaboration options including user info and callbacks
onStateChange(state) => voidCallback 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

ParameterType
userVizelCollaborationUser

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();

Released under the MIT License.