This repository was archived by the owner on Dec 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathApp.js
More file actions
47 lines (43 loc) · 1.65 KB
/
App.js
File metadata and controls
47 lines (43 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import React, { useState } from 'react';
import { StyleSheet, View, Text, Button } from 'react-native';
import { WebView } from 'react-native-webview';
import { ORG, WORLD_ID } from './config';
import ExampleStartScreen from './ExampleStartScreen';
export default function App() {
const [showWebView, setShowWebView] = useState(false);
// Monkey patch - this is required to prevent GFN classifying the device as unknown, which would result in session being aborted
const inject = `(function() {
const originalSetRequestHeader = XMLHttpRequest.prototype.setRequestHeader;
XMLHttpRequest.prototype.setRequestHeader = function(header, value) {
if(header === "nv-browser-type") {
value = "SAFARI";
console.log("nv-browser-type header is set to SAFARI");
}
return originalSetRequestHeader.apply(this, arguments);
};
})();`
const webViewUri = `https://${ORG}.m2worlds.io/worlds/${WORLD_ID}`
return (
<View style={styles.container}>
{showWebView ? (
<WebView
injectedJavaScriptBeforeContentLoaded={inject}
webviewDebuggingEnabled={true}
source={{ uri: webViewUri }}
scrollEnabled={true}
allowsFullscreenVideo={false}
userAgent="Mozilla/5.0 (iPhone; CPU iPhone OS 17_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Mobile/15E148 Safari/604.1"
allowsInlineMediaPlayback={true}
/>
) : (
<ExampleStartScreen onPress={() => setShowWebView(true)} />
)}
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
},
});