Skip to content

isMobileVR() erroneously return true on iPad since AVP support #5605

@vincentfretin

Description

@vincentfretin

Description:

AFRAME.utils.device.isMobileVR() erroneously return true on iPad (probably also on iPhone) since the changes to support Apple Vision Pro in c590f85. It returned false on aframe 1.6.0

I'm not sure how to fix it on aframe side.

Currently in my solidjs project I'm using a headsetConnected variable/signal that I set like this:

  const [headsetConnected, setHeadsetConnected] = createSignal(false);
  const [supportsVRSession, setSupportsVRSession] = createSignal(false);
  createEffect(() => {
    const errorHandler = function (err: Error) {
      console.error("WebXR session support error: " + err.message);
    };
    if (navigator.xr !== undefined && navigator.xr.isSessionSupported) {
      // Current WebXR spec uses a boolean-returning isSessionSupported promise
      navigator.xr
        .isSessionSupported("immersive-vr")
        .then(function (supported) {
          setSupportsVRSession(supported);
        })
        .catch(errorHandler);
    }
  });

  createEffect(() => {
    // We don't use AFRAME.utils.device.checkHeadsetConnected() because it set supportsVRSession internally after
    // the promise is resolved so the checkHeadsetConnected() call may be done before the promise is resolved.
    setHeadsetConnected(supportsVRSession() && AFRAME.utils.device.isMobileVR());
  });

where I add an additional check to see if the browser supports a vr session.
I don't use AFRAME.utils.device.checkHeadsetConnected() or checkVRSupport() because those are not reliable if you call it too early, the navigator.xr.isSessionSupported promise may not have been resolved yet, I actually had that issue.

Maybe we should expose checkVRSupportAsync that return a promise? Just a thought.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions