Skip to content

Commit f57a1fa

Browse files
ngokevindmarcos
authored andcommitted
move second vrdisplayactivate back to attachedCallback to fix auto enter VR issues, event being added too late, regressed in camera system prioritization patch (#4155)
1 parent 5dd4ce6 commit f57a1fa

File tree

1 file changed

+28
-30
lines changed

1 file changed

+28
-30
lines changed

src/core/scene/a-scene.js

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,34 @@ module.exports.AScene = registerElement('a-scene', {
9393
initMetaTags(this);
9494
initWakelock(this);
9595

96+
// Handler to exit VR (e.g., Oculus Browser back button).
97+
this.onVRPresentChangeBound = bind(this.onVRPresentChange, this);
98+
window.addEventListener('vrdisplaypresentchange', this.onVRPresentChangeBound);
99+
100+
// Bind functions.
101+
this.enterVRBound = function () { self.enterVR(); };
102+
this.exitVRBound = function () { self.exitVR(); };
103+
this.exitVRTrueBound = function () { self.exitVR(true); };
104+
this.pointerRestrictedBound = function () { self.pointerRestricted(); };
105+
this.pointerUnrestrictedBound = function () { self.pointerUnrestricted(); };
106+
107+
if (!isWebXRAvailable) {
108+
// Exit VR on `vrdisplaydeactivate` (e.g. taking off Rift headset).
109+
window.addEventListener('vrdisplaydeactivate', this.exitVRBound);
110+
111+
// Exit VR on `vrdisplaydisconnect` (e.g. unplugging Rift headset).
112+
window.addEventListener('vrdisplaydisconnect', this.exitVRTrueBound);
113+
114+
// Register for mouse restricted events while in VR
115+
// (e.g. mouse no longer available on desktop 2D view)
116+
window.addEventListener('vrdisplaypointerrestricted', this.pointerRestrictedBound);
117+
118+
// Register for mouse unrestricted events while in VR
119+
// (e.g. mouse once again available on desktop 2D view)
120+
window.addEventListener('vrdisplaypointerunrestricted',
121+
this.pointerUnrestrictedBound);
122+
}
123+
96124
// Camera set up by camera system.
97125
this.addEventListener('cameraready', function () {
98126
self.attachedCallbackPostCamera();
@@ -125,36 +153,6 @@ module.exports.AScene = registerElement('a-scene', {
125153

126154
// Add to scene index.
127155
scenes.push(this);
128-
129-
// Handler to exit VR (e.g., Oculus Browser back button).
130-
this.onVRPresentChangeBound = bind(this.onVRPresentChange, this);
131-
window.addEventListener('vrdisplaypresentchange', this.onVRPresentChangeBound);
132-
133-
// bind functions
134-
this.enterVRBound = function () { self.enterVR(); };
135-
this.exitVRBound = function () { self.exitVR(); };
136-
this.exitVRTrueBound = function () { self.exitVR(true); };
137-
this.pointerRestrictedBound = function () { self.pointerRestricted(); };
138-
this.pointerUnrestrictedBound = function () { self.pointerUnrestricted(); };
139-
140-
if (!isWebXRAvailable) {
141-
// Enter VR on `vrdisplayactivate` (e.g. putting on Rift headset).
142-
window.addEventListener('vrdisplayactivate', this.enterVRBound);
143-
144-
// Exit VR on `vrdisplaydeactivate` (e.g. taking off Rift headset).
145-
window.addEventListener('vrdisplaydeactivate', this.exitVRBound);
146-
147-
// Exit VR on `vrdisplaydisconnect` (e.g. unplugging Rift headset).
148-
window.addEventListener('vrdisplaydisconnect', this.exitVRTrueBound);
149-
150-
// Register for mouse restricted events while in VR
151-
// (e.g. mouse no longer available on desktop 2D view)
152-
window.addEventListener('vrdisplaypointerrestricted', this.pointerRestrictedBound);
153-
154-
// Register for mouse unrestricted events while in VR
155-
// (e.g. mouse once again available on desktop 2D view)
156-
window.addEventListener('vrdisplaypointerunrestricted', this.pointerUnrestrictedBound);
157-
}
158156
},
159157
writable: window.debug
160158
},

0 commit comments

Comments
 (0)