Skip to content

minimizing signaling round trips required to set up connections #164

@saurik

Description

@saurik

Hello! I've recently begun looking at mediasoup in some level of earnestness, and one of the things I've noticed is that setting up a connection--let's say a consumer--involves a number of round-trips to the server, which causes quite a bit of delay in receiving the video feed.

The steps in one random nicely-simple demo that I found (a weird one, though, which carries some "state" on the server) seems to be the following four requests (still for the consumer), which "adds up" and causes a noticeable delay when clicking the "subscribe" button.

  1. nothing to the server to create a transport and receive ice/dtls information
  2. rtp capabilities to the server to create the consumer and receive rtp parameters
  3. dtls parameters to the server in order to finalize and establish the connection
  4. nothing to the server to request that the remote consumer resume receiving

FWIW, I feel like the first two of these being separate steps might just be the random demo I found being "naive", but the API surface of mediasoup-client seems to really want that third step to be separate: it doesn't give you the dtls parameters until after you give it the rtp parameters.

Only, that's not a requirement of the WebRTC API: it is totally possible to get the fingerprints required for DTLS before having an offer in hand. (FWIW, Firefox doesn't support RTCCertificate.getFingerprints, but "worst case" you can create a dummy peer connection and parse its offer.)

I've thereby put together a "proof of concept" in the form of a fork of that random demo I found with a commit on a branch to show how to get the interaction with the server down to a single signaling round-trip for the consumer: saurik/mediasoup-sample-app@roundtrips

The one problem I ran into with this proof-of-concept in the existing mediasoup-client is that it takes the "additionalSettings" parameter and "sanitizes" it through utils.clone, which prevents me from smuggling an RTCCertificate object through the certificates array. The hack for that in Transport.ts:

// Clone and sanitize additionalSettings.
//additionalSettings = utils.clone(additionalSettings, {});
additionalSettings = additionalSettings || {};

Is better supporting this architecture something you'd consider for mediasoup{,-client}? For the consumer, arguably the minimum required would involve providing some way to pass through un-sanitized arguments to the RTCPeerConnection (so I could do it like this proof of concept).

But for the producer, I believe a different API is required, even though it is way more obvious why the producer should only need a single round trip :(... the client should be able to send the dtls fingerprint and rtp parameters at the same time, but it doesn't have a way to get the rtp parameters until after you have the remote ice candidates, which clearly isn't something the client actually needs to calculate those: it should only need the server's rtp capabilities. To fix this would seem to require a more different API of some kind (I haven't bothered to put any thought into what I'd personally do for this yet, as I'm kind of hoping that seeing that this is possible is "inspiring" enough ;P).

(If you need me to prove I can make this kind of flow work in Firefox without .getFingerprints()--potentially with deeper changes to the setup of the RTCPeerConnection, as I'd probably prefer to avoid creating a temporary RTCPeerConnection just to pull the fingerprints--I'd be happy to do that.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions