Skip to content
Snippets Groups Projects
Unverified Commit d87794e9 authored by Marshall Quander's avatar Marshall Quander Committed by GitHub
Browse files

Merge pull request #457 from mozilla/vr-ua-check-fix

Fix regex tests in VR capabilities checks
parents 708bf2a7 e205f442
No related branches found
No related tags found
No related merge requests found
...@@ -10,12 +10,12 @@ export const VR_DEVICE_AVAILABILITY = { ...@@ -10,12 +10,12 @@ export const VR_DEVICE_AVAILABILITY = {
maybe: "maybe" // Implies this device may support this VR platform, but may not be installed or in a compatible browser maybe: "maybe" // Implies this device may support this VR platform, but may not be installed or in a compatible browser
}; };
function isMaybeGearVRCompatibleDevice() { function isMaybeGearVRCompatibleDevice(ua) {
return navigator.userAgent.match(/\WAndroid\W/); return /\WAndroid\W/.test(ua);
} }
function isMaybeDaydreamCompatibleDevice() { function isMaybeDaydreamCompatibleDevice(ua) {
return navigator.userAgent.match(/\WAndroid\W/); return /\WAndroid\W/.test(ua);
} }
// Blacklist of VR device name regex matchers that we do not want to consider as valid VR devices // Blacklist of VR device name regex matchers that we do not want to consider as valid VR devices
...@@ -43,8 +43,9 @@ const GENERIC_ENTRY_TYPE_DEVICE_BLACKLIST = [/cardboard/i]; ...@@ -43,8 +43,9 @@ const GENERIC_ENTRY_TYPE_DEVICE_BLACKLIST = [/cardboard/i];
// //
// This function also detects if the user is already in a headset, and returns the isInHMD key to be `true` if so. // This function also detects if the user is already in a headset, and returns the isInHMD key to be `true` if so.
export async function getAvailableVREntryTypes() { export async function getAvailableVREntryTypes() {
const isSamsungBrowser = browser.name === "chrome" && navigator.userAgent.match(/SamsungBrowser/); const ua = navigator.userAgent;
const isOculusBrowser = navigator.userAgent.match(/Oculus/); const isSamsungBrowser = browser.name === "chrome" && /SamsungBrowser/.test(ua);
const isOculusBrowser = /Oculus/.test(ua);
const isInHMD = isOculusBrowser; const isInHMD = isOculusBrowser;
// This needs to be kept up-to-date with the latest browsers that can support VR and Hubs. // This needs to be kept up-to-date with the latest browsers that can support VR and Hubs.
...@@ -73,21 +74,21 @@ export async function getAvailableVREntryTypes() { ...@@ -73,21 +74,21 @@ export async function getAvailableVREntryTypes() {
// //
// If we are in Oculus Browser (ie, we are literally wearing a GearVR) then return 'yes'. // If we are in Oculus Browser (ie, we are literally wearing a GearVR) then return 'yes'.
let gearvr = VR_DEVICE_AVAILABILITY.no; let gearvr = VR_DEVICE_AVAILABILITY.no;
if (isMaybeGearVRCompatibleDevice()) { if (isMaybeGearVRCompatibleDevice(ua)) {
gearvr = isOculusBrowser ? VR_DEVICE_AVAILABILITY.yes : VR_DEVICE_AVAILABILITY.maybe; gearvr = isOculusBrowser ? VR_DEVICE_AVAILABILITY.yes : VR_DEVICE_AVAILABILITY.maybe;
} }
// For daydream detection, we first check if they are on an Android compatible device, and assume they // For daydream detection, we first check if they are on an Android compatible device, and assume they
// may support daydream *unless* this browser has WebVR capabilities, in which case we can do better. // may support daydream *unless* this browser has WebVR capabilities, in which case we can do better.
let daydream = let daydream =
isMaybeDaydreamCompatibleDevice() && !isInHMD ? VR_DEVICE_AVAILABILITY.maybe : VR_DEVICE_AVAILABILITY.no; isMaybeDaydreamCompatibleDevice(ua) && !isInHMD ? VR_DEVICE_AVAILABILITY.maybe : VR_DEVICE_AVAILABILITY.no;
if (isWebVRCapableBrowser) { if (isWebVRCapableBrowser) {
const displays = await navigator.getVRDisplays(); const displays = await navigator.getVRDisplays();
// Generic is supported for non-blacklisted devices and presentable HMDs. // Generic is supported for non-blacklisted devices and presentable HMDs.
generic = displays.find( generic = displays.find(
d => d.capabilities.canPresent && !GENERIC_ENTRY_TYPE_DEVICE_BLACKLIST.find(r => d.displayName.match(r)) d => d.capabilities.canPresent && !GENERIC_ENTRY_TYPE_DEVICE_BLACKLIST.find(r => r.test(d.displayName))
) )
? VR_DEVICE_AVAILABILITY.yes ? VR_DEVICE_AVAILABILITY.yes
: VR_DEVICE_AVAILABILITY.no; : VR_DEVICE_AVAILABILITY.no;
...@@ -95,12 +96,12 @@ export async function getAvailableVREntryTypes() { ...@@ -95,12 +96,12 @@ export async function getAvailableVREntryTypes() {
cardboard = cardboard =
!isIDevice && !isIDevice &&
!isFirefoxBrowser && !isFirefoxBrowser &&
displays.find(d => d.capabilities.canPresent && d.displayName.match(/cardboard/i)) displays.find(d => d.capabilities.canPresent && /cardboard/i.test(d.displayName))
? VR_DEVICE_AVAILABILITY.yes ? VR_DEVICE_AVAILABILITY.yes
: VR_DEVICE_AVAILABILITY.no; : VR_DEVICE_AVAILABILITY.no;
// For daydream detection, in a WebVR browser we can increase confidence in daydream compatibility. // For daydream detection, in a WebVR browser we can increase confidence in daydream compatibility.
const hasDaydreamWebVRDevice = displays.find(d => d.displayName.match(/daydream/i)); const hasDaydreamWebVRDevice = displays.find(d => /daydream/i.test(d.displayName));
if (hasDaydreamWebVRDevice) { if (hasDaydreamWebVRDevice) {
// If we detected daydream via WebVR // If we detected daydream via WebVR
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment