nodertc / stun

Low-level Session Traversal Utilities for NAT (STUN) client and server
MIT License
160 stars 29 forks source link

Compatibility with REACT #22

Open cfabio opened 5 years ago

cfabio commented 5 years ago

Hi, I am trying to use this library in an Electron + React project I am developing. For some reason everything works nicely as long as I run the application in debug mode, if I try to run the production ready compiled binary of the app I get and empty blank window. Do you have any clue on why this might be happening? I am at a loss here, can't really find a solution. Thanks

reklatsmasters commented 5 years ago

There is no need some extra compatibility. Why do you think your problem related to stun? Try to check stderr, console, wtv. I'm not an extrasensory.

cfabio commented 5 years ago

I think it has to do with this library because the moment I import it the UI stops working; stdout and stderr are empty.

reklatsmasters commented 5 years ago

I don’t know how to help you. If electron do not print errors, probably there is not errors.

cfabio commented 5 years ago

I managed to debug the production code using some third party library. The issue seems to be related to how "stun" and related libraries import each other. See attached screenshot. screenshot_2019-06-06_at_11 10 43

reklatsmasters commented 5 years ago

Your module loader should follow nodejs module loader rules. NodeJS trying to add node_modules folder to each one starting from main file folder. See nodejs docs. I don’t known how to work Electron’s module resolver.

bhspencer commented 4 years ago

I am also running this stun library in an electron app and believe I have a related issue.

I am able to run this stun library if I am in the main process but not if I am in a render process. The render process is using a content security policy that prevents the execution of the transitive dependency called generate-function:

└─┬ stun@2.1.0 ├─┬ binary-data@0.6.0 │ ├─┬ generate-function@2.3.1

In particular generate-function uses eval() which is prohibited by the security policy for reasonable reasons.

This is unfortunate as in order to get my public ip in the render process I have to set up a bunch of inter process communication to the main process. I would prefer to not have to do that.

reklatsmasters commented 4 years ago

generate-function used for runtime generate buffer to integer parsers. It gives maximal performance. Anyway, this related to generate-function module. @bhspencer

bhspencer commented 4 years ago

@reklatsmasters I could imagine that generate-function provides maximal convenience. STUN packets are not particularly complicated, the maximally preferment way of decoding STUN messages from a buffer would be to write an explicit decoder rather than use eval().

ilittle-cnri commented 4 years ago

FYI, I ran into the issue describe by @cfabio as well. I believe the issue is a bug in electron-builder that's causing it to strip out nested node_modules folders, which breaks this package. See https://github.com/electron-userland/electron-builder/issues/3185

If I build with electron-forge, it leaves the nested node_modules alone and the stun package works just fine in the production Electron+React app.

Anyway, upshot is, @reklatsmasters I think you can close this issue. It's not a node-stun bug, it's an electron-builder bug.