Skip to content

feat: upgrade dependencies to Nitro 0.14 and React Native 0.76 #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ npm install react-native-fast-ws react-native-nitro-modules
### TODOs

- Provide Android support
- Upgrade dependencies to latest (yeah, I've been working on this for waaaay to long)
- Fix outstanding (and known) issues
- Figure out a better name and logo
- Stable release at [React Native London Conf](https://www.reactnativelondon.co.uk)
Expand All @@ -36,3 +35,17 @@ If you want to contribute, please reach out (you can find me on [X/Twitter](http
**Websockets**
- On iOS, uses built-in APIs for WebSockets (available on iOS 13+). React Native uses `SocketRocket` instead
- Does not use `EventEmitter` to communicate new messages back to the JavaScript. With Nitro, we can call callbacks directly

### Developing

Run the example app to test changes:

```bash
// Start the demo server
bun server.ts

// Run the app
cd example && npm run ios
```

You can also start the app from Xcode, in case you want to make changes to the native code. In that case, open `example/ios/NitroPlayground.xcworkspace` and hit run.
27 changes: 6 additions & 21 deletions example/index.tsx → example/App.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import '@bacons/text-decoder/install'

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() {
const encoder = new TextEncoder()

export function App() {
return (
<View style={styles.container}>
<TestCase payload="Hello World" title="Test String" />
<TestCase payload={new TextEncoder().encode('Hello World')} title="Test Binary" />
<TestCase payload={encoder.encode('Hello World')} title="Test Binary" />
</View>
)
}
Expand All @@ -32,8 +30,8 @@ function Results({
<View>
<View style={styles.resultRowContainer}>
<Text style={styles.resultItem}> </Text>
<Text style={styles.resultItem}>{`FastWS`}</Text>
<Text style={styles.resultItem}>{`WebSocket`}</Text>
<Text style={styles.resultItem}>FastWS</Text>
<Text style={styles.resultItem}>WebSocket</Text>
</View>
<ResultsRow
title="Sending (ms)"
Expand All @@ -45,11 +43,6 @@ function Results({
fastResult={fastResults.incomingTime}
wsResult={wsResults.incomingTime}
/>
<ResultsRow
title="TFM (ms)"
fastResult={fastResults.incomingFirstMessageTime}
wsResult={wsResults.incomingFirstMessageTime}
/>
</View>
)
}
Expand Down Expand Up @@ -127,19 +120,16 @@ const testWebsocketMessages = async (opts: {
}): Promise<{
outgoingTime: number
incomingTime: number
incomingFirstMessageTime: number
}> =>
new Promise((resolve) => {
const inst = new opts.Ws('ws://localhost:3000')

let outgoingTime: number
let incomingTime: number
let incomingFirstMessageTime: number
let received = 0

inst.addEventListener('message', () => {
if (received === 0) {
incomingFirstMessageTime = performance.now() - incomingFirstMessageTime
incomingTime = performance.now()
}

Expand All @@ -154,7 +144,6 @@ const testWebsocketMessages = async (opts: {
resolve({
outgoingTime,
incomingTime: performance.now() - incomingTime,
incomingFirstMessageTime,
})
})

Expand All @@ -167,8 +156,6 @@ const testWebsocketMessages = async (opts: {

outgoingTime = performance.now() - start

incomingFirstMessageTime = performance.now()

inst.send(JSON.stringify({ count: opts.incoming, binary: typeof opts.payload !== 'string' }))
})
})
Expand All @@ -194,5 +181,3 @@ const styles = StyleSheet.create({
backgroundColor: 'red',
},
})

AppRegistry.registerComponent('NitroPlayground', () => App)
7 changes: 7 additions & 0 deletions example/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import '@bacons/text-decoder/install'

import { AppRegistry } from 'react-native'

import { App } from './App'

AppRegistry.registerComponent('NitroPlayground', () => App)
Loading