webrtc-nv-use-cases icon indicating copy to clipboard operation
webrtc-nv-use-cases copied to clipboard

WHATWG streams for data channel messages

Open aboba opened this issue 6 years ago • 7 comments

Copied from: https://github.com/w3c/webrtc-pc/issues/1732

Posted by Lennart Grahl (lgrahl) on January 11, 2018:

There is a long standing issue with large data channel messages in the existing API of RTCDataChannel. If I want to send a single message containing 1 GiB of data (for example a large file), I have to have this gigantic message in memory at the time of sending. If I receive a 1 GiB message, this message is slowly being reassembled until it's in memory and then handed out to the application. That creates backpressure and the like.

My idea is to resolve this by extending the RTCDataChannel API in the following way:

Sending

Add a .createWritableStream method which returns a WritableStream instance. With the associated WritableStreamWriter instance, one can add chunks by calling .write on the writer. Once the writer is closed, the message is considered complete.

Receiving

If .binaryType is set to stream, the event raised for onmessage contains a ReadableStream instance that is being created when the first chunk is being received. Once the whole message has been read, the reader will return EOF on a .read call (as specified by the streams API).

Edit: What should happen when a string is being received will need to be discussed.


In the meeting, I think there was a slight confusion about what streaming API I meant. Basically, I propose two streaming APIs that use WHATWG streams:

  • WHATWG streams for the QuicStream API is being discussed here: https://github.com/w3c/webrtc-quic/issues/2
  • WHATWG streams for the existing RTCDataChannel API. This is what this issue is for. And with the above description it should be clear that for RTCDataChannel there would have to be a stream for each message as data channels transfer datagrams and not a sequence of bytes. This is the point I wanted to make during the meeting. I hope this clarifies it a bit. :)

aboba avatar Aug 13 '19 21:08 aboba

Note: WebsocketStreams API has been proposed: https://docs.google.com/document/d/1La1ehXw76HP6n1uUeks-WJGFgAnpX2tCjKts7QFJ57Y/

aboba avatar Aug 27 '19 21:08 aboba

@lgrahl Are there any requirements that need to be added beyond what is already covered here? https://w3c.github.io/webrtc-nv-use-cases/#filesharing*

aboba avatar Aug 27 '19 22:08 aboba

Closing this issue since it already seems to be incorporated in existing use cases.

aboba avatar Aug 27 '19 22:08 aboba

@lgrahl Are there any requirements that need to be added beyond what is already covered here? https://w3c.github.io/webrtc-nv-use-cases/#filesharing*

Yeah, that should do.

lgrahl avatar Aug 29 '19 08:08 lgrahl

We seem to have lost any open issue for actually delivering the extension spec (which was fairly strongly outlined in the webrtc-pc bug). Where should we track that?

alvestrand avatar Sep 17 '19 00:09 alvestrand

@alvestrand Re-opening as a tracking issue for the extension spec.

aboba avatar Sep 17 '19 03:09 aboba

Just want to point out: support for streams over DataChannels would make it very easy to make a compressed DataChannel, by adding a CompressionStream and DecompressionStream at either end.

AshleyScirra avatar Feb 28 '20 13:02 AshleyScirra