Tinder / Scarlet

A Retrofit inspired WebSocket client for Kotlin, Java, and Android
Other
3.23k stars 237 forks source link

onReceive :ReceiveChannel<ApiResponse> never triggers #150

Open james04gr opened 3 years ago

james04gr commented 3 years ago

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

FreedomChuks commented 3 years ago

where you able to fix it

james04gr commented 3 years ago

where you able to fix it

No...nobody cares for this github project!

msesma commented 3 years ago

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