Reputation: 13233
In A-Frame, I want to detect if the user has a VR headset connected and to tell which device they are using. How can I do this?
Upvotes: 10
Views: 2566
Reputation: 13233
There are several utility functions in A-Frame we can use to detect compatibility: https://aframe.io/docs/master/core/utils.html
The mobile-related utils look at navigator.userAgent
. The VR-related utils check to see if the pose data returned from the headset/polyfill is not 0,0,0.
Given the current API:
!AFRAME.utils.checkHeadsetConnected()
AFRAME.utils.isMobile()
AFRAME.utils.isGearVR()
!AFRAME.utils.isMobile() && AFRAME.utils.checkHeadsetConnected()
!AFRAME.utils.isMobile() && AFRAME.utils.checkHeadsetConnected()
To differentiate Rift vs. Vive, try using WebVR API Stage Parameters https://w3c.github.io/webvr/#interface-vrstageparameters
Upvotes: 12