@realeyes/environment-checker
Advanced tools
Comparing version 2.3.2 to 3.1.0
module.exports = { | ||
"parser": "babel-eslint", | ||
"root": true, | ||
@@ -6,3 +7,2 @@ "env": { | ||
}, | ||
"extends": "airbnb-base", | ||
"rules": { | ||
@@ -9,0 +9,0 @@ "indent": ["error", 4], |
188
index.js
@@ -9,3 +9,2 @@ /*! | ||
import swfobject from 'swfobject'; | ||
import uuidV4 from 'uuid/v4'; | ||
@@ -15,9 +14,5 @@ import detect from '@realeyes/environment-detector'; | ||
import platform from '@realeyes/environment-detector/lib/platform'; | ||
import capabilities from '@realeyes/environment-detector/lib/capabilities'; | ||
import Logger from '@realeyes/environment-detector/lib/utils/Logger'; | ||
const DEFAULT_FLASH_DETECTOR_PATH = './environment-detector.swf'; | ||
/** | ||
@@ -33,65 +28,2 @@ * @typedef {{ | ||
/** | ||
* Checks if element is present in the array. | ||
* | ||
* @param {Array} arr The array | ||
* @param {*} value The value | ||
* @return {boolean} | ||
*/ | ||
function inArray(arr, value) { | ||
if (typeof Array.prototype.indexOf === 'function') { | ||
return arr.indexOf(value) !== -1; | ||
} | ||
for (let i = 0; i < arr.length; i++) { | ||
if (arr[i] === value) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
/** | ||
* Compares the version strings. | ||
* | ||
* @param {string} v1 First version | ||
* @param {string} v2 Second version | ||
* @return {number} | ||
*/ | ||
function compareVersions(v1, v2) { | ||
const s1 = v1.split('.'); | ||
const s2 = v2.split('.'); | ||
for (let i = 0; i < Math.max(s1.length, s2.length); i++) { | ||
const n1 = parseInt(s1[i] || 0, 10); | ||
const n2 = parseInt(s2[i] || 0, 10); | ||
if (n1 > n2) return 1; | ||
if (n2 > n1) return -1; | ||
} | ||
return 0; | ||
} | ||
/** | ||
* Returns the first match for the regexp. | ||
* | ||
* @param {string} str String | ||
* @param {RegExp} regex Regular expression used for matching | ||
* @return {string} | ||
*/ | ||
function getFirstMatch(str, regex) { | ||
const match = str.match(regex); | ||
if (match && match.length > 1) { | ||
return match[1]; | ||
} | ||
return ''; | ||
} | ||
window.Realeyesit = window.Realeyesit || {}; | ||
@@ -101,10 +33,9 @@ window.Realeyesit.EnvironmentalDetectionAPI = { | ||
BLACKLISTED_FLASH_VERSIONS: ['11.4.31.110'], | ||
MIN_FLASH_VERSION: '10.2.0', | ||
BLACKLISTED_BROWSERS: [ | ||
[browsers.names.INTERNET_EXPLORER, '0-8'], | ||
[browsers.names.FIREFOX, '0-3'], | ||
[browsers.names.OPERA, '0-11'], | ||
[browsers.names.INTERNET_EXPLORER, '0-11'], | ||
[browsers.names.FIREFOX, '0-49'], | ||
[browsers.names.OPERA, '0-46'], | ||
[browsers.names.CHROME, '0-54'], | ||
[browsers.names.MICROSOFT_EDGE, '0-14'], | ||
[browsers.names.SAFARI, '0-10'], | ||
], | ||
@@ -119,5 +50,2 @@ | ||
failureReasonCodes: { | ||
FLASH_NOT_INSTALLED: 1, | ||
FLASH_TOO_OLD: 2, | ||
FLASH_BLACKLISTED: 3, | ||
BROWSER_NOT_CAPABLE: 4, | ||
@@ -127,2 +55,4 @@ MOBILE_BROWSER: 5, | ||
OTHER_ERROR: 7, | ||
IOS_WEBVIEW: 8, | ||
UNSUPPORTED_BROWSER: 9 //Browser is not supported, even not blacklisted for example exotic browsers | ||
}, | ||
@@ -134,8 +64,7 @@ | ||
* @param {function({EnvironmentCheckResult})} callback Callback function | ||
* @param {*} flash Flash detection options | ||
* @param {*} options detection options | ||
* @param {*} logger Logging options | ||
* @return {undefined} | ||
*/ | ||
start(callback, { | ||
flash = { path: DEFAULT_FLASH_DETECTOR_PATH }, | ||
start(callback, options = {}, { | ||
logger = {}, | ||
@@ -149,17 +78,3 @@ } = {}) { | ||
this.checkResults.checksPassed = false; | ||
const ua = navigator.userAgent; | ||
const skip = []; | ||
if ( | ||
(/firefox/i.test(navigator.userAgent) && | ||
compareVersions(getFirstMatch(ua, /(?:firefox)[ /](\d+(\.\d+)?)/i), '31') >= 0) || | ||
(/chrome/i.test(navigator.userAgent) && !/edge/i.test(ua) && | ||
compareVersions(getFirstMatch(ua, /(?:chrome)\/(\d+(\.\d+)?)/i), '38') >= 0) || | ||
(/opera|opr|opios/i.test(navigator.userAgent) && | ||
compareVersions(getFirstMatch(ua, /(?:opera|opr|opios)[\s/](\d+(\.\d+)?)/i), '38') >= 0) | ||
) { | ||
skip.push('flash'); | ||
} | ||
const detectorOptions = { flash, skip, logger: loggerOpts }; | ||
const detectorOptions = { logger: loggerOpts }; | ||
ecLogger.log('environment-checker calling detector', detectorOptions); | ||
@@ -170,27 +85,23 @@ | ||
let flashVersionString = ''; | ||
if (!inArray(skip, 'flash')) { | ||
const flashVersion = swfobject().getFlashPlayerVersion(); | ||
flashVersionString = `${flashVersion.major}.${flashVersion.minor}.${flashVersion.release}`; | ||
} | ||
if (!this.checkBrowser(result)) { | ||
this.checkResults.failureReasonCode = this.failureReasonCodes.BROWSER_NOT_CAPABLE; | ||
this.checkResults.failureReasonString = 'BROWSER_NOT_CAPABLE'; | ||
} else if (result.platform.type === platform.types.MOBILE) { | ||
} else if (result.browser.name === browsers.names.IOS_WEBVIEW) { | ||
this.checkResults.failureReasonCode = this.failureReasonCodes.IOS_WEBVIEW; | ||
this.checkResults.failureReasonString = 'IOS_WEBVIEW'; | ||
} else if (result.platform.type === platform.types.MOBILE | ||
&& options.allowedDevices.indexOf(platform.types.MOBILE) === -1) { | ||
this.checkResults.failureReasonCode = this.failureReasonCodes.MOBILE_BROWSER; | ||
this.checkResults.failureReasonString = 'MOBILE_BROWSER'; | ||
} else if (result.flash === null) { | ||
this.checkResults.failureReasonCode = this.failureReasonCodes.FLASH_NOT_INSTALLED; | ||
this.checkResults.failureReasonString = 'FLASH_NOT_INSTALLED'; | ||
} else if (compareVersions(flashVersionString, this.MIN_FLASH_VERSION) === -1) { | ||
this.checkResults.failureReasonCode = this.failureReasonCodes.FLASH_TOO_OLD; | ||
this.checkResults.failureReasonString = 'FLASH_TOO_OLD'; | ||
} else if (this.BLACKLISTED_FLASH_VERSIONS.indexOf(result.flash.version) !== -1) { | ||
this.checkResults.failureReasonCode = this.failureReasonCodes.FLASH_BLACKLISTED; | ||
this.checkResults.failureReasonString = 'FLASH_BLACKLISTED'; | ||
} else if (result.flash.webcams.length === 0) { | ||
} else if (result.platform.type === platform.types.TABLET | ||
&& options.allowedDevices.indexOf(platform.types.TABLET) === -1) { | ||
this.checkResults.failureReasonCode = this.failureReasonCodes.MOBILE_BROWSER; | ||
this.checkResults.failureReasonString = 'MOBILE_BROWSER'; | ||
} else if (result.webcams.length === 0) { | ||
this.checkResults.failureReasonCode = this.failureReasonCodes.NO_WEBCAMS_DETECTED; | ||
this.checkResults.failureReasonString = 'NO_WEBCAMS_DETECTED'; | ||
} else if (this.unsupportedBrowser(result)) { | ||
this.checkResults.failureReasonCode = this.failureReasonCodes.UNSUPPORTED_BROWSER; | ||
this.checkResults.failureReasonString = 'UNSUPPORTED_BROWSER'; | ||
this.checkResults.checksPassed = true; | ||
} else { | ||
@@ -200,14 +111,2 @@ this.checkResults.checksPassed = true; | ||
if (result && this.checkResults.failureReasonCode === this.failureReasonCodes.FLASH_NOT_INSTALLED && | ||
inArray(skip, 'flash')) { | ||
if (result.webcams.length > 0) { | ||
this.checkResults.checksPassed = true; | ||
this.checkResults.failureReasonCode = null; | ||
this.checkResults.failureReasonString = null; | ||
} else { | ||
this.checkResults.failureReasonCode = this.failureReasonCodes.NO_WEBCAMS_DETECTED; | ||
this.checkResults.failureReasonString = 'NO_WEBCAMS_DETECTED'; | ||
} | ||
} | ||
this.checkResults.detectorResult = result; | ||
@@ -235,16 +134,27 @@ | ||
checkBrowser(res) { | ||
// TODO: this check is probably better to be performed in "@realeyes/environment-detector/lib/browsers" module | ||
// Detect IE <=7 | ||
if (inArray(res.capabilities, capabilities.names.DOCUMENT_ALL) | ||
&& !inArray(res.capabilities, capabilities.names.DOCUMENT_QUERY_SELECTOR)) { | ||
return false; | ||
for (let i = 0; i < this.BLACKLISTED_BROWSERS.length; i++) { | ||
const name = this.BLACKLISTED_BROWSERS[i][0]; | ||
const blacklistedVersions = this.BLACKLISTED_BROWSERS[i][1].split('-'); | ||
const [from, to] = [parseInt(blacklistedVersions[0], 10), parseInt(blacklistedVersions[1], 10)]; | ||
const browserVersion = parseInt(res.browser.version, 10); | ||
if (name === res.browser.name && browserVersion >= from && browserVersion <= to) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
}, | ||
/** | ||
* Checks if browser is unsupported. | ||
* | ||
* @param {EnvironmentDetectionResult} res Environment check result | ||
* @return {boolean} | ||
*/ | ||
unsupportedBrowser(res) { | ||
for (let i = 0; i < this.BLACKLISTED_BROWSERS.length; i++) { | ||
const name = this.BLACKLISTED_BROWSERS[i][0]; | ||
const [from, to] = this.BLACKLISTED_BROWSERS[i][1].split('-'); | ||
if (name === res.browser.name | ||
&& compareVersions(res.browser.version, from) >= 0 | ||
&& compareVersions(res.browser.version, to) <= 0) { | ||
if (name === res.browser.name) { | ||
return false; | ||
@@ -279,6 +189,10 @@ } | ||
typeof window._RealeyesitEnvDetectParams._callback === 'function') { | ||
window.Realeyesit.EnvironmentalDetectionAPI.start(window._RealeyesitEnvDetectParams._callback); | ||
window.Realeyesit.EnvironmentalDetectionAPI.start( | ||
window._RealeyesitEnvDetectParams._callback, | ||
window._RealeyesitEnvDetectParams._options); | ||
} else { | ||
if (typeof window._RealeyesitEnvDetectCallback === 'function') { | ||
window.Realeyesit.EnvironmentalDetectionAPI.start(window._RealeyesitEnvDetectCallback); | ||
window.Realeyesit.EnvironmentalDetectionAPI.start( | ||
window._RealeyesitEnvDetectCallback, | ||
(window._RealeyesitEnvDetectParams || {})._options); | ||
} | ||
@@ -285,0 +199,0 @@ } |
{ | ||
"name": "@realeyes/environment-checker", | ||
"version": "2.3.2", | ||
"version": "3.1.0", | ||
"scripts": { | ||
"lint": "eslint .", | ||
"build": "ejs-cli -O package.json index.js | browserify - -d -t [ babelify ] | exorcist ./dist/Realeyesit.EnvironmentalDetectionAPI.js.map > ./dist/Realeyesit.EnvironmentalDetectionAPI.js", | ||
"copy": "copyfiles -f node_modules/@realeyes/environment-detector/dist/{environment-detector.swf,log.gif} dist", | ||
"copy": "copyfiles -f node_modules/@realeyes/environment-detector/dist/log.gif dist", | ||
"copy:example": "copyfiles -f example/* dist", | ||
"minify": "uglifyjs --support-ie8 --comments /^!/ dist/Realeyesit.EnvironmentalDetectionAPI.js --source-map dist/Realeyesit.EnvironmentalDetectionAPI.min.js.map --in-source-map dist/Realeyesit.EnvironmentalDetectionAPI.js.map --source-map-url Realeyesit.EnvironmentalDetectionAPI.min.js.map > dist/Realeyesit.EnvironmentalDetectionAPI.min.js", | ||
"minify": "uglifyjs --comments /^!/ dist/Realeyesit.EnvironmentalDetectionAPI.js --source-map dist/Realeyesit.EnvironmentalDetectionAPI.min.js.map --in-source-map dist/Realeyesit.EnvironmentalDetectionAPI.js.map --source-map-url Realeyesit.EnvironmentalDetectionAPI.min.js.map > dist/Realeyesit.EnvironmentalDetectionAPI.min.js", | ||
"cleanup": "rimraf dist/*", | ||
"all": "npm run cleanup && npm run lint && npm run build && npm run copy && npm run copy:example && npm run minify", | ||
"prepublish": "npm run all" | ||
"all": "npm run cleanup && npm run lint && npm run build && npm run copy && npm run copy:example && npm run minify" | ||
}, | ||
@@ -21,19 +20,20 @@ "license": "Apache-2.0", | ||
"devDependencies": { | ||
"babel-plugin-transform-es2015-classes": "^6.14.0", | ||
"babel-plugin-transform-es2015-destructuring": "^6.9.0", | ||
"babel-plugin-transform-es2015-modules-commonjs": "^6.14.0", | ||
"babel-plugin-transform-es2015-spread": "^6.8.0", | ||
"babel-plugin-transform-es3-member-expression-literals": "^6.8.0", | ||
"babel-plugin-transform-es3-property-literals": "^6.8.0", | ||
"babel-plugin-transform-runtime": "^6.12.0", | ||
"babel-preset-es2015": "^6.13.2", | ||
"babelify": "^7.3.0", | ||
"browserify": "^13.1.0", | ||
"copyfiles": "^1.0.0", | ||
"ejs-cli": "^2.0.0", | ||
"eslint": "^3.3.1", | ||
"eslint-config-airbnb-base": "11.0.0", | ||
"eslint-plugin-import": "2.2.0", | ||
"exorcist": "^0.4.0", | ||
"rimraf": "^2.5.4", | ||
"babel-core": "6.26.0", | ||
"babel-eslint": "8.2.2", | ||
"babel-plugin-transform-es2015-classes": "^6.24.1", | ||
"babel-plugin-transform-es2015-destructuring": "^6.23.0", | ||
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0", | ||
"babel-plugin-transform-es2015-spread": "^6.22.0", | ||
"babel-plugin-transform-es3-member-expression-literals": "^6.22.0", | ||
"babel-plugin-transform-es3-property-literals": "^6.22.0", | ||
"babel-plugin-transform-runtime": "^6.23.0", | ||
"babel-preset-es2015": "^6.24.1", | ||
"babelify": "^8.0.0", | ||
"browserify": "^16.1.1", | ||
"copyfiles": "^2.0.0", | ||
"ejs-cli": "^2.0.1", | ||
"eslint": "^4.18.2", | ||
"eslint-plugin-import": "^2.9.0", | ||
"exorcist": "^1.0.1", | ||
"rimraf": "^2.6.2", | ||
"uglify-js": "^2.7.3" | ||
@@ -52,9 +52,7 @@ }, | ||
"environment", | ||
"flash", | ||
"checker" | ||
], | ||
"dependencies": { | ||
"@realeyes/environment-detector": "^1.8.3", | ||
"swfobject": "github:realeyes/swfobject#e057ecd34207ad7e2180d83f4a7e75aebac0e42e", | ||
"uuid": "^3.0.1" | ||
"@realeyes/environment-detector": "^2.0.0", | ||
"uuid": "^3.2.1" | ||
}, | ||
@@ -61,0 +59,0 @@ "browserify": { |
# Environment Checker | ||
This package allows you to automatically run the environment check and receive the return the result in a simplified format. We provide two versions of Environment Checker, version 1 should be used for flash-only collections, version 2 for flash and WebRTC collections. | ||
This package allows you to automatically run the environment check and receive the return the result in a simplified format. We provide three versions of Environment Checker, version 1 should be used for flash-only collections, version 2 for flash and WebRTC collections, version 3 for WebRTC only. | ||
@@ -14,6 +14,6 @@ ## Installation | ||
This example loads the latest release of version 2: | ||
This example loads the latest release of version 3: | ||
```html | ||
<script src="https://codesdwncdn.realeyesit.com/environment-checker/release/2/Realeyesit.EnvironmentalDetectionAPI.js"></script> | ||
<script src="https://codesdwncdn.realeyesit.com/environment-checker/release/3/Realeyesit.EnvironmentalDetectionAPI.js"></script> | ||
``` | ||
@@ -30,3 +30,3 @@ | ||
The other way is to call the `Realeyesit.EnvironmentalDetectionAPI.start(callback, options)` method manually. In this case you should provide the callback that will handle the result. | ||
`options` parameter is optional and can be used to disable logging, for example: `Realeyesit.EnvironmentalDetectionAPI.start(callback, { logger: { disable: true } })`. | ||
`options` parameter is optional and can be used to disable logging, for example: `Realeyesit.EnvironmentalDetectionAPI.start(callback, { logger: { disable: true } })`. In options we can manage the allowed device types also for example: `Realeyesit.EnvironmentalDetectionAPI.start(callback, { logger: { disable: true }, allowedDevices: [ 'mobile', 'tablet', 'desktop' ] })` | ||
The result will be in the following format: | ||
@@ -62,5 +62,2 @@ | ||
- `FLASH_NOT_INSTALLED: 1` | ||
- `FLASH_TOO_OLD: 2` | ||
- `FLASH_BLACKLISTED: 3` | ||
- `BROWSER_NOT_CAPABLE: 4` | ||
@@ -70,4 +67,7 @@ - `MOBILE_BROWSER: 5` | ||
- `OTHER_ERROR: 7` | ||
- `IOS_WEBVIEW: 8` | ||
And 'detectorResult' is a result object of environment detector (see more [Environment Detector API](README.html#api)) | ||
*NOTE:* if you are using Environment Checker, then there is no need to use Environment Detector separately. | ||
@@ -96,3 +96,3 @@ ## Example usage | ||
Copyright 2016 Realeyes OU. | ||
Copyright 2018 Realeyes OU. | ||
@@ -99,0 +99,0 @@ Licensed under the Apache License, Version 2.0 (the "License"); |
# Release process | ||
* Use gitflow release or hotfix branch to prepare a release. | ||
* First commit in a release or hotfix branch should bump the version in package.json. | ||
* First commit in a release or hotfix branch should bump the version in package.json. `npm version z.y.z` | ||
* Use `followTags = true` when pushing a release. | ||
* `npm publish` from master branch after a release. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
GitHub dependency
Supply chain riskContains a dependency which resolves to a GitHub URL. Dependencies fetched from GitHub specifiers are not immutable can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 1 instance in 1 package
2
26
0
400779
19
2369
1
+ Added@realeyes/environment-detector@2.0.24(transitive)
+ Addedvisibilityjs@2.0.2(transitive)
- Removedswfobject@github:realeyes/swfobject#e057ecd34207ad7e2180d83f4a7e75aebac0e42e
- Removed@realeyes/environment-detector@1.8.9(transitive)
- Removedvisibilityjs@1.2.8(transitive)
Updateduuid@^3.2.1