Open dontcallmedom opened 8 years ago
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();
}
});
}
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 :-)
From TAG review:
As noted by @domenic in the discussion there:
(still filing this as an issue, since I'm not sure how much the group has given thoughts to this topic)