getUserMedia
What is this?
A tiny browser module that gives us a simple API for getting access to a user's camera or microphone by wrapping the navigator.getUserMedia
API in modern browsers.
It gives us a cleaner node.js-style, error-first API and cross-browser handling. No browser support checking necessary, lack of support is treated in the same way as when the user rejects the request: the callback gets passed an error as the first argument.
Suitable for use with browserify/CommonJS on the client.
If you're not using browserify or you want AMD support use getusermedia.bundle.js
.
Installing
npm install getusermedia
How to use it
With this helper it's clean/simple to get access to a user's camera, mic, etc.
var getUserMedia = require('getusermedia');
getUserMedia(function (err, stream) {
if (err) {
console.log('failed');
} else {
console.log('got a stream', stream);
}
});
Passing in options is optional. It defaults to {video: true, audio: true}
;
getUserMedia({video: true, audio: false}, function (err, stream) { ... });
Why? Because it's super ugly without this tool
var getUserMedia = navigator.getUserMedia ||
navigator.mozGetUserMedia ||
navigator.webkitGetUserMedia;
if (getUserMedia) {
getUserMedia = getUserMedia.bind(navigator);
}
getUserMedia(
{video: true, audio: true},
function (stream) {
},
function (error) {
}
)
License
MIT
Created By
If you like this, follow: @HenrikJoreteg on twitter.