Skip to content

Commit 834955a

Browse files
committed
Don't leak RSocket into API
1 parent 1b03b8a commit 834955a

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

core/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ kotlin {
175175
implementation(libs.ktor.client.contentnegotiation)
176176
implementation(libs.ktor.serialization.json)
177177
implementation(libs.kotlinx.io)
178-
api(libs.rsocket.core)
178+
implementation(libs.rsocket.core)
179179
implementation(libs.rsocket.transport.websocket)
180180
implementation(libs.kotlinx.coroutines.core)
181181
implementation(libs.kotlinx.datetime)

core/src/commonMain/kotlin/com/powersync/sync/RSocketSupport.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ internal fun HttpClient.rSocketSyncStream(
9494
}
9595
}
9696

97-
keepAlive = options.keepAlive
97+
keepAlive = options.keepAlive.toRSocket()
9898
}
9999
}
100100

core/src/commonMain/kotlin/com/powersync/sync/SyncOptions.kt

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.powersync.sync
33
import com.powersync.ExperimentalPowerSyncAPI
44
import com.powersync.PowerSyncDatabase
55
import io.rsocket.kotlin.keepalive.KeepAlive
6+
import kotlin.time.Duration
67
import 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

Comments
 (0)