Skip to content

Commit 8656897

Browse files
committed
Don't use WebSockets on watchOS
1 parent 7e758fa commit 8656897

File tree

5 files changed

+23
-3
lines changed

5 files changed

+23
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.11.2 (unreleased)
4+
5+
- Don't attempt to create WebSocket connections on watchOS.
6+
37
## 1.11.1
48

59
- Fix RSocket connection bugs on iOS (and other platforms using the RSocket sync transport):
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.powersync.internal
2+
3+
internal actual fun platformAllowsWebSockets(): Boolean = true

common/src/commonMain/kotlin/com/powersync/internal/PlatformSpecificQuirks.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,15 @@ import kotlin.concurrent.atomics.ExperimentalAtomicApi
2020
public val httpClientIsKnownToNotSupportBackpressure: AtomicReference<((HttpClientEngineConfig) -> Boolean)?> = AtomicReference(null)
2121

2222
@OptIn(ExperimentalAtomicApi::class, InternalPowerSyncAPI::class)
23-
internal val HttpClientEngineConfig.isKnownToNotSupportBackpressure: Boolean
23+
internal val HttpClientEngineConfig.shouldUseRSocketStream: Boolean
2424
get() {
25+
if (!platformAllowsWebSockets()) {
26+
// We can only use regular HTTP on watchOS, so avoid falling back to RSocket streams there.
27+
return false
28+
}
29+
2530
val check = httpClientIsKnownToNotSupportBackpressure.load() ?: return false
2631
return check(this)
2732
}
33+
34+
internal expect fun platformAllowsWebSockets(): Boolean

common/src/commonMain/kotlin/com/powersync/sync/ConfigureSyncHttpClient.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.powersync.sync
22

33
import com.powersync.ExperimentalPowerSyncAPI
4-
import com.powersync.internal.isKnownToNotSupportBackpressure
4+
import com.powersync.internal.shouldUseRSocketStream
55
import com.powersync.sync.StreamingSyncClient.Companion.SOCKET_TIMEOUT
66
import io.ktor.client.HttpClient
77
import io.ktor.client.HttpClientConfig
@@ -71,7 +71,7 @@ internal object WebSocketIfNecessaryPlugin : HttpClientPlugin<Unit, WebSockets>
7171
plugin: WebSockets,
7272
scope: HttpClient,
7373
) {
74-
if (scope.engineConfig.isKnownToNotSupportBackpressure) {
74+
if (scope.engineConfig.shouldUseRSocketStream) {
7575
WebSockets.install(plugin, scope)
7676
scope.attributes.put(needsRSocketKey, true)
7777
} else {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.powersync.internal
2+
3+
import kotlin.experimental.ExperimentalNativeApi
4+
5+
@OptIn(ExperimentalNativeApi::class)
6+
internal actual fun platformAllowsWebSockets(): Boolean = Platform.osFamily != OsFamily.WATCHOS

0 commit comments

Comments
 (0)