Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix regex checking for cardboard support #358

Merged
merged 11 commits into from
Jun 1, 2018

Conversation

InfiniteLee
Copy link
Contributor

@InfiniteLee InfiniteLee commented May 2, 2018

fix the regex so that ios cardboard is properly detected. Fixes #352

Despite the name of the branch, iOS is explicitly disabled until we fix rendering on carboard iOS. Same for Android/Firefox.

@gfodor
Copy link
Contributor

gfodor commented May 10, 2018

What's the case here this misses? As it is right now I think \W* on both ends basically serves no purpose since it will match anything and could be removed. I'm guessing there is an example where it's a substring?

@gfodor gfodor self-requested a review May 10, 2018 18:44
@InfiniteLee
Copy link
Contributor Author

@gfodor I believe it has to do with the fact that "Cardboard" is the first word that shows up in the navigator.getVRDisplays() name ("Cardboard VRDisplay") on iOS. So \W alone wont match anything.

"Cardboard VRDisplay".match(/\Wcardboard\W/i)
> null
"Cardboard VRDisplay".match(/\W*cardboard\W*/i)
> Array [ "Cardboard " ]

vs on Android:

"Google, Inc. Cardboard v1".match(/\Wcardboard\W/i)
> Array [ "Cardboard " ]

@gfodor
Copy link
Contributor

gfodor commented May 10, 2018

Ah I understand -- I believe I intended these to be \b's (word boundaries) not \W's -- should match begin/end of line as well as whitespaces

@InfiniteLee
Copy link
Contributor Author

I'll try that.

@brianpeiris and I also just discovered this same bug is preventing us from launching cardboard on firefox android.

@InfiniteLee
Copy link
Contributor Author

\b wont match if cardboard appears in the middle of another string e.g. "GoogleCardboard". I don't know if that will be important or not.

@gfodor
Copy link
Contributor

gfodor commented May 10, 2018

i guess its not the end of the world if we just match the substring. sgtm.

@gfodor
Copy link
Contributor

gfodor commented May 10, 2018

i'd just drop the \w*'s now

@cvan
Copy link
Contributor

cvan commented May 10, 2018

feel free to do d.displayName.toLowerCase().includes("cardboard")

btw, displayName is deprecated in WebVR v1.1 - though it is still implemented in the WebVR v1.1 browsers and the WebVR Polyfill. Apple will not be implementing it in Safari.

so likely you will want to check d.capabilities.hasExternalDisplay === false instead to future-proof this.

@@ -70,12 +70,12 @@ export async function getAvailableVREntryTypes() {
? VR_DEVICE_AVAILABILITY.yes
: VR_DEVICE_AVAILABILITY.no;

cardboard = displays.find(d => d.capabilities.canPresent && d.displayName.match(/\Wcardboard\W/i))
cardboard = displays.find(d => d.capabilities.canPresent && d.displayName.match(/\W*cardboard\W*/i))
Copy link
Contributor

@cvan cvan May 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when the WebVR Polyfill is used, you can check d.isPolyfilled

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing we need to re-write this all imminently once WebXR lands in origin trial in chrome, so probably not worth worrying about for now

@InfiniteLee InfiniteLee changed the title WIP - enable cardboard on iOS Fix regex checking for cardboard support May 11, 2018
@@ -43,6 +43,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/);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I don't own an iPad, but I'd assume the bug exists there as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we already have https://www.npmjs.com/package/mobile-detect in our packages, perhaps that's a good way to check this? or https://www.npmjs.com/package/device-detect

Copy link
Contributor

@cvan cvan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good work! the WebVR and headset landscape makes this quite tricky to chase down


// For daydream detection, in a WebVR browser we can increase confidence in daydream compatibility.
const hasDaydreamWebVRDevice = displays.find(d => d.displayName.match(/\Wdaydream\W/i));
const hasDaydreamWebVRDevice = displays.find(d => d.displayName.match(/daydream/i));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since you're checking d.capabilities.canPresent above, do you want to do it here as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that necessary? I suspect that a daydream display wouldn't show up at all if that were the case.

@@ -70,12 +71,13 @@ export async function getAvailableVREntryTypes() {
? VR_DEVICE_AVAILABILITY.yes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, it can likely be discussed in a separate issue, but should GENERIC_ENTRY_TYPE_DEVICE_BLACKLIST instead be checking d.capabilities.hasExternalDisplay === false?

@@ -43,6 +43,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/);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I don't own an iPad, but I'd assume the bug exists there as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable cardboard mode on iOS
4 participants