-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Changes from all commits
ac29977
e173bb9
a03d112
94488f7
d1a057f
e44bd2b
4fd2c88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,7 @@ class AScene extends AEntity { | |
self.systems = {}; | ||
self.systemNames = []; | ||
self.time = self.delta = 0; | ||
self.usedOfferSession = false; | ||
|
||
self.behaviors = {tick: [], tock: []}; | ||
self.hasLoaded = false; | ||
|
@@ -270,13 +271,15 @@ class AScene extends AEntity { | |
* @param {bool?} useAR - if true, try immersive-ar mode | ||
* @returns {Promise} | ||
*/ | ||
enterVR (useAR) { | ||
enterVR (useAR, useOfferSession) { | ||
var self = this; | ||
var vrDisplay; | ||
var vrManager = self.renderer.xr; | ||
var xrInit; | ||
|
||
// Don't enter VR if already in VR. | ||
if (useOfferSession && (!navigator.xr || !navigator.xr.offerSession)) { return Promise.resolve('OfferSession is not supported.'); } | ||
if (self.usedOfferSession && useOfferSession) { return Promise.resolve('OfferSession was already called.'); } | ||
if (this.is('vr-mode')) { return Promise.resolve('Already in VR.'); } | ||
|
||
// Has VR. | ||
|
@@ -294,9 +297,16 @@ 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 requestSession = useOfferSession ? navigator.xr.offerSession.bind(navigator.xr) : navigator.xr.requestSession.bind(navigator.xr); | ||
self.usedOfferSession |= useOfferSession; | ||
cabanier marked this conversation as resolved.
Show resolved
Hide resolved
|
||
requestSession(xrMode, xrInit).then( | ||
function requestSuccess (xrSession) { | ||
self.xrSession = xrSession; | ||
|
||
if (useOfferSession) { | ||
self.usedOfferSession = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably can always set this to false here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. without checking useOfferSession There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe the regular requestSession API will then also set this to false. At that point we'll be in a bad state because the offersession promise is still pending. |
||
} | ||
|
||
vrManager.layersEnabled = xrInit.requiredFeatures.indexOf('layers') !== -1; | ||
vrManager.setSession(xrSession).then(function () { | ||
vrManager.setFoveation(rendererSystem.foveationLevel); | ||
|
There was a problem hiding this comment.
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