react-native-webview :- getUserMedia not working. It works without problem on a mobile browser but when I call a webpage via React-Native <Webview />
no request is shown to accept the permission.
const [url, setUrl] = useState(props.route.params.url);
const handleWebViewNavigationStateChange = (url: string = '') => {
if (
(url && url.includes(PORTAL_DASHBOARD_URL)) ||
url === PORTAL_DASHBOARD_URL
) {
setUrl(LOGOUT_URL); //ToDo: Remove if not needed
navigation.navigate('VirtualVisit');
}
if (url.includes(PORTAL_VIDEO_URL)) {
setUrl(url);
}
};
<WebView
ref={webViewRef}
source={{uri: url}}
javaScriptEnabled={true}
onLoadEnd={(syntheticEvent: WebViewEvent) => {
const {nativeEvent} = syntheticEvent;
if (url.includes(CUSTOM_URL)) {
//Workaround to request permssion. Works only on iOS, Android not working
if (nativeEvent.loading == false && reloadCount <= 1) {
webViewRef.current?.reload();
setCount(reloadCount + 1);
}
}
setLoaded(!nativeEvent.loading);
}}
onNavigationStateChange={(navigationState: WebViewNavigation) => {
handleWebViewNavigationStateChange(navigationState?.url);
}}
allowsInlineMediaPlayback={true}
mediaPlaybackRequiresUserAction={false}
originWhitelist={['*']}
userAgent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36"
onError={(e) => console.log('error: ', e)}
/>