Skip to content

Can I avoid the XRButton ? #220

Discussion options

You must be logged in to vote

WebXR requires interaction to start a session, so you could place a button beforehand (you'll often see immersive sites have a button gate to get the same permission for audio), and eagerly create a session once granted. Maybe react-xr can export a method to do this. This would be the relevant code:

function XRSessionInit() {
  const set = useXR(state => state.set)

  useLayoutEffect(() => {
    let session

    try {
      navigator.xr
        .requestSession('immersive-vr', {
          optionalFeatures: ['local-floor', 'bounded-floor', 'hand-tracking', 'layers'],
        })
        .then((session) => {
          // Check if unmounted
          if (session === null) return
          // O…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@quertenmont
Comment options

@bbohlender
Comment options

Answer selected by bbohlender
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants