attachMediaStream
What is this?
A tiny browser module for attaching a media stream to a video (or audio) element with some options. It handles the differences between browsers via adapter.js.
Suitable for use with browserify/CommonJS on the client.
If you're not using browserify or you want AMD support use attachmediastream.bundle.js
.
Installing
npm install attachmediastream
How to use it
Makes it easy to attach video streams to video tags.
var getUserMedia = require('getusermedia');
var attachMediaStream = require('attachmediastream');
getUserMedia(function (err, stream) {
if (err) {
console.log('failed');
} else {
console.log('got a stream', stream);
var videoEl = attachMediaStream(stream, document.getElementById('myVideo'));
var generatedVideoEl = attachMediaStream(stream);
var videoEl = attachMediaStream(stream, someEl, {
autoplay: true,
mirror: true,
muted: true,
audio: false
});
}
});
Why?
Browsers used to to this very differently. This is now less true than it used to be.
It's still handy to be able to control mirroring, muting, autoplay in one shot with sane defaults.
License
MIT
Created By
If you like this, follow @HenrikJoreteg on twitter.