package
Create a MediaSource from a Readable stream
npm install media-source-streamGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Creates MSE MediaSource objects from readable streams.
Does the reverse of media-recorder-stream.
npm install media-source-streamThe easiest way to get a compatible readable stream is to use media-recorder-stream, but you can also create your own via FFMPEG.
var getMedia = require('getusermedia')
var MediaRecorderStream = require('media-recorder-stream')
var MediaSourceStream = require('media-source-stream')
getMedia({video: true, audio: true}, function (err, media) {
// Change a MediaStream into a data stream
var recordStream = MediaRecorderStream(media, {
mimeType: 'video/webm; codecs="opus,vp8"', // You MUST set the MIME type
interval: 100 // A short interval is recommended to keep buffer sizes low
})
// Do stuff to the data...
// And change it back!
var sourceStream
net.socket.sourceStream = new MediaSourceStream([opts])Create a new MediaSourceStream, which is a writable stream.
Optional opts is the options object to pass to the MediaSource constructor.
sourceStream.mediaSourceThe output MediaSource object.
Here is an example of how to send video/audio over a WebRTC DataChannel (with simple-peer), without using media channels. You could also do this over WebSockets.
Keep in mind there is a moderate increase in latency, so this is only suitable when MediaStreams aren't an option.
getMedia({video: true, audio: true}, function (err, stream) {
var recordStream = MediaRecorderStream(stream, {
mimeType: 'video/webm; codecs=vp8',
interval: 100
})
var peer1 = new SimplePeer({
initiator: true
})
var peer2 = new SimplePeer()
peer1.on('signal', function (data) {
peer2.signal(data)
})
peer2.on('signal', function (data) {
peer1.signal(data)
Note: You want to start recording once you already have a connection so that all recorded data is sent. If any initial data is missing, the stream cannot be reconstructed on the other side.