1 | # getScreenMedia
|
2 |
|
3 | ## What is this?
|
4 |
|
5 | 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's API.
|
6 |
|
7 | 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.
|
8 |
|
9 | Suitable for use with browserify/CommonJS on the client.
|
10 |
|
11 | 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`.
|
12 |
|
13 |
|
14 | ## Installing
|
15 |
|
16 | ```
|
17 | npm install getscreenmedia
|
18 | ```
|
19 |
|
20 | ## How to use it
|
21 |
|
22 |
|
23 | With this helper it's clean/simple to get access to a user's camera, mic, etc.
|
24 |
|
25 | ```js
|
26 | var getScreenMedia = require('getscreenmedia');
|
27 |
|
28 | getScreenMedia(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 |
|
43 | 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!
|
44 |
|
45 | ## Error handling
|
46 |
|
47 | Error 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 |
|
51 | Because that's a current requirement of Chrome, the only browser that currently supports screensharing.
|
52 |
|
53 | See 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 |
|
58 | MIT
|
59 |
|
60 | ## Created By
|
61 |
|
62 | If you like this, follow: [@HenrikJoreteg](http://twitter.com/henrikjoreteg) on twitter.
|
63 |
|