Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for offerSession #5410

Merged
merged 7 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/components/scene/xr-mode-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ module.exports.Component = registerComponent('xr-mode-ui', {
} else {
if (!utils.device.checkVRSupport()) { this.enterVREl.classList.add('fullscreen'); }
this.enterVREl.classList.remove(HIDDEN_CLASS);
sceneEl.enterVR(false, true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably handle this a bit differently. Give control to the dev and decide if the page is auto-entering VR. Maybe a property in this component enterImmersiveModeAtPageLoad a tad long but descriptive. open to a shorter alternative. We can then probably handled the sceneEl.enterVR here https://github.com/aframevr/aframe/pull/5410/files#diff-8eae4e9d86bc7d08e7db133212411b40a655722a0d8c42c1c99c45fccef72f74L124 before deciding to display the UI

}
},

Expand All @@ -161,6 +162,7 @@ module.exports.Component = registerComponent('xr-mode-ui', {
this.enterAREl.classList.add(HIDDEN_CLASS);
} else {
this.enterAREl.classList.remove(HIDDEN_CLASS);
sceneEl.enterVR(true, true);
}
},

Expand Down
13 changes: 11 additions & 2 deletions src/core/scene/a-scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,15 @@ class AScene extends AEntity {
* @param {bool?} useAR - if true, try immersive-ar mode
* @returns {Promise}
*/
enterVR (useAR) {
enterVR (useAR, useOfferSession = false) {
cabanier marked this conversation as resolved.
Show resolved Hide resolved
var self = this;
var vrDisplay;
var vrManager = self.renderer.xr;
var xrInit;

// Don't enter VR if already in VR.
if (navigator.xr.offerSession === undefined) { return Promise.resolve('OfferSession is not supported.'); }
cabanier marked this conversation as resolved.
Show resolved Hide resolved
if (this.is('has-offer-session')) { return Promise.resolve('Already has offerSession.'); }
cabanier marked this conversation as resolved.
Show resolved Hide resolved
if (this.is('vr-mode')) { return Promise.resolve('Already in VR.'); }

// Has VR.
Expand All @@ -294,9 +296,15 @@ class AScene extends AEntity {
var xrMode = useAR ? 'immersive-ar' : 'immersive-vr';
xrInit = this.sceneEl.systems.webxr.sessionConfiguration;
return new Promise(function (resolve, reject) {
navigator.xr.requestSession(xrMode, xrInit).then(
var requestFunction = useOfferSession ? navigator.xr.offerSession.bind(navigator.xr) : navigator.xr.requestSession.bind(navigator.xr);
cabanier marked this conversation as resolved.
Show resolved Hide resolved
if (useOfferSession) {
self.addState('has-offer-session');
}
requestFunction(xrMode, xrInit).then(
function requestSuccess (xrSession) {
self.xrSession = xrSession;
self.removeState('has-offer-session');

vrManager.layersEnabled = xrInit.requiredFeatures.indexOf('layers') !== -1;
vrManager.setSession(xrSession).then(function () {
vrManager.setFoveation(rendererSystem.foveationLevel);
Expand All @@ -306,6 +314,7 @@ class AScene extends AEntity {
enterVRSuccess(resolve);
},
function requestFail (error) {
self.removeState('has-offer-session');
var useAR = xrMode === 'immersive-ar';
var mode = useAR ? 'AR' : 'VR';
reject(new Error('Failed to enter ' + mode + ' mode (`requestSession`)', { cause: error }));
Expand Down
Loading