PdfSyncSession class

A transport-agnostic collaborative editing session over one document's annotations, built on the snapshot + diff primitives (pdfDiffAnnotations, PdfAnnotationSnapshot, PdfAnnotationSyncEditing.upsertAnnotation).

The session owns a mutable byte buffer and the live document reopened from it. A local apply runs an editor optimistically, diffs the result, and broadcasts each change through the injected transport; incoming remote changes are merged with last-writer-wins keyed on /NM, ordered by the message's (clock, origin). Because that order is total and every session evaluates it identically, sessions sharing a transport converge to the same annotation set regardless of delivery order - conflicting edits to the same /NM resolve to the same winner everywhere.

Seed every collaborator from the same bytes (run PdfAnnotationEditing.nameAnnotations once on the source so every annotation has a durable /NM before sharing) - independently minted names would never reconcile.

Anonymous annotations (no /NM) cannot be id-merged: they ride along as create/remove but are skipped by the LWW table.

Constructors

PdfSyncSession({required Uint8List bytes, required PdfSyncTransport transport, String password = ''})

Properties

bytes Uint8List
The current document bytes - what "save to disk" would write.
no setter
changes Stream<List<PdfAnnotationChange>>
Every annotation change this session applies - both local edits and accepted remote merges - so a host can refresh its UI. Local edits are also broadcast to peers; remote merges are not re-broadcast (no echo).
no setter
document PdfDocument
The live document for the current state.
no setter
hashCode int
The hash code for this object.
no setterinherited
id String
This session's id (its transport endpoint's).
no setter
peers Set<String>
The session ids currently connected (from the transport's presence).
no setter
presence Stream<Set<String>>
Presence updates from the transport: the connected session ids whenever a peer joins or leaves.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
transport PdfSyncTransport
The transport this session sends through and listens on.
final

Methods

annotationBaseline() List<PdfAnnotationChange>
The whole current annotation state as created-changes - what a new peer asks an existing session for to catch up (or what seeds a store). Mirrors PdfEditingController.annotationBaseline.
annotationDigest() Map<String, Object?>
A canonical fingerprint of the current annotation state: /NM → snapshot JSON for every captureable named annotation. Two converged sessions have equal digests - handy for tests and for detecting drift.
apply(void edit(PdfEditor editor), {Iterable<int>? pages}) List<PdfAnnotationChange>
Runs edit against the current document, commits it as the new state, broadcasts the resulting changes, and returns them. pages limits the diff to the touched page indices (null/empty diffs every page - pass it for speed on large documents). No-op edits return an empty list and send nothing.
dispose() Future<void>
Stops listening and releases the change stream. Does not close the transport - the host owns its lifecycle.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited