Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require not defined #7

Open
louptheron opened this issue Mar 20, 2016 · 10 comments
Open

Require not defined #7

louptheron opened this issue Mar 20, 2016 · 10 comments
Assignees

Comments

@louptheron
Copy link

After a successful npm install freedom-port-control and npm install freedom-for-node, running :

var freedom = require('freedom-for-node');
var portcontrol = freedom('node_modules/freedom-port-control/src/port-control.json');

give me an error :
TypeError: freedom is not a function

Running :
var portcontrol = freedom.freedom('node_modules/freedom-port-control/src/port-control.json');

I have this error :
[ReferenceError: require is not defined]

Do you know why ?

Thank you

@willscott
Copy link
Member

looks like the second line is actually

 var portcontrol = freedom.freedom('node_modules/freedom-port-control/dist/port-control.json');

@louptheron
Copy link
Author

it give me no error, but when I test :

var freedom = require('freedom-for-node');
var portcontrol = freedom.freedom('node_modules/freedom-port-control/dist/port-control.json');
portcontrol.probeProtocolSupport();

there is

TypeError: portcontrol.probeProtocolSupport is not a function

Result of a console.log(portcontrol) :

lib$es6$promise$promise$$Promise {
  _id: 0,
  _state: undefined,
  _result: undefined,
  _subscribers: [] }

@willscott
Copy link
Member

you probably have a promise that resolves to the expected interface. Sorry - all of the calls will be asynchronous promises, rather than direct returns.

var freedom = require('freedom-for-node');
freedom('node_modules/freedom-port-control/dist/port-control.json').then(function(portControl) {
  return portControl.probeProtocolSupport();
}).then(function(support) {
  console.log(support);
});

@louptheron
Copy link
Author

Ok, I followed the code example and the freedom-port-control module is loaded (got it for the promise, thank you) :

require('freedom-for-node').freedom('node_modules/freedom-port-control/dist/port-control.json', {}).then(function(Root){
        var root = new Root();
        root.probeProtocolSupport().then(function(res){
            console.log(res);
        });
    });

but I got new errors :

Cannot instantiate provider, since it is not provided
[unbound Provider] dropping message {"to":8,"type":"message","message":{"action":"method","type":"createDataChannel","reqId":0,"text":["dummy data channel",null],"binary":[]}}
Cannot instantiate provider, since it is not provided
[unbound Provider] dropping message {"to":9,"type":"message","message":{"action":"method","type":"createDataChannel","reqId":0,"text":["dummy data channel",null],"binary":[]}}
[unbound Provider] dropping message {"to":8,"type":"message","message":{"action":"method","type":"close","reqId":1,"text":[],"binary":[]}}
[unbound Provider] dropping message {"to":9,"type":"message","message":{"action":"method","type":"close","reqId":1,"text":[],"binary":[]}}
UPnP failed at: URL is not defined

It seems that _getUpnpControlUrl() does not give the expected controlUrl as expected, maybe with a bad Ssdp response.

@willscott
Copy link
Member

Sigh. Didn't realize this code had a dependency on WebRTC - probably to learn your external IP address through the STUN process.

I don't think i've ever made that work in a reliable way in node.js, although that's probably worth doing. The alternative is to not use STUN, or use it as a UDP protocol rather than bundled in webRTC.

@willscott willscott self-assigned this Mar 21, 2016
@louptheron
Copy link
Author

Mhm ok, thank you for your help !

@kennysong
Copy link
Member

Actually, I think this error is because we're using the URL interface that's only supported in Chrome or Firefox, and not in node. This was fine since our initial use case was only in browser apps.

From a quick look, it seems like URL is only used on one line here, so it should be fairly easy to substitute out and remove this dependency.

Also, if I recall correctly, WebRTC is only used to determine the private IPs of the computer, which is done by gathering ICE candidates on a dummy data channel – no STUN servers are actually used.

@kennysong kennysong reopened this Mar 22, 2016
@louptheron
Copy link
Author

In fact, it is easy remove the URL interface here and here, but XMLHttpRequest is used there, and is not implemented by the node Javascript engine.

@kennysong
Copy link
Member

Yeah, it looks like there will be minor incompatibilities with the current code and node. @willscott what do you think is the best way to deal with this?

@bemasc
Copy link
Contributor

bemasc commented Mar 22, 2016

If you need XMLHttpRequest in a freedom module, you might like https://github.com/uproxy/freedom-xhr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants