Scarlet
Scarlet copied to clipboard
onReceive :ReceiveChannel<ApiResponse> never triggers
I have created my Socket Interface with the @Receive observeEvents and @Send sendMessage and also the @Receive observeApiMessage methods. I can observe the events when they happen however the observeApiMessage never gets triggered.
interface FlowSocketApi {
@Receive
fun observeEvents(): ReceiveChannel<WebSocket.Event>
@Send
fun send(message: Any): Boolean
@Receive
fun observeApiMessage(): ReceiveChannel<FlowSocketResponse>
}
I have a FlowSocket that implements the FlowSocketApi interface and inside my repository i call this.
flowSocketService.observeApiMessage().consumeAsFlow().asLiveData().observeForever {
it?.let {
println("flowMessagesObserver result")
println(it.body)
} ?: run {
println("flowMessagesObserver null")
}
}
I never see that print logs
where you able to fix it
where you able to fix it
No...nobody cares for this github project!
This my working code
websocketJob = scope.launch(dispatchers.io) {
for (event in eventChannel) {
Timber.d("$event")
when (event) {
is WebSocket.Event.OnConnectionOpened<*> -> receiveMessages()
is WebSocket.Event.OnConnectionFailed -> onConnectionFailed(event.throwable)
is WebSocket.Event.OnConnectionClosed -> onConnectionDropped(event.shutdownReason)
is WebSocket.Event.OnConnectionClosing -> onConnectionClosing(event.shutdownReason)
is WebSocket.Event.OnMessageReceived -> Unit
}
}
}
private fun receiveMessages() {
messagesJob = scope.launch(dispatchers.io) {
for (message in myService.observeMessage()) {
logger.logMessageReceived(message)
when (message) {
.......
}.exhaustive
}
}
}