This example demonstrates how to integrate the SpeedOf.Me speed test API into a React Native app using react-native-webview.
The SpeedOf.Me API is JavaScript-based, so React Native apps use WebView to:
onMessage propnpm install react-native-webview
# For iOS
cd ios && pod install
SomApi.account = "YOUR_API_KEY";
SomApi.domainName = "your-domain.com";
Option A: Remote URL (Recommended)
const webViewSource = { uri: 'https://your-domain.com/speedtest.html' };
Option B: Inline HTML
const webViewSource = { html: SPEED_TEST_HTML };
React Native App
└── SpeedTestScreen
└── WebView (react-native-webview)
└── speedtest.html
└── SomApi.js
▼
window.ReactNativeWebView.postMessage(json)
▼
onMessage={(event) => {...}}
The HTML page sends messages via:
window.ReactNativeWebView.postMessage(JSON.stringify({
type: 'completed',
data: result
}));
React Native receives them:
<WebView
onMessage={(event) => {
const message = JSON.parse(event.nativeEvent.data);
// Handle message
}}
/>
interface SpeedTestResult {
download: number;
upload: number;
latency: number;
jitter: number;
testServer?: string;
ip_address?: string;
hostname?: string;
}
npx expo install react-native-webview
javaScriptEnabled={true}window.ReactNativeWebView exists in HTML