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
sealed class DocumentSyncResult

Represents the result of synchronizing the document with the server.

Link copied to clipboard
interface Event

Represents the type of the events that the client can emit. It can be delivered by Client.events.

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

Represents whether the stream connection between the client and the server is connected or not.

Link copied to clipboard

SyncMode defines synchronization modes for the PushPullChanges API.

Properties

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

Functions

Link copied to clipboard
fun activateAsync(): Deferred<Boolean>

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<Boolean>

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
fun deactivateAsync(): Deferred<Boolean>

Deactivates this Client.

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

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<Boolean>

Removes the given document.

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

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.