joffrey-bion / krossbow

A Kotlin multiplatform coroutine-based STOMP client over websockets, with built-in conversions.
MIT License
203 stars 15 forks source link

Auto-discovery of websocket implementation dependencies #252

Open joffrey-bion opened 2 years ago

joffrey-bion commented 2 years ago

We could provide a StompClient() factory function without WebSocketClient argument, which would discover an implementation automatically the same way ServiceLoader does on the JVM.

Ktor's HttpClient() factory function uses a ServiceLoader on JVM, and some interesting eager-initialization shenanigans to register implementations in a list and get a similar effect on Kotlin/Native. On JS, they only have one implementation. Maybe we could pull off something similar on JS too nonetheless (however, see issue KT-51626 and its workaround)

For reference, here is my issue on the Kotlin YouTrack for adding a multiplatform equivalent to the JVM's ServiceLoader: https://youtrack.jetbrains.com/issue/KT-53056/Multiplatform-equivalent-of-JVMs-ServiceLoader

joffrey-bion commented 2 months ago

A possible approach would be to use https://github.com/whyoleg/sweet-spi. This library wraps all the hacks in a neat API, which is exactly what we would need.