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

Supported Session Features Table and requestSession with promises #1385

Closed
TiborUdvari opened this issue Sep 9, 2024 · 3 comments
Closed

Comments

@TiborUdvari
Copy link

I'm creating a page where one can see which features of immersive sessions are available. Does this already exist somewhere? I would prefer to link to it.

I'm trying to cycle through creating an immersive-ar and immersive-vr session with one session feature each time, as listed in the MDN docs. If the session creation is successful, the feature is supported. Is there a more straightforward way of achieving this?

I'm trying to use Promises and async-await, which works well in the simulator. However, on the Meta Quest 3 device I own, whenever any promise seems to be involved with requestSession, it just hangs and never returns. I wanted to document this here in case anyone else runs into this behavior. Please redirect me anywhere else if there is a more appropriate place to ask this question.

Context: I'm working on p5.xr, and I think it's a little tricky ATM for people to be able to query what capabilities their devices have

Here is a snippet I tried to wrap, which never returns either a session or an error:

function requestSessionPromise(mode, feature) {
  return new Promise((resolve, reject) => {
    if (!navigator.xr) {
      reject(new Error('navigator.xr non existent'));
    }
    navigator.xr
      .requestSession(mode, { requiredFeatures: [feature] })
      .then(
        (session) => {
          resolve(session);
        },
        (error) => {
          reject(error);
        },
      );
  });
}
Screenshot 2024-09-09 at 15 04 48
@Maksims
Copy link

Maksims commented Sep 9, 2024

I think you can make a single request with all features as optionalFueatures array, and then check a session's enabledFeatures list of what is supported.

@AdaRoseCannon
Copy link
Member

https://immersiveweb.dev/#supporttable should be an up to date table. If you find mistakes please make a pull request.

@TiborUdvari
Copy link
Author

Thanks for the feedback! I was looking for a way to test features on the current device, the way that was suggested by @Maksims works best for that. Although if the whole session fails to start for some reason, there is no meaningful info, so I also added buttons for each mode - session feature combination as a fallback.

The support table is also a valuable resource, thank you @AdaRoseCannon

Here is the result: https://p5xr.org/#/webxr-test.html

After refactoring for not using Promises, I found that I was getting a Security error relating to not starting an XRSession from a user event. I was trying to start the next one from the end event of the previous one. Weird that it failed silently with promises.

Screenshot 2024-09-10 at 11 20 58

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

No branches or pull requests

3 participants