getDefaultUserPresence

See source code

Creates default presence state information for a user based on the current store state.

This function extracts the current state from various store records (instance, page state, camera, pointer) and combines them with user information to create a complete presence state object. This is commonly used as a starting point for custom presence implementations.

function getDefaultUserPresence(
  store: TLStore,
  user: TLUser,
): {
  brush: import(".").BoxModel | null;
  camera: {
    x: number;
    y: number;
    z: number;
  };
  chatMessage: string;
  color: string;
  currentPageId: import(".").TLPageId;
  cursor: {
    rotation: number;
    type: string;
    x: number;
    y: number;
  };
  followingUserId: null | string;
  lastActivityTimestamp: number;
  meta: {};
  screenBounds: import(".").BoxModel;
  scribbles: import(".").TLScribble[];
  selectedShapeIds: import(".").TLShapeId[];
  userId: import(".").TLUserId;
  userName: string;
} | null;

Example

import { getDefaultUserPresence } from "@tldraw/tlschema";

const user = { id: "user-123", name: "Alice", color: "#ff0000", meta: {} };
const presenceInfo = getDefaultUserPresence(store, user);

if (presenceInfo) {
  console.log("Current cursor:", presenceInfo.cursor);
  console.log("Selected shapes:", presenceInfo.selectedShapeIds);
  console.log("Camera position:", presenceInfo.camera);
}
// Common pattern: customize default presence
const customPresence = {
  ...getDefaultUserPresence(store, user),
  // Remove camera for privacy
  camera: undefined,
  // Add custom metadata
  customField: "my-data",
};

Parameters

NameDescription

store

TLStore;

The tldraw store containing the current editor state

user

TLUser;

The user information to include in the presence state

Returns

{
  brush: import(".").BoxModel | null;
  camera: {
    x: number;
    y: number;
    z: number;
  };
  chatMessage: string;
  color: string;
  currentPageId: import(".").TLPageId;
  cursor: {
    rotation: number;
    type: string;
    x: number;
    y: number;
  };
  followingUserId: null | string;
  lastActivityTimestamp: number;
  meta: {};
  screenBounds: import(".").BoxModel;
  scribbles: import(".").TLScribble[];
  selectedShapeIds: import(".").TLShapeId[];
  userId: import(".").TLUserId;
  userName: string;
} | null;

The default presence state info, or null if required store records are missing

Prev
getDefaultTranslationLocale
Next
idValidator