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
| Property | Type | Description |
|---|
online | Map<string, [CollabKitUser](/types/core#collabkituser)> | Currently online users only |
all | Map<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`);
});
| Event | Payload | Description |
|---|
userJoined | CollabKitUser | A user came online in the room |
userLeft | CollabKitUser | A user went offline |
userCreated | CollabKitUser | A new user was added to the room |
userUpdated | CollabKitUser | A user’s fields changed (name, profile picture, etc.) |
userDeleted | CollabKitUser | A 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
| Property | Type | Description |
|---|
id | string | Unique user ID |
name | string | Display name |
status | 'online' | 'offline' | Current connection status |
profile_picture | string | undefined | Avatar URL |
room_id | string | The room this user belongs to |
created_at | string | ISO timestamp of user creation |
joined_at | string | undefined | Last time the user came online |
left_at | string | undefined | Last time the user went offline |
following | string[] | User IDs this user is following |
followers | string[] | 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);
});
| Event | Payload | Description |
|---|
updated | CollabKitUser | The user’s fields changed |
statusChanged | CollabKitUser | Online/offline status changed |
deleted | CollabKitUser | The user was removed |
commentTagged | CollabKitComment | The user was tagged in a comment |
followersChanged | CollabKitUser | The 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();