Howdy,
I need to know when the user has accepted camera permissions in Niantic Studio so I can begin the game.
I’m looking for the equivalent to this:
window.addEventListener(‘realityready’, () => {
console.log(‘Camera is ready and permission was granted’);
});
Any ideas?
window.addEventListener('xrloaded', () => {console.log('ready')})
Is what you’re looking for. 
1 Like
Hey George!
So the good news is the call back works, but unfortunately it gets called before the user gives camera permissions.
Is there by any chance another method?
Cheers!
You could try something like the following, however it would need to check in tick
since there’s no way to listen for the permission granted as far as I know.
async function onCameraPermissionGranted(onGranted) {
if (!navigator.permissions) return;
try {
const status = await navigator.permissions.query({ name: 'camera' });
if (status.state === 'granted') onGranted();
status.onchange = () => {
if (status.state === 'granted') onGranted();
};
} catch (err) {
console.error('Could not query camera permission:', err);
}
}
onCameraPermissionGranted(() => {
console.log('Camera permission is granted – go ahead and use the camera!');
});
1 Like
Are you sure that this works? Doesn’t seem like it’s firing if I add it in my component?
add: (world, component) => {
window.addEventListener('xrloaded', () => {
console.log('XR8 Engine Loaded. Ready for XR8 configurations.')
XR8.addCameraPipelineModule({
name: 'microphone',
requiredPermissions: () => ([XR8.XrPermissions.permissions().MICROPHONE]),
})
XR8.addCameraPipelineModule(XR8.MediaRecorder.pipelineModule())
console.log('should see mic permissions?')
})
},
it seems like adding it in add:
is not good practice because window is not available yet so I move it to .onEnter
and it seems ok.
1 Like