import { EventSubscriber, ServerMessage, VerdantInternalPresence } from '@verdant-web/common'; import { Context } from '../context/context.js'; import type { UserInfo } from '../index.js'; import { LocalReplicaInfo } from '../persistence/interfaces.js'; export declare const HANDLE_MESSAGE: unique symbol; export declare class PresenceManager extends EventSubscriber<{ /** * Fired when a particular peer's presence changes */ peerChanged: (userId: string, presence: UserInfo) => void; /** * Fired immediately when a change to local presence is made. This change may not * yet have been sent to the server (see: "update" event) */ selfChanged: (presence: UserInfo) => void; /** Fired when any number of peer presences have changed */ peersChanged: (peers: Record>) => void; /** Fired when a peer presence goes offline */ peerLeft: (userId: string, lastPresence: UserInfo) => void; /** Fired after local presence changes are flushed to the server. */ update: (data: { presence?: Presence; internal?: VerdantInternalPresence; }) => void; load: () => void; /** Fired on any change to a peer or the local user */ change: () => void; /** The server's in-memory presence revision was reset. */ versionReset: () => void; }> { private _peers; private _self; private _selfReplicaIds; private _peerIds; private presenceEpoch; private snapshotRevision; private newerUpdates; private _updateBatcher; private _updateBatch; get self(): UserInfo; get peers(): Record>; get peerIds(): string[]; get everyone(): { [x: string]: UserInfo; }; get selfReplicaIds(): Set; constructor({ initialPresence, updateBatchTimeout, defaultProfile, ctx, }: { initialPresence: Presence; defaultProfile: Profile; updateBatchTimeout?: number; ctx: Context; }); /** * Decides if an update is for the local user or not. Even if it's a different replica * than the local one. * * If the replicaId matches, we use that first - we may not know the local replica's User ID yet, * e.g. on the first presence update. * * Otherwise, match the user ID to our local copy. */ private isSelf; [HANDLE_MESSAGE]: (localReplicaInfo: LocalReplicaInfo, message: ServerMessage) => Promise; private updateSelf; update: (presence: Partial) => Promise; flushPresenceUpdates: (presenceUpdates: { presence?: Partial; internal?: Partial; }[]) => void; setViewId: (viewId: string | undefined) => void; setFieldId: (fieldId: string | undefined, timestamp?: number) => void; /** * Get all peers that are in the same view as the local user. */ getViewPeers: () => UserInfo[]; /** * Get all peers that have interacted with the specified * field most recently. */ getFieldPeers: (fieldId: string, expirationPeriod?: number) => UserInfo[]; }