I am trying to connect with the SocketIO, but I got this error from the Android side (iOS works):

Here is what I am doing in the Android:
override fun init() = callbackFlow {
val accessToken = tokenStorage.accessToken ?: return@callbackFlow
val option = IO.Options.builder()
.setUpgrade(false)
.setTransports(arrayOf(WebSocket.NAME))
.setExtraHeaders(mapOf("Authorization" to listOf("Bearer ".plus(accessToken)))) // Without this I'll the the Unauthorized 401
.build()
socket = IO.socket(BuildConfig.WS_URL, option)
socket.on(Socket.EVENT_CONNECT) {
trySend(true)
}
socket.on(Socket.EVENT_CONNECT_ERROR) {
Log.d("xxxx", "asSocketPayload error: ${it[0]}")
}
socket.on(DEFAULT_EVENT) {
it[0].asSocketPayload()
}
socket.connect()
awaitClose {
socket.disconnect()
}
}
I am using the socket IO client 2.0.0
Thanks
It seems the client doesn't support adding a header. So I tried using the OkHttpClient instead. It's working like a charm. Here is the short version of it:
Note that: In this case the socket enpoint should use
wss://instead ofhttps://. I'll mark this as an answer to this question. So if you have a solution to use SocketIO client, please let us know below. Thanks!