Skip to content

Commit 848d79c

Browse files
committed
Kotlin: Document websocket transport mode
1 parent 116ae4d commit 848d79c

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

client-sdk-references/kotlin-multiplatform.mdx

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,56 @@ Logger.e("Some error");
339339

340340
See [Usage Examples](/client-sdk-references/kotlin-multiplatform/usage-examples) for further examples of the SDK.
341341

342+
## Developer Notes
343+
344+
### Client implementation
345+
346+
The PowerSync service sends encoded instructions about data to sync to connected clients.
347+
These instructions are decoded by our SDKs, and on Kotlin there are two implementations available for this:
348+
349+
1. **Kotlin (default)**
350+
- This is the original implementation method, mostly implemented in Kotlin.
351+
- Most upcoming features will not be ported to this implementation, and we intend to remove it eventually.
352+
2. **Rust (currently experimental)**
353+
- This is a newer implementation, mostly implemented in Rust but still using Kotlin for networking.
354+
- Apart from newer features, this implementation is also more performant.
355+
- We [encourage interested users to try it out](https://releases.powersync.com/announcements/improved-sync-performance-in-our-client-sdks)
356+
and report feedback, as we intend to make it the default after a stabilization period.
357+
358+
To enable the Rust client, pass `SyncOptions(newClientImplementation = true)` as a second parameter when
359+
[connecting](https://powersync-ja.github.io/powersync-kotlin/core/com.powersync/-power-sync-database/connect.html).
360+
361+
### Connection Methods
362+
363+
This SDK supports two methods for streaming sync commands:
364+
365+
1. **WebSocket (currently experimental)**
366+
- The implementation leverages RSocket for handling reactive socket streams.
367+
- Back-pressure is effectively managed through client-controlled command requests.
368+
- Sync commands are transmitted efficiently as BSON (binary) documents.
369+
- Enabling websocket support requires the new client implementation.
370+
2. **HTTP Streaming (default)**
371+
- This is the original implementation method.
372+
- This method sends data as text (JSON) instead of BSON.
373+
374+
By default, the `PowerSyncDatabase.connect()` method uses HTTP streams.
375+
You can optionally specify the `connectionMethod` to override this:
376+
377+
```Kotlin
378+
// HTTP streaming (default)
379+
powerSync.connect(connector)
380+
381+
// WebSockets (experimental)
382+
powerSync.connect(connector, SyncOptions(
383+
newClientImplementation = true,
384+
method = ConnectionMethod.WebSocket(),
385+
))
386+
```
387+
342388
## ORM Support
343389

344-
ORM support is not yet available, we are still investigating options. Please [let us know](/resources/contact-us) what your needs around ORMs are.
390+
ORM support is not yet available, we are still investigating options to integrate the SDK with Room and SQLDelight.
391+
Please [let us know](/resources/contact-us) what your needs around ORMs are.
345392

346393
## Troubleshooting
347394

0 commit comments

Comments
 (0)