diff --git a/example/index.tsx b/example/index.tsx index b2b7def..4417c5a 100644 --- a/example/index.tsx +++ b/example/index.tsx @@ -1,13 +1,123 @@ import '@bacons/text-decoder/install' -import { AppRegistry, View } from 'react-native' +import { useCallback, useState } from 'react' +import { AppRegistry } from 'react-native' +import { ActivityIndicator, Button, StyleSheet, Text, View } from 'react-native' import { WebSocket as FastWebSocket } from 'react-native-fast-ws' +type Result = { + outgoingTime: number + incomingTime: number + incomingFirstMessageTime: number +} + function App() { - return + return ( + + + + + ) } -AppRegistry.registerComponent('NitroPlayground', () => App) +function Results({ + fastResults, + wsResults, +}: { + title: string + fastResults: Result + wsResults: Result +}) { + return ( + + + + {`FastWS`} + {`WebSocket`} + + + + + + ) +} + +function ResultsRow({ + title, + fastResult, + wsResult, +}: { + title: string + fastResult: number + wsResult: number +}) { + const isFastBetter = fastResult < wsResult + return ( + + {title} + + + + ) +} + +function ResultItem({ result, isBetter }: { result: number; isBetter: boolean }) { + return ( + {`${result.toFixed(2)}`} + ) +} + +function TestCase({ payload, title }: { payload: string | ArrayBuffer; title: string }) { + const [fastResult, setFastResult] = useState(null) + const [wsResult, setWsResult] = useState(null) + const [loading, setLoading] = useState(false) + const runTest = useCallback(async () => { + if (loading) { + return + } + setLoading(true) + const fastRes = await testWebsocketMessages({ + // @ts-ignore + Ws: FastWebSocket, + outgoing: OUTGOING, + incoming: INCOMING, + payload, + }) + setFastResult(fastRes) + const wsRes = await testWebsocketMessages({ + Ws: WebSocket, + outgoing: OUTGOING, + incoming: INCOMING, + payload, + }) + setWsResult(wsRes) + setLoading(false) + }, [loading]) + + return ( + +