Skip to content

Commit fa253e3

Browse files
committed
Update React Native, shrink connection code
1 parent 0846183 commit fa253e3

5 files changed

Lines changed: 424 additions & 303 deletions

File tree

android/app/src/main/java/com/enderchat/MainApplication.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@ class MainApplication : Application(), ReactApplication {
1818

1919
override val reactNativeHost: ReactNativeHost =
2020
object : DefaultReactNativeHost(this) {
21-
override fun getPackages(): List<ReactPackage> {
22-
val packages = PackageList(this).packages
23-
// Packages that cannot be autolinked yet can be added manually here, for example:
24-
// packages.add(new MyReactNativePackage());
25-
packages.add(NavBarColorPackage())
26-
packages.add(ConnectionPackage())
27-
return packages
28-
}
21+
override fun getPackages(): List<ReactPackage> =
22+
PackageList(this).packages.apply {
23+
// Packages that cannot be autolinked yet can be added manually here, for example:
24+
// add(new MyReactNativePackage())
25+
add(NavBarColorPackage())
26+
add(ConnectionPackage())
27+
}
2928

3029
override fun getJSMainModuleName(): String = "index"
3130

android/app/src/main/java/com/enderchat/modules/connection/ConnectionModule.kt

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,6 @@ class ConnectionModule(reactContext: ReactApplicationContext)
189189
return@launch
190190
}
191191

192-
// Calculate the necessary packet IDs.
193-
val is1164 = protocolVersion >= PROTOCOL_VERSION_1164
194-
val is117 = protocolVersion >= PROTOCOL_VERSION_117
195-
val is119 = protocolVersion >= PROTOCOL_VERSION_119
196-
val is1191 = protocolVersion >= PROTOCOL_VERSION_1191
197-
val is1193 = protocolVersion >= PROTOCOL_VERSION_1193
198-
val is1194 = protocolVersion >= PROTOCOL_VERSION_1194
199-
val is1202 = protocolVersion >= PROTOCOL_VERSION_1202
200-
val is1203 = protocolVersion >= PROTOCOL_VERSION_1203
201192
// Login state packet IDs
202193
val loginSuccessId = 0x02
203194
val loginAcknowledgedId = 0x03
@@ -209,30 +200,30 @@ class ConnectionModule(reactContext: ReactApplicationContext)
209200
val finishConfigurationServerBoundId = 0x02
210201
// Play state packet IDs
211202
val startConfigurationClientBoundId =
212-
if (is1203) 0x67
213-
else if (is1202) 0x65
203+
if (protocolVersion >= PROTOCOL_VERSION_1203) 0x67
204+
else if (protocolVersion >= PROTOCOL_VERSION_1202) 0x65
214205
else -1
215206
val acknowledgeConfigurationServerBoundId =
216-
if (is1202) 0x0b
207+
if (protocolVersion >= PROTOCOL_VERSION_1202) 0x0b
217208
else -1
218209
val playKeepAliveClientBoundId =
219-
if (is1202) 0x24
220-
else if (is1194) 0x23
221-
else if (is1193) 0x1f
222-
else if (is1191) 0x20
223-
else if (is119) 0x1e
224-
else if (is117) 0x21
225-
else if (is1164) 0x1f
210+
if (protocolVersion >= PROTOCOL_VERSION_1202) 0x24
211+
else if (protocolVersion >= PROTOCOL_VERSION_1194) 0x23
212+
else if (protocolVersion >= PROTOCOL_VERSION_1193) 0x1f
213+
else if (protocolVersion >= PROTOCOL_VERSION_1191) 0x20
214+
else if (protocolVersion >= PROTOCOL_VERSION_119) 0x1e
215+
else if (protocolVersion >= PROTOCOL_VERSION_117) 0x21
216+
else if (protocolVersion >= PROTOCOL_VERSION_1164) 0x1f
226217
else -1
227218
val playKeepAliveServerBoundId =
228-
if (is1203) 0x15
229-
else if (is1202) 0x14
230-
else if (is1194) 0x12
231-
else if (is1193) 0x11
232-
else if (is1191) 0x12
233-
else if (is119) 0x11
234-
else if (is117) 0x0f
235-
else if (is1164) 0x10
219+
if (protocolVersion >= PROTOCOL_VERSION_1203) 0x15
220+
else if (protocolVersion >= PROTOCOL_VERSION_1202) 0x14
221+
else if (protocolVersion >= PROTOCOL_VERSION_1194) 0x12
222+
else if (protocolVersion >= PROTOCOL_VERSION_1193) 0x11
223+
else if (protocolVersion >= PROTOCOL_VERSION_1191) 0x12
224+
else if (protocolVersion >= PROTOCOL_VERSION_119) 0x11
225+
else if (protocolVersion >= PROTOCOL_VERSION_117) 0x0f
226+
else if (protocolVersion >= PROTOCOL_VERSION_1164) 0x10
236227
else -1
237228

238229
// Re-use the current thread, start reading from the socket.
@@ -283,7 +274,7 @@ class ConnectionModule(reactContext: ReactApplicationContext)
283274
compressionThreshold = threshold
284275
compressionEnabled = threshold >= 0
285276
} else if (packet.id.value == loginSuccessId && state == ConnectionState.LOGIN) {
286-
state = if (is1202) {
277+
state = if (protocolVersion >= PROTOCOL_VERSION_1202) {
287278
directlyWritePacket(loginAcknowledgedId, ByteArray(0))
288279
ConnectionState.CONFIGURATION
289280
} else ConnectionState.PLAY

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"test": "jest",
1212
"lint": "tsc && eslint ."
1313
},
14-
"packageManager": "yarn@4.0.1",
14+
"packageManager": "yarn@4.0.2",
1515
"engines": {
1616
"node": ">=18"
1717
},
@@ -28,7 +28,7 @@
2828
"buffer": "^6.0.3",
2929
"events": "^3.3.0",
3030
"react": "18.2.0",
31-
"react-native": "0.73.0",
31+
"react-native": "0.73.2",
3232
"react-native-crypto": "^2.2.0",
3333
"react-native-pager-view": "^6.2.0",
3434
"react-native-randombytes": "^3.6.1",
@@ -46,10 +46,10 @@
4646
"@babel/core": "^7.22.9",
4747
"@babel/preset-env": "^7.22.9",
4848
"@babel/runtime": "^7.22.6",
49-
"@react-native/babel-preset": "^0.73.18",
50-
"@react-native/eslint-config": "^0.73.1",
51-
"@react-native/metro-config": "^0.73.2",
52-
"@react-native/typescript-config": "^0.73.1",
49+
"@react-native/babel-preset": "0.73.19",
50+
"@react-native/eslint-config": "0.73.2",
51+
"@react-native/metro-config": "0.73.3",
52+
"@react-native/typescript-config": "0.73.1",
5353
"@types/jest": "^29.5.3",
5454
"@types/metro-config": "^0.76.3",
5555
"@types/node": "^20.4.2",

react-native.config.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)