From 3d43b0a9771a4b7f71cc40f0ec47a639ef6a7585 Mon Sep 17 00:00:00 2001
From: Kevin Lee <kevin@infinite-lee.com>
Date: Fri, 11 May 2018 16:00:32 -0700
Subject: [PATCH] Adding device-detect to check against all "iDevices".

---
 package.json                |  1 +
 src/utils/vr-caps-detect.js | 11 +++++++----
 yarn.lock                   |  4 ++++
 3 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/package.json b/package.json
index 096b55a05..bc629bbad 100644
--- a/package.json
+++ b/package.json
@@ -34,6 +34,7 @@
     "copy-to-clipboard": "^3.0.8",
     "copy-webpack-plugin": "^4.5.1",
     "detect-browser": "^2.1.0",
+    "device-detect": "^1.0.7",
     "event-target-shim": "^3.0.1",
     "form-urlencoded": "^2.0.4",
     "jsonschema": "^1.2.2",
diff --git a/src/utils/vr-caps-detect.js b/src/utils/vr-caps-detect.js
index 42f3c6676..7a577b6eb 100644
--- a/src/utils/vr-caps-detect.js
+++ b/src/utils/vr-caps-detect.js
@@ -1,5 +1,6 @@
 const { detect } = require("detect-browser");
 const browser = detect();
+const deviceDetect = require("device-detect")();
 
 // Precision on device detection is fuzzy -- we can sometimes know if a device is definitely
 // available, or definitely *not* available, and assume it may be available otherwise.
@@ -43,8 +44,8 @@ export async function getAvailableVREntryTypes() {
   const isSamsungBrowser = browser.name === "chrome" && navigator.userAgent.match(/SamsungBrowser/);
   const isOculusBrowser = navigator.userAgent.match(/Oculus/);
   const isDaydreamCapableBrowser = !!(isWebVRCapableBrowser && browser.name === "chrome" && !isSamsungBrowser);
-  const isIPhone = navigator.userAgent.match(/iPhone/);
-  const isFirefoxBrowser = navigator.userAgent.match(/Firefox/);
+  const isIDevice = ["iPhone", "iPad", "iPod"].indexOf(deviceDetect.device) > -1;
+  const isFirefoxBrowser = browser.name === "firefox";
 
   let generic = VR_DEVICE_AVAILABILITY.no;
   let cardboard = VR_DEVICE_AVAILABILITY.no;
@@ -55,7 +56,9 @@ export async function getAvailableVREntryTypes() {
   //
   // If we are in Oculus Browser (ie, we are literally wearing a GearVR) then return 'yes'.
   const gearvr = isMaybeGearVRCompatibleDevice()
-    ? isOculusBrowser ? VR_DEVICE_AVAILABILITY.yes : VR_DEVICE_AVAILABILITY.maybe
+    ? isOculusBrowser
+      ? VR_DEVICE_AVAILABILITY.yes
+      : VR_DEVICE_AVAILABILITY.maybe
     : VR_DEVICE_AVAILABILITY.no;
 
   // For daydream detection, we first check if they are on an Android compatible device, and assume they
@@ -73,7 +76,7 @@ export async function getAvailableVREntryTypes() {
       : VR_DEVICE_AVAILABILITY.no;
 
     cardboard =
-      !isIPhone &&
+      !isIDevice &&
       !isFirefoxBrowser &&
       displays.find(d => d.capabilities.canPresent && d.displayName.match(/cardboard/i))
         ? VR_DEVICE_AVAILABILITY.yes
diff --git a/yarn.lock b/yarn.lock
index cc1b5ae12..aba9e254d 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2594,6 +2594,10 @@ detective@^5.0.2:
     defined "^1.0.0"
     minimist "^1.1.1"
 
+device-detect@^1.0.7:
+  version "1.0.7"
+  resolved "https://registry.yarnpkg.com/device-detect/-/device-detect-1.0.7.tgz#d4f1aa2fc3afbbc7d4b4dc182b9822dffc50a708"
+
 diff@^2.1.2:
   version "2.2.3"
   resolved "https://registry.yarnpkg.com/diff/-/diff-2.2.3.tgz#60eafd0d28ee906e4e8ff0a52c1229521033bf99"
-- 
GitLab