wngr / async-datachannel

Async Wrapper for datachannel-rs
Apache License 2.0
9 stars 4 forks source link

Cannot create multiple DataStreams from one PeerConnection #4

Open eras opened 1 year ago

eras commented 1 year ago

It seems the interface is designed so that it is impossible to create multiple DataStreams for one PeerConnection. Line 240 of lib.rs says:

    pub async fn dial(self, label: &str) -> anyhow::Result<DataStream> {

taking self in, disallowing it to be called multiple times. In datachannel-rs there is no such limitation, as can be seen from line 355 of peerconnection.rs:

    pub fn create_data_channel_ex<C>(
        &mut self,
        label: &str,
        dc_handler: C,
        dc_init: &DataChannelInit,
    ) -> Result<Box<RtcDataChannel<C>>>

The documentation for libdatachannel doesn't outright say that there can be multiple DataChannels, but it does say that rtcCreateDataChannel adds a datachannel to a Peer Connection and in general this is possible.

It can be useful to have e.g. one unordered and unreliable DataChannel paired with an ordered an reliable DataChannel.

~It seems some internal changes are needed to make this happen, peer_con: Arc<Mutex<Box<RtcPeerConnection<ConnInternal>>>> in PeerConnection probably needs to be an Arc as well, for one.~ I guess I misread it :).

eras commented 1 year ago

Turns out the native interface change was trivial, though I did only try the normal use case ;-). However, the Wasm version needs more work :/.