Let say I have a web application with a camera library Instrascan running on my local server + HTTPS (use a self-signed certificate).
I would like to make the ReactNative WebView to run the web app from my local server and now the problem I'm facing is the Instascan lib tries to call navigator.mediaDevices.enumerateDevices() function to get media devices e.g. Camera and Microphone (with HTTP the result of enumerateDevices() is always an empty array)
so when the ReactNative WebView open my app from my local server (URL=https://192.168.1.200:9999) I got an error below:
{"canGoBack": false, "canGoForward": false, "code": 3, "description": "SSL error: The certificate authority is not trusted", "loading": false, "target": 9, "title": "", "url": "https://192.168.1.200:9999"}
I have added a network_security_config to android/app/src/main/res/xml/network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
</network-security-config>
This is my AndroidManifest.xml file
<manifest ...>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application ... android:networkSecurityConfig="@xml/network_security_config">
...
</application>
</manifest>
this is my react-native webview component
<WebView
source={{ uri: 'https://192.168.1.200:9999' }}
javaScriptEnabled
allowsInlineMediaPlayback
mediaPlaybackRequiresUserAction={false}
originWhitelist={['*']}
useWebKit
startInLoadingState
scalesPageToFit
onError={syntheticEvent => {
const { nativeEvent } = syntheticEvent;
console.warn('WebView error: ', nativeEvent);
}}
/>
here are my dependencies:
"@react-native-community/masked-view": "^0.1.10"
"@react-navigation/native": "^5.7.1"
"@react-navigation/stack": "^5.7.1"
"prop-types": "^15.7.2"
"react": "16.13.1"
"react-native": "0.63.2"
"react-native-camera": "^3.35.0"
"react-native-gesture-handler": "^1.7.0"
"react-native-permissions": "^2.1.5"
"react-native-reanimated": "^1.10.1"
"react-native-safe-area-context": "^3.1.1"
"react-native-screens": "^2.9.0"
"react-native-webview": "^10.3.2"
to summarize my problem now I'm facing these 2 problems:
- the problem of
SSL error: The certificate authority is not trustedwhen using a self-signed certificate. - When I tried some web app for camera testing below the camera seem to work but it cannot stream an images. it only shows a static image of the first image while initialize the camera.
- https://turncameraon.com/
- https://webcamtests.com/
- https://marcusbelcher.github.io/wasm-asm-camera-webgl-test/index.html
Please anybody give me some advices?
Thank you