[WebXR] Headset sleep and wake-up events

I can’t find any event to handle sleep and wake-up state transitions of the VR headset. Tried Babylon.js documentation, WebXR specification, Google)

It’s a common task for XR, I guess, to stop some process (video player, game, etc.) while taking off the headset. And to resume the process after putting on the headset.

Is it possible?

Pinging @RaananW

Hi @Dmitry123,

That’s a very good question! As far as I know, there are no events that are triggered when the headset is in rest mode or comes out of it. I’m also pretty sure that in the case of the oculus quest, code stop executing the second the headset is removed (but I’m not 100% sure here).

If you want, you can submit a github ticket and I’ll investigate it further when I have the time to dive into that.

Found it! I’ve missed XRSessionEvent.

    xrSession.addEventListener("visibilitychange", (eventData: any) => {
        switch(eventData.session.visibilityState) {
            case "visible":
            case "visible-blurred":
            case "hidden":
1 Like

great! is the code in hidden being executed?

Yes, this is my simplified copy-paste. I’ve tested this code on Oculus Quest.