Producer connection state stuck to "checking"

I am using the mediasoup-client-android with socket.io. Here is my sendTransportListener :

val listener = object: SendTransport.Listener
 {
            override fun onConnect(transport: Transport?, dtlsParameters: String?)
            {
                val params = JSONObject()
                params.put("method", "connectWebRtcTransport")

                val data = JSONObject()
                data.put("transportId", sendTransport.id)
                data.put("dtlsParameters", dtlsParameters)

                params.put("data", data)

                socket.send("request", params)
            }

            override fun onProduce(transport: Transport?, kind: String?, rtpParameters: String?, appData: String?): String
            {
                val params = JSONObject()
                params.put("method", "produce")

                val data = JSONObject()
                data.put("transportId", sendTransport.id)
                data.put("kind", kind)
                data.put("rtpParameters", JSONObject(rtpParameters))
                data.put("appData", appData)

                params.put("data", data)

                val latch = CountDownLatch(1)

                socket.emit("request", params, Ack { args ->

                    val idObj = args.firstOrNull { arg -> arg is JSONObject } as JSONObject
                    sendTransportRemoteId = idObj.getString("id")

                    latch.countDown()
                })

                latch.await()

                Log.i("Socket", "Returning = $sendTransportRemoteId // Thread = ${Thread.currentThread().name} // State = ${transport?.connectionState}")

                return sendTransportRemoteId
            }

            override fun onConnectionStateChange(transport: Transport?, connectionState: String?) {
                Log.i("Socket", "Send Transport : ${transport.toString()}, connectionState : $connectionState")
            }
        }

Does “latch.countDown” run?

Yes, the log shows the correct producerId is returned.

I’m assuming the checking state is the SendTransport not the producer.
Does it not change to failed after a while?
Does anything interesting popup on the server side with mediasoup debug logs enabled?
Have you set up the webrtc transport listen Ips on the server side to the correct ip?

  • You are correct, it is the SendTransport that is stuck in “checking” state.

  • It does switch to “failed” after a while, although not in a predictable way.

  • The logs are the same when I successfully connect with my browser implementation.

  • No problem when connecting from browser, including mobile browser, so I would assume everything is properly set server wise.

Unrelated issue but it might help in resolving : I am also unable to consume anything as I never get the “newConsumer” events. It is odd since I do receive other events such as “newPeer” or “activeSpeaker”…

override fun onConnect(transport: Transport?, dtlsParameters: String?)

dtlsParameters are not a String in libmeidasoupclient

On the other hand, you may need to trace the network traffic (tcpdump, wireshark, or alike) and check that the ICE binding requests are being sent to mediasoup and replied back.