Multiple client-side WebRtcTransports pointing a single server-side WebRtcTransport

According to Split sender and receiver Transport classes · Issue #686 · versatica/mediasoup · GitHub, mediasoup-client and libmediasoupclient objects are unidirectional just only due to complexities in management of bi-directional SDPs. Not fully sure if due to a misunderstood, but I’ve created with mediasoup-client both a WebRTCSendTransport and a WebRtcRecvTransport, and server side a single WebRtcTransport object.

After that, I registered the connect event in both clients to send their dtlsParameters parameters to the server and there call to connect() method. First one works, but second ones throw an error about Transport already connected. If I don’t register the connect event in the second client-side Transport (the sender one), I get an error about not being registered, so I just register a dumb handler that just call the callback as a sucesfully connection… and seems to work :slight_smile: or at least I can get video flowing in.

I still needs to check if I can send data too, but in any case it seems a bit hacky to me, so I want to ask: does it makes sense what I’m doing? I’ve just reviewed the sent info and seems to me there’s nothing related the Transport is intended to receive or send info (maybe the role field?):

424["transport_connect",{"transportId":"3b652ddc-2103-470a-82cd-95077545baa1","dtlsParameters":{"role":"client","fingerprints":[{"algorithm":"sha-256","value":"11:F7:9D:56:26:24:E8:07:9E:7F:B9:8B:D6:3C:B3:1F:82:7F:42:26:50:82:FE:42:1D:55:A2:3D:FB:44:22:1C"}]}}]

If this is a (hacky) valid use case, shouldn’t connect() method just ignore the second call instead of throwing an error? Should I capture and check it instead, in case there would have been any other error? Maybe detect that I’ve already called it once and don’t try to call it again?

No, it doesn’t. Where do you think the second client transport is connected to? There is a RTCPeerConnection inside, which is P2P by nature, it needs a dedicated peer on the other side.

I know there’s a RTCPeerConnection object inside each mediasoup-client WebRtcTransport, but I’ve already exchanged the rtpCandidates and didn’t find any issue on that, just only with the connect event. Do you mean that since I have two unidirectional RTCPeerConnection objects on client side, I’m forced to create two WebRtcTransports on the server too?

Yes, you do!

1 Like

It’s impossible that DTLS works for both client transports if there is a single transport in server side.

1 Like

Then I misunderstood your words, thanks to clarify @ibc, i’ll rewrite my code then. Is It posible to add some way to prevent that pitfall? Maybe a map on client side of hash of dtls to the WebRtcTransports? Or maybe better (or un addition to It) to add support for bidirectional ones?