Client

Client that can communicate with the server. It has Documents and sends changes of the documents in local to the server to synchronize with other replicas in remote.

A single-threaded, Closeable is used as default. Therefore you need to close the client, when the client is no longer needed. If you provide your own dispatcher, it is up to you to decide close is needed or not.

Constructors

Link copied to clipboard
constructor(host: String, options: Client.Options = Options(), unaryClient: OkHttpClient = OkHttpClient(), streamClient: OkHttpClient = unaryClient, dispatcher: CoroutineDispatcher = createSingleThreadDispatcher("Client(${options.key})"), ioDispatcher: CoroutineDispatcher = Dispatchers.IO)

Types

Link copied to clipboard
data class Options(val key: String = UUID.randomUUID().toString(), val apiKey: String? = null, val token: String? = null, val syncLoopDuration: Duration = 50.milliseconds, val reconnectStreamDelay: Duration = 1_000.milliseconds)

User-settable options used when defining Client.

Link copied to clipboard
interface Status

Represents the status of the client.

Link copied to clipboard

SyncMode defines synchronization modes for the PushPullChanges API.

Properties

Link copied to clipboard
Link copied to clipboard
val status: StateFlow<Client.Status>

Functions

Link copied to clipboard

Activates this Client. That is, it registers itself to the server and receives a unique ID from the server. The given ID is used to distinguish different clients.

Link copied to clipboard
fun attachAsync(document: Document, initialPresence: P = emptyMap(), syncMode: Client.SyncMode = SyncMode.Realtime): Deferred<OperationResult>

Attaches the given Document to this Client. It tells the server that this Client will synchronize the given document.

Link copied to clipboard
fun changeSyncMode(document: Document, syncMode: Client.SyncMode)

Changes the sync mode of the document.

Link copied to clipboard
open override fun close()
Link copied to clipboard

Deactivates this Client.

Link copied to clipboard
fun detachAsync(document: Document): Deferred<OperationResult>

Detaches the given document from this Client. It tells the server that this client will no longer synchronize the given Document.

Link copied to clipboard
fun removeAsync(document: Document): Deferred<OperationResult>

Removes the given document.

Link copied to clipboard
Link copied to clipboard
fun syncAsync(document: Document? = null): Deferred<OperationResult>

Pushes local changes of the attached documents to the server and receives changes of the remote replica from the server then apply them to local documents.