Re: [webrtc-pc] WHATWG streams for data channel messages (#1732)

Async iteration has landed to the stream specs:
https://streams.spec.whatwg.org/#rs-asynciterator

So it could be possible to write the following code:
```
const dc = pc.createDataChannel(...);
dc.binaryType = 'stream';
// We only need one small buffer per channel
const buffer = new Uint8Array(myPreferredChunkSize);
let view = new DataView(buffer.buffer, 0);

// Note: The function is declared async!
dc.onmessage = async (event) => {
    for await (const chunk of event.data) {
       view = chunk.value; // We reclaim the buffer here
            // ... write the view's data to disk
    }
};`
```

-- 
GitHub Notification of comment by murillo128
Please view or discuss this issue at https://github.com/w3c/webrtc-pc/issues/1732#issuecomment-460949958 using your GitHub account

Received on Wednesday, 6 February 2019 09:09:50 UTC