johanhelsing / matchbox

Painless peer-to-peer WebRTC networking for rust wasm (and native!)
Apache License 2.0
879 stars 72 forks source link

Implement `AsyncWrite` and `AsyncRead` for `WebRtcChannel` #453

Open th4s opened 3 months ago

th4s commented 3 months ago

My understanding is that currently WebRtcChannel supports sync but non-blocking API. It would be cool to have full AsyncRead and AsyncWrite support. It is already possible to take a channel from the socket with WebRtcSocket::take_channel.

What about having a

impl WebRtcChannel {
    pub fn into_async_raw(self) -> impl AsyncRead + AsyncWrite {
        // ...
    }
}

Is something like this possible? The UnboundedSender/UnboundedReceiver already implement Sink/Stream for (PeerId, Box<[u8]>) which could be leveraged for such an implementation.