Can you know if an XR session WILL BE granted without requesting a session?

Today, an incredibly small number of XR webpages are being loaded via a “link” from within another page which is already in immersive mode, and has set it up so that the next page can start off in immersive mode. (Yes, BJS does this).

Yet, I would still like to know at the very beginning when one of my pages is being loaded, that they EVENTUALLY will or will not qualify as not having click something to get into immersive. If known, things could be arranged in different ways to get the fastest perceived loading for either case.

I did a search for sessiongranted XR. Pickings are very light. A 3 year dormant proposal repo is like the top hit as well. It looks like it is wrong too. Results that follow quickly drop off from there.

Is this something that can be knowable?

1 Like

Well just as I hit the send, I think I figured it out, & suspect it might have to be a little forced. In the WebXREnterExitUI constructor there is

    // prepare for session granted event
    if (!options.ignoreSessionGrantedEvent && (navigator as any).xr) {
        (navigator as any).xr.addEventListener("sessiongranted", this._onSessionGranted);
    }

Seems like adding my own listener, will at least tell me after the fact, but only after requesting a session would I know. Guess will HAVE to move the request up, which I was in the process of doing, but not plann to that early.

1 Like

I don’t quite get the use case, but if you have found the solution i’m very happy :slight_smile:

The use case is if the vast majority of the time that user clicking is going to be required, then it might pay to put checking in render loop code to only actually call scene.render() more than once till fully ready in these cases:

  • not on an XR device (am assuming desktops are faster here)
  • Native (not currently testable)
  • coming from a prior page in immersive
  • user clicked the goggles
  • loading of everything complete

It might take a user up to a second to get a pointer over & click the goggles, no use wasting ANY UI thread time till then. Retrieval of stuff takes place off the main thread, but there are intermittent times when UI thread is needed, especially if parallel shader loading is not supported.

I am trying to do as defensible coding as possible. If immersive was entered, the device frame rate is also going to be lowered as far as possible. In addition, only allowing a single mesh to be close in front of the camera, with a scene freeze is on to preventing even looking for other things.

I load my geometry with JS not a .bablyon / .glb, so not sure how applicable when doing that.