SyncClient
enables interacting with managed documents - MeshDocument
and synchronizing local changes with all remote clients.
SyncClient
in your code:
SyncClient
SyncClient
class is responsible for coordinating document synchronization through a RoomClient
. It automatically listens for local changes on MeshDocument
instances and forwards them to the remote server, while also applying remote changes as they are received.
room: RoomClient
RoomClient
, which handles the underlying communication with the server.create(path, json?)
path
– The path where the document will be created on the server.schema
– A MeshSchema
describing the structure of the document.json
– (Optional) Initial data or metadata to send along with the creation request.MeshDocument
at the given path with a specified schema.open(path, create = true)
path
– The path identifying the document to open.create
– (Optional) Whether to create the document if it doesn’t exist. Defaults to true
.MeshDocument
instance tied to the specified path.MeshDocument
that automatically sends local changes to the backend.close(path)
path
– The path of the document to close.sync(path, data)
path
– The path of the document to synchronize.data
– A Uint8Array
(or equivalent) containing serialized changes.MeshDocument
are automatically queued for sending, thanks to sendChangesToBackend
. You rarely need to call sync()
manually unless you want to send raw data yourself.
SyncClient
internally tracks how many times a document is opened via the same path. Calling open
multiple times for the same path returns the same underlying document. Only when all references are closed (via close()
) will the client actually disconnect.
RoomClient
may throw an error (like RoomServerException
). Wrap calls in try/catch
(or use .catch(...)
) to handle them gracefully.
RoomClient
and server are configured for concurrent operations.SyncClient
uses a StreamController
internally to manage queued updates, sending them asynchronously to the server.SyncClient
for specialized document operations—such as partial updates, conflict resolution logic, or customized schema handling—by adding new methods or composing it with other classes that also use RoomClient
.