Skip to content

Commit 9f8e41a

Browse files
Artyom17dmarcos
authored andcommitted
Fixing issue #4198: VR deep-linking / VR navigation doesn't work. (#4199)
* Fixing issue #4198: VR deep-linking / VR navigation doesn't work. * Addressing feedback from Diego. * One more feedback from Diego.
1 parent b3ed182 commit 9f8e41a

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/core/scene/a-scene.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* global Promise, screen */
1+
/* global Promise, screen, CustomEvent */
22
var initMetaTags = require('./metaTags').inject;
33
var initWakelock = require('./wakelock');
44
var loadingScreen = require('./loadingScreen');
@@ -309,6 +309,14 @@ module.exports.AScene = registerElement('a-scene', {
309309

310310
// Callback that happens on enter VR success or enter fullscreen (any API).
311311
function enterVRSuccess () {
312+
// vrdisplaypresentchange fires only once when the first requestPresent is completed;
313+
// the first requestPresent could be called from ondisplayactivate and there is no way
314+
// to setup everything from there. Thus, we need to emulate another vrdisplaypresentchange
315+
// for the actual requestPresent. Need to make sure there are no issues with firing the
316+
// vrdisplaypresentchange multiple times.
317+
var event = new CustomEvent('vrdisplaypresentchange', {detail: {display: utils.device.getVRDisplay()}});
318+
window.dispatchEvent(event);
319+
312320
self.addState('vr-mode');
313321
self.emit('enter-vr', {target: self});
314322
// Lock to landscape orientation on mobile.

src/utils/device.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ window.addEventListener('vrdisplayactivate', function (evt) {
99
if (navigator.xr) { return; }
1010
canvasEl = document.createElement('canvas');
1111
vrDisplay = evt.display;
12+
// We need to make sure the canvas has a WebGL context associated with it.
13+
// Otherwise, the requestPresent could be denied.
14+
canvasEl.getContext('webgl', {});
1215
// Request present immediately. a-scene will be allowed to enter VR without user gesture.
1316
vrDisplay.requestPresent([{source: canvasEl}]).then(function () {}, function () {});
1417
});

0 commit comments

Comments
 (0)