How to detect if we are in AR or VR?

I have a model viewer I am adding VR capabilities to but I need to know if we are entering VR or AR when using the WebXR class- how can I check if we are in AR or VR here? I can see _isInVR and _isInAR are private there

            WebXR.addEventListener(
              WebXREvent.XRStarted,
              this.onXRStarted.bind(this)
            );
            WebXR.addEventListener(
              WebXREvent.XRStopped,
              this.onXRStopped.bind(this)
            );

Original Post on Discord

by user 103054507105067008

Exactly like that - not sure what the question is :slightly_smiling_face:

I am detecting XR started there but not AR or VR specifically

by user 103054507105067008

It was fine for when I just had an AR mode as I was detecting an AR session but now I want to know if we are entering VR or AR when those events fire

by user 103054507105067008

.IsInAR() and .IsInVR() expose the session type

Ah I can grab those globally of course :smiling_face_with_tear:

by user 103054507105067008

on WebXR (on the component instance not the static one)

the context also has xrSessionMode

and a few more places :smile: lots of options

Thanks that’s perfect!

by user 103054507105067008