TLSocketRoomOptions

See source code
Table of contents

Base options for TLSocketRoom.

interface TLSocketRoomOptions<R extends UnknownRecord, SessionMeta> {}

Properties

authorizeRecord

optional

Per-type authorizers for client record writes (create, update, delete): veto writes the session isn't allowed to make, or rewrite the record on create — e.g. force a comment's authorId to the signed-in user. See TLRecordAuthorizers.

authorizeRecord?: TLRecordAuthorizers<R, SessionMeta>;

clientTimeout

optional
clientTimeout?: number;

initialSnapshot

optional

Deprecated: use the storage option instead

initialSnapshot?: RoomSnapshot | TLStoreSnapshot;

log

optional
log?: TLSyncLog;

objectTypes

optional

Record type names to serve through the object-store lane instead of the document lane. Each must be a document-scoped type registered in the schema. Object-lane writes are gated per session by objectAccess (see TLSocketRoom.handleSocketConnect) rather than isReadonly, so e.g. a session can be allowed to comment without being allowed to edit.

objectTypes?: readonly string[];

onAfterReceiveMessage

optional
onAfterReceiveMessage?: (args: {
  message: TLSocketServerSentEvent<R>;
  meta: SessionMeta;
  sessionId: string;
  stringified: string;
}) => void;

onBeforeSendMessage

optional
onBeforeSendMessage?: (args: {
  message: TLSocketServerSentEvent<R>;
  meta: SessionMeta;
  sessionId: string;
  stringified: string;
}) => void;

onCommittedChanges

optional

Called once after a client push commits, with the committed document diff. Use to react to document changes as soon as they commit — e.g. project certain record types to an external store. Best-effort: do not throw and do not block.

Only fires for client pushes. Server-initiated changes — updateStore, loadSnapshot, or writing to the storage directly — do not trigger it, so anything mirroring room state through this callback must handle those paths itself.

onCommittedChanges?: (args: {
  diff: TLSyncForwardDiff<R>;
  documentClock: number;
}) => void;

onSessionRemoved

optional
onSessionRemoved?: (
  room: TLSocketRoom<R, SessionMeta>,
  args: {
    meta: SessionMeta;
    numSessionsRemaining: number;
    sessionId: string;
  },
) => void;

onSessionSnapshot

optional

When set, the room will call TLSocketRoom.getSessionSnapshot after no message activity for a session for 5s and pass the result to this callback. Use for persisting snapshots to WebSocket attachments (e.g. Cloudflare hibernation). The room clears any pending snapshot when the session closes.

onSessionSnapshot?: (
  sessionId: string,
  snapshot: SessionStateSnapshot,
) => void;

schema

optional
schema?: StoreSchema<R, any>;

storage

optional
storage?: TLSyncStorage<R>;

Methods

onDataChange

optional

Deprecated: use the storage option with an onChange callback instead


Prev
TLPersistentClientSocket
Next
TLSyncForwardDiff