Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate response from websocket is coming after a channel is unsubscribed and subscribed again #214

Open
rohitiiita007 opened this issue Apr 26, 2022 · 0 comments

Comments

@rohitiiita007
Copy link

rohitiiita007 commented Apr 26, 2022

I have a use case where I unsubscribe a channel and then subscribe again.
But somehow multiple duplicate response is received .
Below are my subscribe & unsubscribe methods
`

fun subscribeChannel() {
     viewModelScope.launchWithException {
            if (socketRepository.isSocketConnected) {
                socketRepository.subscribeChannel(coinName, ChannelNameConstants.CHANNEL_ORDER_BOOK)
            } else {
                val socketFlow = socketRepository.getWebSocketEvents()
                socketFlow.collect {
                    when (it) {
                        is WebSocket.Event.OnConnectionOpened<*> -> {
                            socketRepository.isSocketConnected = true
                            socketRepository.subscribeChannel(coinName, ChannelNameConstants.CHANNEL_ORDER_BOOK)
                        }
                        is WebSocket.Event.OnConnectionClosed,
                        is WebSocket.Event.OnConnectionFailed -> {
                            socketRepository.isSocketConnected = false
                        }
                    }
                }
            }
        }
}
    fun unsubscribeChannel(coinName: String, channelName: String) {
    socketService.sendUnsubscribe(
        ChannelData(
            channelName = "$channelName ${SubscriptionType.UNSUBSCRIBE.value}",
            data = coinName
        )
    )
}
`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant