Presence

Show who is in a document, display collaborator names and avatars, and enable remote cursors and selections.

Presence shows who else has the same document open and where each person is working. When Bob selects cell B3, for example, Alice sees his selection labeled with the name “Bob”. Applications can also display the current collaborators in an avatar bar or a member list.

The SDK synchronizes membership and cursor information and renders remote cursors where the editor supports them. Collaborator names and avatars are supplied by the application, and the member subscription API is available for avatar bars, member panels, and online user counts.

Before you begin

Complete Quick start and Identity and authorization first. At that point the editor should synchronize edits, the server should identify the signed-in user through context.userID, and the read, JOIN, and edit policies should be in place.

The examples below extend the existing transport, endpoint, and univer setup. Retain the authentication and authorization rules from the previous guide.

Member and cursor synchronization

Alice and Bob open the same spreadsheet. Presence produces two kinds of updates:

ActionMember listWhat Alice sees in the sheet
Alice opens the sheetAliceHer own selection
Bob opens the same sheetAlice, BobBob's selection when he selects a cell
Bob moves from B3 to C5Alice, BobBob's selection moves to C5
Bob closes the sheetAlice, after the leave update arrivesBob's selection disappears

The member list changes when a connection joins or leaves. Moving a cursor only changes the selection drawn in the editor; it does not add or remove a member. If Bob also edits the value in C5, the document content is synchronized through the collaboration editing flow.

Presence is scoped to one document, a Unit. It covers the people currently connected to that document, while the access list configured in the previous guide covers everyone allowed to open it. Presence is temporary: cursor movement does not create a changeset, does not advance the document revision, and is not saved to the database.

With the collaboration plugins from Quick start and the corresponding editor UI enabled, the SDK captures local cursor and selection updates, sends them, and renders the corresponding cursors, selections, and names in other members' editors.

EditorOnline member subscriptionRemote cursor and selection UI
SheetSupportedCell and range selections
DocSupportedText cursors and selections
SlideSupportedPointer positions and object selections
BoardSupportedPointer positions and object selections
BaseSupportedNot available

1. Set collaborator names and avatars

Set context.member.name and context.member.avatar in the Endpoint's connect Middleware. The application decides how to retrieve the profile: query it with the authenticated context.session.userID, or reuse data saved during authentication in customData.

This example uses customData to avoid a second lookup. Add these fields to the existing Transport Middleware and register connect before starting the server:

TypeScript
type AppUser = {  id: string;  name: string;  avatar?: string;};transport.use(async (context, next) => {  // Your authentication function; rejects unauthenticated requests.  const user: AppUser = await auth.requireUser(context.incomingMessage);  context.userID = user.id;  // An application-defined field to reuse the profile in connect.  context.customData.user = user;  await next();});endpoint.use("connect", async (context, next) => {  // Read the profile saved when the session ticket was issued.  const user = context.session.customData.user as AppUser;  // Without this assignment, the member name defaults to userID.  context.member.name = user.name;  // Use an empty string when there is no avatar URL.  context.member.avatar = user.avatar ?? "";  await next();});

The SDK passes the customData from the session-ticket request to context.session.customData. In a multi-node deployment, a sender connected to another node arrives with only userID and memberID, so data that must travel with each message belongs in the Presence payload. The user key and the AppUser type are application choices; the SDK does not interpret them. Other collaborators receive the profile assigned to context.member.

connect runs once for each new WebSocket connection, including reconnections, and always before the client joins a document. When a profile changes in the application, the member profiles already shared with existing connections do not update automatically.

2. Display a member list (optional)

To build an avatar bar or a member panel, subscribe to the members of the open document with subscribeCollaborators(unitID, callback). Cursor rendering does not depend on this subscription.

TypeScript
import { FUniver } from "@univerjs/core/facade";// Import once in the client entry point to enable collaboration Facade methods.import "@univerjs-pro/collaboration-client/facade";// Reuse an existing univerAPI if your editor setup already provides one.const univerAPI = FUniver.newAPI(univer);// unitID is the ID of the document open in the editor.const subscription = univerAPI.getCollaboration().subscribeCollaborators(unitID, (members) => {  // Each callback is a new list snapshot that the application can use to update its UI.  console.table(members);});

The SDK waits for the document's collaboration room to become available. Each callback receives an IMember[] snapshot of the members currently known to the client, including the client itself once it has joined. An empty list can arrive during initialization. The callback reports membership, not cursor positions.

For Alice and Bob, the member data contains fields like these (IDs are illustrative):

userIDmemberIDnameavatar
alice83446a72-a1cc-4ed8-aedc-afd8907bbb18Alice""
bob7ee5a94e-c784-4e1e-b1a3-b9d34be8ec4eBob""

userID identifies a person in the application. memberID identifies one connection and is assigned by the SDK. If Bob opens a second tab, the list gains another entry with userID: "bob" and a different memberID, so there are now two users and three connections. Applications can group by userID for an avatar bar or an online user count, or use memberID to display and count connections. The editor renders each connection's cursor separately.

Release the subscription when the view that uses it is removed:

TypeScript
subscription.dispose();

Dispose an application-created univerAPI and the Univer instance when the editor is destroyed. Closing only a member panel requires disposing only that panel's subscription.

Example: a React member list

Pass the existing univerAPI and the document ID into this component:

TSX
import type { FUniver } from "@univerjs/core/facade";import type { IMember } from "@univerjs/protocol";import "@univerjs-pro/collaboration-client/facade";import { useEffect, useState } from "react";export function OnlineMembers({ univerAPI, unitID }: { univerAPI: FUniver; unitID: string }) {  const [members, setMembers] = useState<IMember[]>([]);  useEffect(() => {    // Clear the previous document list while waiting for the new subscription.    setMembers([]);    const subscription = univerAPI.getCollaboration().subscribeCollaborators(unitID, setMembers);    // Unsubscribe when the document changes or the component unmounts.    return () => subscription.dispose();  }, [univerAPI, unitID]);  // Show each user once, even when they have multiple connections.  const users = [...new Map(members.map((member) => [member.userID, member])).values()];  return (    <ul>      {users.map((user) => (        <li key={user.userID}>          {user.avatar && <img src={user.avatar} alt="" width={24} height={24} />}          <span>{user.name}</span>        </li>      ))}    </ul>  );}

The subscription reflects the latest room membership received by the client. A lost connection takes time to detect, so a departing member may remain in the list briefly. The SDK's built-in collaboration status UI provides the current client's synchronization state, an offline indication, and a reconnect action.

Try it with two users

  1. Sign in as Alice and Bob in separate browser profiles and open the same document.
  2. Check that both names appear in the member list.
  3. In a Sheet, select B3 as Bob, then C5. Alice should see Bob's named selection move while the member list stays unchanged.
  4. Open another tab as Bob. The subscription should include another memberID, and the React list should still display Bob once.
  5. Close both Bob tabs. After the leave updates arrive, Alice's list should contain only Alice.

How is this guide?

© 2026 DreamNum Co., Ltd.