import { Awareness } from 'y-protocols/awareness'; import * as Y from 'yjs'; import { type CollaborationRole } from './identity.js'; import { type TeardownOptions } from './lifecycle.js'; import { type SyncGate } from './policy.js'; import { type PresenceIdentity, type RemotePresence } from './presence.js'; import { type ConnectionStatus, type ProviderFactory, type SyncProvider } from './provider.js'; export interface SessionOptions
{
roomId: string;
provider: ProviderFactory;
user: {
name: string;
/** Defaults to a stable palette colour derived from the client id. */
color?: string;
avatar?: string;
role?: CollaborationRole;
};
/** Bring your own document (for example one a viewer already populated). */
doc?: Y.Doc;
/** The local "where am I" payload published with the identity. */
initialPresence?: P;
/** Validate a remote payload; return `null` to hide that peer. Defaults to accepting `{}`. */
sanitizePayload?: (raw: Record {
status: ConnectionStatus;
synced: boolean;
/** The remote presence list changed (join, leave, move, staleness). */
peers: RemotePresence [];
/** Local writes just became allowed (once per connection epoch). */
ready: undefined;
error: Error;
}
export interface CollabSession {
readonly roomId: string;
readonly doc: Y.Doc;
readonly awareness: Awareness;
readonly clientId: number;
readonly role: CollaborationRole | undefined;
readonly identity: PresenceIdentity;
readonly gate: SyncGate;
readonly provider: SyncProvider;
readonly status: ConnectionStatus;
readonly synced: boolean;
/** Writes are allowed: the gate opened (synced, or the grace period passed), not a viewer, not destroyed. */
canWrite: () => boolean;
peers: () => RemotePresence [];
/** Merge a patch into the published local presence payload (throttled). */
updatePresence: (patch: Partial ) => void;
on: [K]) => void) => () => void;
connect: () => void;
disconnect: () => void;
/** Leave the room and release everything; a session created with `doc` leaves that doc alive. */
destroy: () => void;
}
export declare function createCollabSession (options: SessionOptions ): CollabSession ;
//# sourceMappingURL=session.d.ts.map