getDefaultUserPresence
See source codeCreates 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: TLPresenceUserInfo
): {
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: string
userName: string
} | null
Example
import { getDefaultUserPresence } from '@tldraw/tlschema'
const user = { id: 'user-123', name: 'Alice', color: '#ff0000' }
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
Name | Description |
---|---|
| The tldraw store containing the current editor state |
| 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: string
userName: string
} | null
The default presence state info, or null if required store records are missing
Prev
getDefaultTranslationLocaleNext
idValidator