Rabtman / WsManager

OkHttp WebSocket Manager for Android
416 stars 86 forks source link

WSManager does not reconnect after connectivity change. #11

Open rahatshahzeb opened 5 years ago

Dodger92 commented 4 years ago

I solved this issue by tracking connection changes using the ConnectivityManager and manually reconnecting the socket

val networkCallback: ConnectivityManager.NetworkCallback =
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                object : ConnectivityManager.NetworkCallback() {
                    override fun onAvailable(network: Network) {
                          wsManager?.startConnect()
                    }
                    override fun onLost(network: Network) {
                        wsManager?.stopConnect()
                    }
                }
            }