1 | # Environment Detector
|
2 |
|
3 | ## Installation
|
4 |
|
5 | ### NPM version
|
6 |
|
7 | **Highlight:** flash detection removed from version 2.0
|
8 |
|
9 | $ npm i --save @realeyes/environment-detector
|
10 |
|
11 | If you need to detect flash then you should use previous 1.x versions of Environment Detector for example install the latest 1.x
|
12 |
|
13 | $ npm i --save @realeyes/environment-detector@1.8.6
|
14 |
|
15 | ### CDN version
|
16 |
|
17 | The general format for the script URL is `"https://codesdwncdn.realeyesit.com/environment-detector/release/{version}/environment-detector.js"`. You can specify which kinds of updates your app can accept using [semver](https://docs.npmjs.com/getting-started/semantic-versioning) string in a following format:
|
18 | - `x.y` to receive bug fixes only: `https://codesdwncdn.realeyesit.com/environment-detector/release/2.0/environment-detector.min.js`
|
19 | - `x` to receive bug fixes and new features (**recommended**): `https://codesdwncdn.realeyesit.com/environment-detector/release/2/environment-detector.min.js`
|
20 |
|
21 | ```html
|
22 | <script src="https://codesdwncdn.realeyesit.com/environment-detector/release/2/environment-detector.min.js"></script>
|
23 | ```
|
24 |
|
25 | ### Self hosted
|
26 |
|
27 | To create a self-hosted solution you will need to download the library archive [https://codesdwncdn.realeyesit.com/environment-detector/release/2/environment-detector.zip](https://codesdwncdn.realeyesit.com/environment-detector/release/2/environment-detector.zip). The archive contains the following files:
|
28 | - environment-detector.js - Detector library
|
29 | - environment-detector.min.js - Minified version
|
30 | - index.html - Example page
|
31 | - log.gif - Tracking pixel
|
32 |
|
33 | To use to detector you will need environment-detector.js.
|
34 |
|
35 | ```html
|
36 | <script src="https://example.com/environment-detector.js"></script>
|
37 | <script>
|
38 | Realeyesit.EnvironmentDetector.detect()
|
39 | .then(function (result) {
|
40 | // result will be an EnvironmentDetectionResult object
|
41 | });
|
42 | </script>
|
43 | ```
|
44 |
|
45 | ## API
|
46 |
|
47 | The `Realeyesit.EnvironmentDetector` namespace contains one method: `detect()`. This method returns a `Promise` object that resolves with the EnvironmentDetectionResult object.
|
48 | This is the type definition for the EnvironmentDetectionResult:
|
49 |
|
50 | {
|
51 | browser: {
|
52 | name: string,
|
53 | version: string,
|
54 | },
|
55 | platform: {
|
56 | type: string,
|
57 | },
|
58 | os: {
|
59 | name: string,
|
60 | version: string,
|
61 | },
|
62 | webcams: Array.<string>,
|
63 | capabilities: Array.<string>
|
64 | }
|
65 |
|
66 | * **browser.name** is a string like "Chrome" or "Firefox"
|
67 | * **browser.version** is a version string like "53.0"
|
68 | * **platform.type** is one of "tablet", "mobile" or "desktop"
|
69 | * **os.name** is a string like "windows" or "macos"
|
70 | * **os.version** is a version string like "10.11"
|
71 | * **webcams** is an array of strings, for example \["USB Camera", "iSight"\]
|
72 | * **capabilities** is an array of strings
|
73 |
|
74 | Here is the list of capabilities we can detect:
|
75 |
|
76 | {
|
77 | GET_USER_MEDIA: 'navigator.getUserMedia',
|
78 | MEDIA_RECORDER: 'MediaRecorder',
|
79 | WEBCAM: 'webcam',
|
80 | DOCUMENT_ALL: 'document.all',
|
81 | DOCUMENT_QUERY_SELECTOR: 'document.querySelector',
|
82 | HTTP: 'http',
|
83 | HTTPS: 'https',
|
84 | }
|
85 |
|
86 | The `detect()` method can receive an optional `options` object with the following type definition:
|
87 |
|
88 | {
|
89 | logger: {
|
90 | path: string, // url of the tracking pixel
|
91 | disable: boolean, // pass true if you want to disable logging
|
92 | } // logger settings
|
93 | }
|
94 |
|
95 | ## Example usage
|
96 |
|
97 | ```javascript
|
98 | Realeyesit.EnvironmentDetector.detect()
|
99 | .then(function (result) {
|
100 | // result will be an EnvironmentDetectionResult object
|
101 | });
|
102 | ```
|
103 |
|
104 |
|
105 | ## License
|
106 |
|
107 | Copyright 2018 Realeyes OU.
|
108 |
|
109 | Licensed under the Apache License, Version 2.0 (the "License");
|
110 | you may not use this file except in compliance with the License.
|
111 | You may obtain a copy of the License at
|
112 |
|
113 | http://www.apache.org/licenses/LICENSE-2.0
|
114 |
|
115 | Unless required by applicable law or agreed to in writing, software
|
116 | distributed under the License is distributed on an "AS IS" BASIS,
|
117 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
118 | See the License for the specific language governing permissions and
|
119 | limitations under the License.
|