Closed mvayngrib closed 8 years ago
Cool! I tried (as a test) to include webtorrent, that started working a bit after adding you shim
if (typeof __dirname === 'undefined') global.__dirname = '/'
if (typeof __filename === 'undefined') global.__filename = ''
if (typeof process === 'undefined') {
global.process = require('process')
} else {
var bProcess = require('process')
for (var p in bProcess) {
if (!(p in process)) {
process[p] = bProcess[p]
}
}
}
global.location = { host: 'react-native' }
process.browser = true
if (typeof Buffer === 'undefined') global.Buffer = require('buffer').Buffer
// global.location = global.location || { port: 80 }
var isDev = typeof __DEV__ === 'boolean' && __DEV__
process.env.NODE_ENV = isDev ? 'development' : 'production'
if (typeof localStorage !== 'undefined') {
localStorage.debug = isDev ? '*' : ''
}
(note that I had to set process.browser to true)
And I added react-native-webrtc, initialized it with: new WebTorrent({ wrtc: require('react-native-webrtc') })
That brought me to the error that createDataChannel
was not available (which is correct)
To get that far I had to add this: https://github.com/vespakoen/node-haste/commit/cf9f1aa428871e90029ea19bd8f86064ba326383#diff-9103f1ac13c3018f7108b3e6bbf20df4R86
I still feel like spelunking when I am working on node-haste, not exactly sure what is going on. I think it's time for somebody from facebook to step in and fix it, I guess our intentions are clear now =)
Thanks for your help!
Added them this project
shims you may want to include (from rn-nodeify):
react-native-udp - dgram shim react-native-tcp - net shim react-native-level-fs - fs shim react-native-crypto - crypto-browserify with replaced randomBytes react-native-http - can't remember what i changed exactly
also, speaking from experience writing rn-nodeify, there's a bunch of things in other people's packages that will set off errors in the react-native packager, e.g.
return
statements not written within functions, or...I need to revisit rn-nodeify to remember. Not sure how to deal with that yet. I submitted some PRs, but that takes time, and if it's a dep of a dep of a dep, it can take forever for it to propagate.