@@ -3,6 +3,7 @@ package com.powersync.sync
33import com.powersync.ExperimentalPowerSyncAPI
44import com.powersync.PowerSyncDatabase
55import io.rsocket.kotlin.keepalive.KeepAlive
6+ import kotlin.time.Duration
67import kotlin.time.Duration.Companion.seconds
78
89/* *
@@ -22,6 +23,12 @@ public class SyncOptions
2223 public val method: ConnectionMethod = ConnectionMethod .Http ,
2324 ) {
2425 public companion object {
26+ /* *
27+ * The default sync options, which are safe and stable to use.
28+ *
29+ * Constructing non-standard sync options requires an opt-in to experimental PowerSync
30+ * APIs, and those might change in the future.
31+ */
2532 @OptIn(ExperimentalPowerSyncAPI ::class )
2633 public val defaults: SyncOptions = SyncOptions ()
2734 }
@@ -51,14 +58,29 @@ public sealed interface ConnectionMethod {
5158 */
5259 @ExperimentalPowerSyncAPI
5360 public data class WebSocket (
54- val keepAlive : KeepAlive = DefaultKeepAlive ,
55- ) : ConnectionMethod {
56- private companion object {
57- val DefaultKeepAlive =
58- KeepAlive (
59- interval = 20.0 .seconds,
60- maxLifetime = 30.0 .seconds,
61- )
62- }
61+ val keepAlive : RSocketKeepAlive = RSocketKeepAlive .default,
62+ ) : ConnectionMethod
63+ }
64+
65+ /* *
66+ * Keep-alive options for long-running RSocket streams:
67+ *
68+ * The client will ping the server every [interval], and assumes the connection to be closed if it
69+ * hasn't received an acknowledgement in [maxLifetime].
70+ */
71+ @ExperimentalPowerSyncAPI
72+ public data class RSocketKeepAlive (
73+ val interval : Duration ,
74+ val maxLifetime : Duration ,
75+ ) {
76+ internal fun toRSocket (): KeepAlive {
77+ return KeepAlive (interval, maxLifetime)
78+ }
79+
80+ internal companion object {
81+ val default = RSocketKeepAlive (
82+ interval = 20.0 .seconds,
83+ maxLifetime = 30.0 .seconds,
84+ )
6385 }
6486}
0 commit comments