@realeyes/environment-checker
Advanced tools
Comparing version 1.0.7 to 2.0.3
@@ -11,2 +11,3 @@ module.exports = { | ||
"valid-jsdoc": ["error", { "requireReturnDescription": false }], | ||
"no-plusplus": ["error", { "allowForLoopAfterthoughts": true }], | ||
"require-jsdoc": ["error", { | ||
@@ -13,0 +14,0 @@ "require": { |
60
index.js
@@ -24,2 +24,3 @@ /*! | ||
* failureReasonString: string, | ||
* detectorResult: EnvironmentDetectionResult, | ||
* }} EnvironmentCheckResult | ||
@@ -74,2 +75,20 @@ */ | ||
/** | ||
* 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 || {}; | ||
@@ -112,8 +131,22 @@ window.Realeyesit.EnvironmentalDetectionAPI = { | ||
this.checkResults.checksPassed = false; | ||
const ua = navigator.userAgent; | ||
const skip = []; | ||
// TODO: flash.path should point to environment-detector.swf file on the CDN | ||
detect({ flash: { path: DEFAULT_FLASH_DETECTOR_PATH } }).then(result => { | ||
const flashVersion = swfobject().getFlashPlayerVersion(); | ||
const flashVersionString = `${flashVersion.major}.${flashVersion.minor}.${flashVersion.release}`; | ||
if ( | ||
(/firefox/i.test(navigator.userAgent) && | ||
compareVersions(getFirstMatch(ua, /(?:firefox)[ /](\d+(\.\d+)?)/i), '48') >= 0) || | ||
(/chrome/i.test(navigator.userAgent) && !/edge/i.test(ua) && | ||
compareVersions(getFirstMatch(ua, /(?:chrome)\/(\d+(\.\d+)?)/i), '50') >= 0) | ||
) { | ||
skip.push('flash'); | ||
} | ||
detect({ flash: { path: DEFAULT_FLASH_DETECTOR_PATH }, skip }).then((result) => { | ||
let flashVersionString = ''; | ||
if (!inArray(skip, 'flash')) { | ||
const flashVersion = swfobject().getFlashPlayerVersion(); | ||
flashVersionString = `${flashVersion.major}.${flashVersion.minor}.${flashVersion.release}`; | ||
} | ||
if (!this.checkBrowser(result)) { | ||
@@ -141,4 +174,19 @@ this.checkResults.failureReasonCode = this.failureReasonCodes.BROWSER_NOT_CAPABLE; | ||
if (result && this.checkResults.failureReasonCode === this.failureReasonCodes.FLASH_NOT_INSTALLED && | ||
(result.browser.name === browsers.names.CHROME || result.browser.name === browsers.names.FIREFOX || | ||
result.browser.name === browsers.names.OPERA)) { | ||
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; | ||
return callback(this.checkResults); | ||
}, err => { | ||
}, (err) => { | ||
this.checkResults.failureReasonCode = this.failureReasonCodes.OTHER_ERROR; | ||
@@ -195,7 +243,5 @@ this.checkResults.failureReasonString = err.message; | ||
/* eslint-disable */ | ||
/** | ||
* Start detection immediately when window has a env detect callback. | ||
*/ | ||
(function () { | ||
@@ -202,0 +248,0 @@ if (typeof window._RealeyesitEnvDetectParams === 'object' && |
{ | ||
"name": "@realeyes/environment-checker", | ||
"version": "1.0.7", | ||
"version": "2.0.3", | ||
"scripts": { | ||
@@ -34,4 +34,4 @@ "lint": "eslint .", | ||
"eslint": "^3.3.1", | ||
"eslint-config-airbnb-base": "^5.0.3", | ||
"eslint-plugin-import": "^1.14.0", | ||
"eslint-config-airbnb-base": "11.0.0", | ||
"eslint-plugin-import": "2.2.0", | ||
"rimraf": "^2.5.4", | ||
@@ -38,0 +38,0 @@ "uglify-js": "^2.7.3" |
15085
231