Skip to main content
The Users module provides access to all users (online & offline) in the current room. It tracks user states in real time & emits events. Access the collection via client.users, or client.currentUser for the local user.

User Collection

The User module offers two collections, all and online:

Properties

PropertyTypeDescription
onlineMap<string, [CollabKitUser](/types/core#collabkituser)>Currently online users only
allMap<string, [CollabKitUser](/types/core#collabkituser)>All users in the room (online and offline)

Methods

Get User Details

get(userId?: string) Fetch the current user’s data from the server. Optionally pass a userId to fetch a specific user.
// Refresh current user
const me = await client.users.get();

// Fetch a specific user
const user = await client.users.get({ userId: 'user-002' });

Get All Users

getAll() Fetch all users in the room from the server:
const users = await client.users.getAll();

Events

Listen for user lifecycle events on the collection like so:
client.users.on('userJoined', (user) => {
  console.log(`${user.name} came online`);
});

EventPayloadDescription
userJoinedCollabKitUserA user came online in the room
userLeftCollabKitUserA user went offline
userCreatedCollabKitUserA new user was added to the room
userUpdatedCollabKitUserA user’s fields changed (name, profile picture, etc.)
userDeletedCollabKitUserA user was removed from the room

Individual User

Each user in the client.users.all map is a CollabKitUser instance with its own properties, methods, and events.

Properties

PropertyTypeDescription
idstringUnique user ID
namestringDisplay name
status'online' | 'offline'Current connection status
profile_picturestring | undefinedAvatar URL
room_idstringThe room this user belongs to
created_atstringISO timestamp of user creation
joined_atstring | undefinedLast time the user came online
left_atstring | undefinedLast time the user went offline
followingstring[]User IDs this user is following
followersstring[]User IDs following this user

Methods

update({ name, profilePicture })

Update the user’s fields:
const user = client.users.all.get('user-001');
await user.update({ name: 'Updated Name' });

delete()

Remove the user from the room:
const user = client.users.all.get('user-001');
await user.delete();

follow()

Follow another user. You can only follow one user at a time:
const targetUser = client.users.all.get('user-002');
await targetUser.follow();
Following is limited to one user at a time. If you’re already following someone and call follow() on a different user, you’ll get an error. Call unfollow() first.

unfollow()

Stop following a user:
const targetUser = client.users.all.get('user-002');
await targetUser.unfollow();

Events

Listen for events on an individual user like so:
const user = client.users.all.get('user-001');

user.on('updated', (user) => {
  console.log('Fields changed:', user.name);
});
EventPayloadDescription
updatedCollabKitUserThe user’s fields changed
statusChangedCollabKitUserOnline/offline status changed
deletedCollabKitUserThe user was removed
commentTaggedCollabKitCommentThe user was tagged in a comment
followersChangedCollabKitUserThe user’s followers list changed

Example

Render a User List

function renderUsers() {
  const users = Array.from(client.users.all.values());

  const html = users.map((u) => {
    const dot = u.status === 'online' ? '🟢' : '⚫';
    return `<li>${dot} ${u.name}</li>`;
  }).join('');

  document.getElementById('user-list').innerHTML = html;
}

// Re-render on any user change
client.users.on('userJoined', renderUsers);
client.users.on('userLeft', renderUsers);
client.users.on('userUpdated', renderUsers);
client.users.on('userCreated', renderUsers);
client.users.on('userDeleted', renderUsers);

// Initial render after connecting
await client.connect();
renderUsers();