W3C home > Mailing lists > Public > public-webrtc-logs@w3.org > February 2019

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

From: Sergio Garcia Murillo via GitHub <sysbot+gh@w3.org>
Date: Wed, 06 Feb 2019 09:09:49 +0000
To: public-webrtc-logs@w3.org
Message-ID: <issue_comment.created-460949958-1549444188-sysbot+gh@w3.org>
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

This archive was generated by hypermail 2.3.1 : Tuesday, 4 June 2019 15:32:54 UTC