Accessing the XRSession in JavaScript (WebVR plugin)

  • Hi all
    What I'm trying to do is to have my tour restart a 360° video whenever a VR headset gets put on the head again.Is there a way for me to access the XRsession that the WebVR plugin creates?

    In order for me to catch it's visibility state changes.
    Or am I totally off here?

    I need something similair like this capability, but then in the VR session:

    document.addEventListener("visibilitychange", () => { console.log(document.hidden); if (document.hidden) {  console.log("Took off headset"); } else {  console.log("Put on headset"); }});

    Kind regardsArnout

  • Hi Klaus

    Thank you for the response. I was able to figure something out thanks to your hint!
    I can now restart my video in VR when the headset is put on again. (So far, my test only shows this working in native Quest 2 browser)

    For any future developers looking for this functionality:
    I added this to my webvr_onentervr-action which allows me to catch this changed visibility event for VR mode in my javascript.

    	if(krpano.webVR.xrSession) {
    		krpano.webVR.xrSession.onvisibilitychange = function(event) {

    Then in my javascript I did this:

    Kind regards

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!