Erik van Oosterhout
Erik van Oosterhout

Reputation: 25

A-frame automatically entering in full screen mode oculus go

I am using A-frame for building a VR website. I wish to enter vr-mode without having to press the 'enter-vr' glasses on the oculus go more than once. For my application most of the html (including the a-scene) get reloaded (but the header/footer remain in place). For pc browsers this code works:

HTML:

<a-scene id="eqvrscene">
</a-scene>
<button id="enterVRButton" onclick="$('#eqvrscene')[0].enterVR();"> Enter VR </button>

JS:

$("#enterVRButton")[0].click();

but this does unfortunately nothing on the oculus go. Does anyone have a suggesting how to tackle this problem?

Upvotes: 1

Views: 1145

Answers (2)

Diego Marcos
Diego Marcos

Reputation: 4585

It’s not posible. The WebVR API does not allow to enter VR mode automatically. It requires a user gesture like a click that cannot be synthetized like your example does. The only exception is when a page enters VR mode after user gesture, new pages are granted permission to enter VR automatically after navigation. A-Frame already accounts for the scenario and no extra application code is necessary.

Firefox also grants permision to enter VR automatically on page reload. That’s why you might be seeing a different behavior on desktop. Your code is not necessary, A-Frame auto enters VR automatically already. This case is not covered in the Oculus Browser

Upvotes: 0

Dan S.
Dan S.

Reputation: 331

This may or may not be related, but you have a typo in your <a-scene> tag.

It's difficult to tell from your code, but are you sure your scene is loaded when you click the button?

Try first listening for the loaded event of the scene, and then setting up a listener for the button:

// Scene entity element
var scene = document.querySelector('a-scene');

// Button element
var enterVRButton = document.querySelector('#enterVRButton');


// Check if scene has loaded, otherwise set up listener for when it does.
if (scene.hasLoaded) {
  addButtonListener();
} else {
  scene.addEventListener('loaded', addButtonListener);
}

// Add our button click listener.
function addButtonListener() {
  enterVRButton.addEventListener('click', function() {
    scene.enterVR();
  });
}

In A-Frame master branch, there is an API in place for adding a custom button for entering VR, so it may be released in 0.9.0. See the master docs: https://aframe.io/docs/master/components/vr-mode-ui.html#specifying-a-custom-enter-vr-button

If you're trying to automate the click event, I don't believe this will work in many browsers, as a user interaction is required for enterVR().

Upvotes: 1

Related Questions