@@ -3,6 +3,7 @@ package com.powersync.sync
3
3
import com.powersync.ExperimentalPowerSyncAPI
4
4
import com.powersync.PowerSyncDatabase
5
5
import io.rsocket.kotlin.keepalive.KeepAlive
6
+ import kotlin.time.Duration
6
7
import kotlin.time.Duration.Companion.seconds
7
8
8
9
/* *
@@ -22,6 +23,12 @@ public class SyncOptions
22
23
public val method: ConnectionMethod = ConnectionMethod .Http ,
23
24
) {
24
25
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
+ */
25
32
@OptIn(ExperimentalPowerSyncAPI ::class )
26
33
public val defaults: SyncOptions = SyncOptions ()
27
34
}
@@ -51,14 +58,29 @@ public sealed interface ConnectionMethod {
51
58
*/
52
59
@ExperimentalPowerSyncAPI
53
60
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
+ )
63
85
}
64
86
}
0 commit comments