mediacapture-record icon indicating copy to clipboard operation
mediacapture-record copied to clipboard

Integrate with ReadableStream

Open dontcallmedom opened this issue 9 years ago • 2 comments
trafficstars

From TAG review:

This spec seems like the perfect target to re-use the ReadableStream concept and harmonize/unify the way that conversions are handled. Streams already have a model for how data is extracted/converted from them, which would potentially simplify this spec a lot.

As noted by @domenic in the discussion there:

Completely agreed on ReadableStream. I put up a draft of how that could work at https://domenic.github.io/streaming-mediastreams/ a while ago. @miguelao and I are definitely interested in exploring this, but my understanding is that given Firefox was already shipping this the priority was on just stabilizing that before exploring a "v2" that is properly layered on streams.

(still filing this as an issue, since I'm not sure how much the group has given thoughts to this topic)

dontcallmedom avatar Nov 02 '16 09:11 dontcallmedom

FTR I played with wrapping MediaRecorder as a ReadableStream in Chromium, here's the codepen (spits to console), the secret sauce is the wrapper:

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();
    }
  });
}

yell0wd0g avatar Mar 15 '17 01:03 yell0wd0g

Given that this has shipped in Firefox, I would expect any tighter integration into the API to happen in a v2 spec at this point--but appreciate the thoughts and continued design advancement here. ReadableStream (and WritableStream) are now shipping in the web platform, so this is no longer a theoretical integration, but something that should be done as the API is advanced :-)

travisleithead avatar Aug 29 '17 15:08 travisleithead