Skip to content

Commit 2a0fb01

Browse files
authored
Update Babylon Native for native camera fixes (#505)
1 parent cd91d2e commit 2a0fb01

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

Apps/Playground/0.69/ios/Playground/Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
5+
<key>NSCameraUsageDescription</key>
6+
<string>Used to render the camera into the Babylon Scene</string>
57
<key>CFBundleDevelopmentRegion</key>
68
<string>en</string>
79
<key>CFBundleDisplayName</key>
Submodule BabylonNative updated 54 files

Modules/@babylonjs/react-native/EngineHook.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Platform } from 'react-native';
33
import { PERMISSIONS, check, request } from 'react-native-permissions';
44
import { Engine, WebXRSessionManager, WebXRExperienceHelper, Color4, Tools, VideoTexture } from '@babylonjs/core';
55
import { ReactNativeEngine } from './ReactNativeEngine';
6+
import { ensureInitialized } from './BabylonModule';
67

78
import * as base64 from 'base-64';
89

@@ -71,17 +72,19 @@ async function requestCameraPermissionAsync() : Promise<void> {
7172
}
7273
}
7374

74-
// Override the VideoTexture.CreateFromWebCamAsync to insert a camera permissions request. It would be cleaner to do this directly in the NativeCamera implementation, but there are a couple problems with that:
75-
// 1. React Native does not provide a way to hook into the permissions request result (at least on Android).
76-
// 2. If it is done on the native side, then we need one implementation per platform.
77-
{
78-
const originalCreateFromWebCamAsync = VideoTexture.CreateFromWebCamAsync;
79-
VideoTexture.CreateFromWebCamAsync = async function (...args: Parameters<typeof originalCreateFromWebCamAsync>): ReturnType<typeof originalCreateFromWebCamAsync> {
80-
await requestCameraPermissionAsync();
75+
ensureInitialized().then(() => {
76+
// Override the navigator.mediaDevices.getUserMedia to insert a camera permissions request. It would be cleaner to do this directly in the NativeCamera implementation, but there are a couple problems with that:
77+
// 1. React Native does not provide a way to hook into the permissions request result (at least on Android).
78+
// 2. If it is done on the native side, then we need one implementation per platform.
79+
{
80+
const originalGetUserMedia = navigator.mediaDevices.getUserMedia;
81+
navigator.mediaDevices.getUserMedia = async function (...args: Parameters<typeof originalGetUserMedia>): ReturnType<typeof originalGetUserMedia> {
82+
await requestCameraPermissionAsync();
8183

82-
return originalCreateFromWebCamAsync.apply(this, args);
84+
return originalGetUserMedia.apply(this, args);
85+
}
8386
}
84-
}
87+
});
8588

8689
if (Platform.OS === "android" || Platform.OS === "ios") {
8790
const originalEnterXRAsync: (...args: any[]) => Promise<WebXRSessionManager> = WebXRExperienceHelper.prototype.enterXRAsync;

Modules/@babylonjs/react-native/shared/BabylonNative.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ namespace BabylonNative
5454
m_nativeInput = &Babylon::Plugins::NativeInput::CreateForJavaScript(m_env);
5555
Babylon::Plugins::NativeOptimizations::Initialize(m_env);
5656
Babylon::Plugins::NativeTracing::Initialize(m_env);
57-
Babylon::Plugins::Camera::Initialize(m_env);
57+
Babylon::Plugins::NativeCamera::Initialize(m_env);
5858

5959
// Initialize Babylon Native polyfills
6060
Babylon::Polyfills::Window::Initialize(m_env);

0 commit comments

Comments
 (0)