Skip to content

Commit 269b65b

Browse files
committed
fix: update config and polyfills
1 parent b439626 commit 269b65b

File tree

5 files changed

+47
-33
lines changed

5 files changed

+47
-33
lines changed

App.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import { identify } from '@libp2p/identify'
1111
import { circuitRelayTransport } from '@libp2p/circuit-relay-v2'
1212
import { tcp } from '@libp2p/tcp'
1313
import { kadDHT } from '@libp2p/kad-dht'
14-
import * as filters from '@libp2p/websockets/filters'
15-
import debug from 'debug'
14+
import { ping } from '@libp2p/ping'
15+
import debug from 'weald'
1616

17-
debug.enable('libp2p:*,*:trace')
17+
debug.enable('libp2p:*')
1818

1919
export default function App () {
2020
const [libp2p, setLibp2p] = useState(null)
@@ -31,9 +31,7 @@ export default function App () {
3131
},
3232
transports: [
3333
circuitRelayTransport(),
34-
webSockets({
35-
filter: filters.all
36-
}),
34+
webSockets(),
3735
tcp()
3836
],
3937
connectionEncrypters: [
@@ -54,7 +52,8 @@ export default function App () {
5452
],
5553
services: {
5654
identify: identify(),
57-
kadDHT: kadDHT()
55+
kadDHT: kadDHT(),
56+
ping: ping()
5857
}
5958
})
6059

babel.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ module.exports = function (api) {
88
plugins: [
99
['module-resolver', {
1010
alias: {
11+
'buffer': '@craftzdog/react-native-buffer',
12+
'node:buffer': '@craftzdog/react-native-buffer',
1113
'crypto': 'react-native-quick-crypto',
1214
'node:crypto': 'react-native-quick-crypto',
13-
//'crypto': 'crypto-browserify',
14-
//'node:crypto': 'crypto-browserify',
1515
'stream': 'stream-browserify',
1616
'node:stream': 'stream-browserify',
1717
'net': 'react-native-tcp-socket',

globals.js

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@ global.process.version = 'v20.12.2'
77
import '@azure/core-asynciterator-polyfill'
88
import 'react-native-get-random-values'
99
import 'weakmap-polyfill'
10-
import { TextEncoder, TextDecoder } from 'text-encoding'
1110
import { EventTarget, Event } from 'event-target-shim'
1211
import { Buffer } from '@craftzdog/react-native-buffer'
1312
import { Crypto } from '@peculiar/webcrypto'
13+
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
1414

15-
global.TextEncoder = TextEncoder
16-
global.TextDecoder = TextDecoder
1715
global.EventTarget = EventTarget
1816
global.Event = Event
1917

@@ -48,8 +46,29 @@ global.AbortSignal.prototype.throwIfAborted = () => {
4846
global.Buffer = Buffer
4947
global.crypto.subtle = new Crypto().subtle
5048

51-
// this is not necessary for your app to run, but it helps when
52-
// tracking down broken polyfill modules
49+
/**
50+
* Polyfill missing ES2024 promise methods
51+
*
52+
* Ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/withResolvers
53+
*/
54+
global.Promise.withResolvers = global.Promise.withResolvers ?? (() => {
55+
let res
56+
let rej
57+
58+
const p = new Promise((resolve, reject) => {
59+
res = resolve
60+
rej = reject
61+
})
62+
63+
return {
64+
promise: p,
65+
resolve: res,
66+
reject: rej
67+
}
68+
})
69+
70+
// this is not necessary for your app to run, but it helps when tracking down
71+
// broken polyfill modules
5372
if (global.__fbBatchedBridge) {
5473
const origMessageQueue = global.__fbBatchedBridge;
5574
const modules = origMessageQueue._remoteModuleTable;
@@ -58,3 +77,9 @@ if (global.__fbBatchedBridge) {
5877
console.log(`The problematic line code is in: ${modules[moduleId]}.${methods[moduleId][methodId]}`)
5978
}
6079
}
80+
81+
// sometimes this is undefined, though perhaps only in the simulator
82+
// ref: https://github.com/craftzdog/react-native-quick-base64/issues/25
83+
global.base64FromArrayBuffer = global.base64FromArrayBuffer ?? ((buf) => {
84+
return uint8ArrayToString(new Uint8Array(buf, 0, buf.byteLength), 'base64')
85+
})

metro.config.js

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

package.json

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,31 @@
1616
"@libp2p/bootstrap": "^11.0.22",
1717
"@libp2p/circuit-relay-v2": "^3.1.12",
1818
"@libp2p/identify": "^3.0.18",
19-
"@libp2p/kad-dht": "^14.2.5",
19+
"@libp2p/kad-dht": "^15.1.3",
20+
"@libp2p/ping": "^2.0.33",
2021
"@libp2p/tcp": "^10.0.19",
2122
"@libp2p/webrtc": "^5.1.0",
2223
"@libp2p/websockets": "^9.1.5",
2324
"@peculiar/webcrypto": "^1.4.4",
24-
"@react-native/metro-config": "^0.74.85",
25+
"@react-native/metro-config": "^0.79.3",
2526
"babel-plugin-module-resolver": "^5.0.2",
26-
"crypto-browserify": "^3.12.0",
2727
"custom-event": "^1.0.1",
2828
"event-target-shim": "^6.0.2",
2929
"events": "^3.3.0",
30-
"expo": "~51.0.20",
31-
"expo-dev-client": "^4.0.20",
32-
"expo-splash-screen": "^0.27.5",
33-
"expo-status-bar": "^1.7.1",
30+
"expo": "^53.0.10",
31+
"expo-dev-client": "^5.2.0",
32+
"expo-splash-screen": "^0.30.9",
33+
"expo-status-bar": "^2.2.3",
3434
"libp2p": "^2.6.2",
3535
"os-browserify": "^0.3.0",
3636
"path-browserify": "^1.0.1",
3737
"process": "^0.11.10",
38-
"react": "18.2.0",
39-
"react-native": "^0.74.3",
38+
"react": "19.0.0",
39+
"react-native": "^0.79.3",
4040
"react-native-get-random-values": "^1.10.0",
4141
"react-native-quick-crypto": "^0.7.1",
4242
"react-native-tcp-socket": "^6.0.6",
4343
"stream-browserify": "^3.0.0",
44-
"text-encoding": "^0.7.0",
4544
"vm-browserify": "^1.1.2",
4645
"weakmap-polyfill": "^2.0.4"
4746
},

0 commit comments

Comments
 (0)