UNPKG

2 kBMarkdownView Raw
1# getScreenMedia
2
3## What is this?
4
5A tiny browser module that gives us a simple API for getting access to a user's screen. It uses https://github.com/HenrikJoreteg/getUserMedia's API.
6
7It 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.
8
9Suitable for use with browserify/CommonJS on the client.
10
11If 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`.
12
13
14## Installing
15
16```
17npm install getscreenmedia
18```
19
20## How to use it
21
22
23With this helper it's clean/simple to get access to a user's camera, mic, etc.
24
25```js
26var getScreenMedia = require('getscreenmedia');
27
28getScreenMedia(function (err, stream) {
29 // if the browser doesn't support user media
30 // or the user says "no" the error gets passed
31 // as the first argument.
32 if (err) {
33 console.log('failed');
34 } else {
35 console.log('got a stream', stream);
36 }
37});
38```
39
40
41## Why?
42
43It'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!
44
45## Error handling
46
47Error handling (denied requests, etc) are handled mostly by the underlying [getUserMedia lib](https://github.com/HenrikJoreteg/getUserMedia). However this adds one more error type:
48
49- `"HTTPS_REQUIRED"`
50
51Because that's a current requirement of Chrome, the only browser that currently supports screensharing.
52
53See the [handling errors section of the getUserMedia lib](https://github.com/HenrikJoreteg/getUserMedia#handling-errors-summary) for details about how errors are handled.
54
55
56## License
57
58MIT
59
60## Created By
61
62If you like this, follow: [@HenrikJoreteg](http://twitter.com/henrikjoreteg) on twitter.
63