I’m trying to terminate a DataChannel SCTP stream in my server application, but finding that the DataConsumer chooses the wrong SCTP Stream ID regardless of what the application needs.
This happens not in the mediasoup worker but in the language bindings. For example in Node is here: node/src/Transport.ts. Turns out that getNextSctpStreamId() unconditionally chooses the first available Stream ID, and then keeps counting up from there.
Problem is that we’d ideally want that a SCTP DataProducer/DataConsumer pair have the same SCTP Stream ID. And these should be application-provided, to comply with rules about using odd or even numbers depending on the DTLS Role.
What I’m doing here is:
webRtcTransport.produceData()
, with application-providedstreamId == 1
(consumed on a Direct DataConsumer).webRtcTransport.consumeData()
, (consuming from a Direct DataProducer) gets an auto-assignedstreamId == 0
.
So inbound and outbound Stream IDs don’t coincide.
It is the DataConsumer’s streamId that gets signaled to the remote peer (a 3rd-party binary module), so this peer starts sending SCTP on streamId == 0
. Because our DataProducer is listening on streamId == 1
, this log happens in mediasoup worker:
no suitable DataProducer for received SCTP message [streamId:0]
However everything works fine if the correct streamId is forced into the DataConsumer.
I tested this by editing the language bindings and allowing a new optional streamId
parameter to DataConsumerOptions
:
type DataConsumerOptions = {
dataProducerId: string;
streamId?: number; // <-- Allow specifying optional Stream ID.
ordered?: boolean;
maxPacketLifeTime?: number;
maxRetransmits?: number;
appData?: DataConsumerAppData;
};
const dataConsumer = await webRtcTransport.consumeData({
dataProducerId: "...",
streamId: 1,
});
Then data is sent and received on the correct SCTP Stream ID.
What do you think? Would this addition to DataConsumerOptions
be a reasonable change to mediasoup?