Scarlet icon indicating copy to clipboard operation
Scarlet copied to clipboard

onReceive :ReceiveChannel<ApiResponse> never triggers

Open james04gr opened this issue 4 years ago • 3 comments

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

james04gr avatar Oct 18 '20 16:10 james04gr

where you able to fix it

FreedomChuks avatar May 01 '21 07:05 FreedomChuks

where you able to fix it

No...nobody cares for this github project!

james04gr avatar May 04 '21 12:05 james04gr

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
        }
    }
}

msesma avatar May 04 '21 13:05 msesma