getScreenMedia
What is this?
A tiny browser module that gives us a simple API for getting access to a user's screen. It uses https://github.com/HenrikJoreteg/getUserMedia API.
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 getscreenmedia.bundle.js
. Note that if no module system is detected it will attach a function called getScreenMedia
to window
.
Installing
npm install getscreenmedia
How to use it
With this helper it's clean/simple to get access to a user's camera, mic, etc.
var getScreenMedia = require('getscreenmedia');
getScreenMedia(function (err, stream) {
if (err) {
console.log('failed');
} else {
console.log('got a stream', stream);
}
});
Why?
It's ugly and annoying to check for support without this tool. Node-style (error-first) APIs that are cross-browser, installable with npm and runnable on the client === win!
Error handling
Error handling (denied requests, etc) are handled mostly by the underlying getUserMedia lib. However this adds one more error type:
Because that's a current requirement of Chrome.
See the handling errors section of the getUserMedia lib for details about how errors are handled.
License
MIT
The Firefox sample extension is licensed under MPL 2.0
Created By
If you like this, follow: @HenrikJoreteg on twitter.