Skip to content

Commit 40135be

Browse files
authored
feat: upgrade dependencies to Nitro 0.14 and React Native 0.76 (#3)
* feat * readme updates * chore
1 parent 13e9d1a commit 40135be

33 files changed

+1798
-4668
lines changed

README.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ npm install react-native-fast-ws react-native-nitro-modules
1515
### TODOs
1616

1717
- Provide Android support
18-
- Upgrade dependencies to latest (yeah, I've been working on this for waaaay to long)
1918
- Fix outstanding (and known) issues
2019
- Figure out a better name and logo
2120
- Stable release at [React Native London Conf](https://www.reactnativelondon.co.uk)
@@ -36,3 +35,17 @@ If you want to contribute, please reach out (you can find me on [X/Twitter](http
3635
**Websockets**
3736
- On iOS, uses built-in APIs for WebSockets (available on iOS 13+). React Native uses `SocketRocket` instead
3837
- Does not use `EventEmitter` to communicate new messages back to the JavaScript. With Nitro, we can call callbacks directly
38+
39+
### Developing
40+
41+
Run the example app to test changes:
42+
43+
```bash
44+
// Start the demo server
45+
bun server.ts
46+
47+
// Run the app
48+
cd example && npm run ios
49+
```
50+
51+
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.

example/index.tsx renamed to example/App.tsx

+6-21
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
import '@bacons/text-decoder/install'
2-
31
import { useCallback, useState } from 'react'
4-
import { AppRegistry } from 'react-native'
52
import { ActivityIndicator, Button, StyleSheet, Text, View } from 'react-native'
63
import { WebSocket as FastWebSocket } from 'react-native-fast-ws'
74

85
type Result = {
96
outgoingTime: number
107
incomingTime: number
11-
incomingFirstMessageTime: number
128
}
139

14-
function App() {
10+
const encoder = new TextEncoder()
11+
12+
export function App() {
1513
return (
1614
<View style={styles.container}>
1715
<TestCase payload="Hello World" title="Test String" />
18-
<TestCase payload={new TextEncoder().encode('Hello World')} title="Test Binary" />
16+
<TestCase payload={encoder.encode('Hello World')} title="Test Binary" />
1917
</View>
2018
)
2119
}
@@ -32,8 +30,8 @@ function Results({
3230
<View>
3331
<View style={styles.resultRowContainer}>
3432
<Text style={styles.resultItem}> </Text>
35-
<Text style={styles.resultItem}>{`FastWS`}</Text>
36-
<Text style={styles.resultItem}>{`WebSocket`}</Text>
33+
<Text style={styles.resultItem}>FastWS</Text>
34+
<Text style={styles.resultItem}>WebSocket</Text>
3735
</View>
3836
<ResultsRow
3937
title="Sending (ms)"
@@ -45,11 +43,6 @@ function Results({
4543
fastResult={fastResults.incomingTime}
4644
wsResult={wsResults.incomingTime}
4745
/>
48-
<ResultsRow
49-
title="TFM (ms)"
50-
fastResult={fastResults.incomingFirstMessageTime}
51-
wsResult={wsResults.incomingFirstMessageTime}
52-
/>
5346
</View>
5447
)
5548
}
@@ -127,19 +120,16 @@ const testWebsocketMessages = async (opts: {
127120
}): Promise<{
128121
outgoingTime: number
129122
incomingTime: number
130-
incomingFirstMessageTime: number
131123
}> =>
132124
new Promise((resolve) => {
133125
const inst = new opts.Ws('ws://localhost:3000')
134126

135127
let outgoingTime: number
136128
let incomingTime: number
137-
let incomingFirstMessageTime: number
138129
let received = 0
139130

140131
inst.addEventListener('message', () => {
141132
if (received === 0) {
142-
incomingFirstMessageTime = performance.now() - incomingFirstMessageTime
143133
incomingTime = performance.now()
144134
}
145135

@@ -154,7 +144,6 @@ const testWebsocketMessages = async (opts: {
154144
resolve({
155145
outgoingTime,
156146
incomingTime: performance.now() - incomingTime,
157-
incomingFirstMessageTime,
158147
})
159148
})
160149

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

168157
outgoingTime = performance.now() - start
169158

170-
incomingFirstMessageTime = performance.now()
171-
172159
inst.send(JSON.stringify({ count: opts.incoming, binary: typeof opts.payload !== 'string' }))
173160
})
174161
})
@@ -194,5 +181,3 @@ const styles = StyleSheet.create({
194181
backgroundColor: 'red',
195182
},
196183
})
197-
198-
AppRegistry.registerComponent('NitroPlayground', () => App)

example/index.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import '@bacons/text-decoder/install'
2+
3+
import { AppRegistry } from 'react-native'
4+
5+
import { App } from './App'
6+
7+
AppRegistry.registerComponent('NitroPlayground', () => App)

0 commit comments

Comments
 (0)