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.

I am also not getting “newConsumer” events. How did you resolve it?

It was a JSON escaping issue, resulting in wrongly formatted rtpCapabilities being sent. After solving that I did receive the newConsumer events.

However, the same problem that I had originally is still there : for either ReceiveTransport or SendTransport, the connectionState will be stuck to checking even though server logs are showing successful transport.connect() requests

@jmillan Can you please elaborate on the network traffic tracing ? What should I be looking for exactly ?

A checking state is indicating that the connection is looking for a usable candiate pair. Look for the ICE candidates you are providing to mediasoup and check if those IP/port make sense.

https://w3c.github.io/webrtc-pc/#dom-rtcicetransportstate-checking

This issue is related to your environment and not to mediasoup libraries.

1 Like

It turns out, the IP in the ICE candidates did NOT make sense after all ! I was able to fix it thanks to you. Thanks x1000000, you just made my week !