Re: [mediacapture-record] Integrate with ReadableStream

FTR I played with wrapping MediaRecorder as a `ReadableStream` in Chromium, here's the [codepen](https://codepen.io/miguelao/pen/OpprWN) (spits to console), the secret sauce is the wrapper:

```javascript
function makeMediaRecorderStream(mediaStream) {
   // Constructor throws.
  recorder = new MediaRecorder(mediaStream);

  return new ReadableStream({
    // Not implemented yet in Chrome.
    // type: "bytes",

    start(controller) {
      // Backpressure is not supported: if the client loses a single event.data,
      // the reconstructed recorded array of Blobs might not be playable.
      recorder.ondataavailable = (event) => { controller.enqueue(event.data); };
      recorder.onstop = () => controller.close();
      recorder.onerror = () => controller.error(new Error("The MediaRecorder errored!"));
      // We have also onstart, onpause and onresume events.
      recorder.start(100);
    },

    cancel() {
      if (recorder.state != 'inactive')
        recorder.stop();
    }
  });
}
```


-- 
GitHub Notification of comment by miguelao
Please view or discuss this issue at https://github.com/w3c/mediacapture-record/issues/87#issuecomment-286616726 using your GitHub account

Received on Wednesday, 15 March 2017 01:49:30 UTC