Open iormark opened 4 years ago
Did you solve the problem?
Unfortunately with this library no.
I found a simple soolution for this problem. It's not very elegant, but it works for now:
private var onReconnected: (() -> Unit)? = null
private var isDisconnected = false
private val stompClient: StompClient by lazy {
Stomp.over(
Stomp.ConnectionProvider.OKHTTP,
"ws://server-base-url/endpoint-name/websocket",
null,
OkHttpProvider.okHttpClient
).apply {
lifecycle().subscribe { event ->
if (event?.type == LifecycleEvent.Type.CLOSED) {
while (!isConnected) {
Thread.sleep(1000)
connect()
}
isDisconnected = true
} else if (event?.type == LifecycleEvent.Type.OPENED) {
if (isDisconnected) {
isDisconnected = false
onReconnected?.invoke()
}
}
}
connect()
}
}
fun startSync() {
onReconnected = { sync() }
sync()
}
private fun sync() {
stompClient
.topic("/topic/endpoint")
.subscribe({/* do something with your data */})
}
Hi, Tell me how to make reconnections, for example, when the server or the Internet is unavailable. For example, similar code that works with okhttp and will not work with StompProtocolAndroid.