I’m having some trouble setting up DataConsumers/DataProducers, here is what i’m trying to have:
I want to be able to send messages to a peer from Rust.
This is what I’ve done:
Created a DataProducer on a DirectTransport, so I can use the send() method.
let data_producer_options = mediasoup::data_producer::DataProducerOptions::new_direct();
let inner_data_producer = self
Then on the peer’s recv transport I created a DataConsumer
let inner_data_consumer = self
.webrtc_transport // The peer's RecV Transport
inner_data_producer_id, // Id of the DataProducer I created earlier
But I’m getting this runtime error when I call the consume_data method:
And I don’t get why it is asking me for some sctpStreamParameters , as the DataProducer was created on a direct transport it doesn’t have sctpStreamParameters? And I can’t use a DataProducer created on a Regular Transport because the DataProducer wouldn’t have a send() method, so I’m a bit confused on what I’m doing wrong here. I thought about creating a DataProducer on a direct transport and trying to consume it on the client but the client need sctpStreamParameters that the DirectDataProducer doesn’t have.
I just checked, while code is different, logic is the same: unless consumer is created on direct transport, implementation clones SCTP stream parameters from producer and does some tweaking to it. SCTP parameters themselves are an optional type, but expected for non-direct transport.
So what happens here is that your consumer transport is not direct, it needs SCTP parameters, but producer is on direct transport and doesn’t have them. I believe it will fail the same exact way in TypeScript too, I was translating logic from TypeScript in Rusty way, but at the same time following mechanics quite literally.
I’m afraid that’s not correct. transport.consumeData() never requires sctpParameters. Those are generated by mediasoup in the returned DataConsumer and they are generated based on sctpParameters of the DataProducer. If the DataProducer is “direct” (it was created on a DirectTransport) the mediasoup generates sctpParameters for the non direct DataConsumer with appropriate values.