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

undefined is not an object (evaluating 'global.WebSocket') #8

Closed
seiyria opened this issue May 18, 2015 · 24 comments
Closed

undefined is not an object (evaluating 'global.WebSocket') #8

seiyria opened this issue May 18, 2015 · 24 comments

Comments

@seiyria
Copy link

seiyria commented May 18, 2015

This is probably me doing something dumb, but I'm unable to get this working on the client. What I did:

  • npm install socketcluster-client
  • cd node_modules/socketcluster-client
  • browserify -s socketCluster index.js > socketcluster.js

and include that file.

I've also tried just using the socketcluster.js file from the repo, but that seems to fail when I attempt to use the socket like so:

var socket = window.socketCluster.connect({hostname: 'localhost', port: 8000});
console.log(socket.state); //undefined

And in my server:

module.exports.run = function (worker) {
  var scServer = worker.scServer;

  scServer.on('connection', function (socket) {
    console.log('client connect');

    socket.on('login', function(credentials, respond) {
      console.log('begin login', credentials);
    });

  });
};

But I get nothing in my browser console, except eventually, I get an xhr polling error. Not sure how to get started with this.

@jondubois
Copy link
Member

@seiyria In your console do:
npm remove -g socketcluster
then
npm cache clean

Then follow these steps exactly:
http://socketcluster.io/#!/docs/getting-started

@seiyria
Copy link
Author

seiyria commented May 18, 2015

I did that exactly, see my project here (it's pretty minimal so far).

@jondubois
Copy link
Member

@seiyria Did you run the socketcluster create myappname command afterwards?

@seiyria
Copy link
Author

seiyria commented May 18, 2015

@jondubois No, I ran that to generate the project shown above, then I removed the server / serve-static part of it as this will just be a dedicated backend (the frontend is an app).

@jondubois
Copy link
Member

@seiyria So you don't want SC to serve the client file (socketcluster.js) - You want to serve it from somewhere else?

@seiyria
Copy link
Author

seiyria commented May 18, 2015

@jondubois Yes, I was under the impression that it was a client and the client could be served from anywhere else. Based on your reaction, I suspect that won't work so well. I suppose I could serve just the js file from there and have the app include it, but I prefer to not have external assets (I think Apple has a policy against that, so my app would probably get rejected).

@jondubois
Copy link
Member

That is possible - You can get the client separately and serve it up from anywhere, but it's a bit trickier to setup (manual). Did you use the socketcluster.js file that is inside socketcluster-client/ repo?

@seiyria
Copy link
Author

seiyria commented May 18, 2015

Yeah, I've tried that as well. My basic code to reproduce was above. It didn't seem to establish a connection.

@jondubois
Copy link
Member

@seiyria Note sure if that could explain the problem but I noticed that there was an outdated socketcluster.js client inside the socketcluster/sample/ app - This was an accident - I removed that file from the module on npm. You should only use the one from the https://github.com/TopCloud/socketcluster-client repo.

@seiyria
Copy link
Author

seiyria commented May 18, 2015

Absolutely, that's the one I was using.

@jondubois
Copy link
Member

What OS are you using?

@seiyria
Copy link
Author

seiyria commented May 18, 2015

I'm on OSX for dev. Originally, I tried hosting the server on my linux VM on my windows machine across the network, but I eventually moved it all to my OSX machine to eliminate possible network problems as a cause (though once I have something working I will revisit getting that working).

@jondubois
Copy link
Member

Is your HTTP server running on the same host/domain as the socketcluster server?

@seiyria
Copy link
Author

seiyria commented May 18, 2015

Yes, currently it is. I'm trying to establish the connection via localhost:8000.

@jondubois
Copy link
Member

What do you get when you run socketcluster -v?

@seiyria
Copy link
Author

seiyria commented May 18, 2015

Oh, wait, shoot. Something I'll have to take a look at later, actually, I don't think it is. It's running in the iOS simulator, which simulates a device. localhost would probably refer to that device, not the host machine. That doesn't explain why it couldn't connect when given a specific IP, though.

Sorry, this might be a total non-issue; I didn't even think about that. I'll try to resolve this when I'm at my machine next.

Thanks for your support so far!

@jondubois
Copy link
Member

Ok. Let me know.
Thanks for reporting.
If in doubt, raise an issue :)))

@seiyria
Copy link
Author

seiyria commented May 18, 2015

Hey, so I double checked. Apparently iOS simulator uses the host network, ie, localhost definitely refers to the machine currently running the server.

@jondubois
Copy link
Member

So you didn't manage to get it working on any platform? Did you try to run on Windows directly?

It would be interesting to know what's causing this. I might play around with serving the file from a different origin than the SC server just to see what happens - This should be supported by default though.

@seiyria
Copy link
Author

seiyria commented May 18, 2015

I have not (I actually have no development tools available to me on windows by design).

It'd be difficult for me to run it all in just linux, as well, as I was unable to get the android simulator working and I can't get the ios simulator on it, so that unfortunately leaves me stuck on OSX. My project is an Ionic app, I should also add. I don't know if that makes a difference though.

Sure, I mean if it works for you, I'm probably screwing something up, but .. who knows.

@jondubois
Copy link
Member

@seiyria I noticed in your first post, you mentioned an 'xhr poll' error - This suggests that you are using version 1.x.x of the client and not the latest 2.x.x version. Could you be using the SC1 client with the SC2 server? The two versions have the same external API but are protocol-incompatible.

Unfortunately, the version number isn't anywhere in the client script (yet) - But to check you can open the socketcluster.js client file and search for the string 'engine.io' - If there are any matches, then it means that you are using v1 of the client.

If that's the issue, make sure you do npm cache clean and then npm install socketcluster-client then get the socketcluster.js file from there - This will be version 2.

npm packages and git branches for SC1 and SC2 have moved around about one or two weeks ago so this could have caused cache issues with npm.

Maybe that's the issue.

@seiyria
Copy link
Author

seiyria commented May 19, 2015

Absolutely, thank you. I will give this a try when I get back and let you know the results. I was out of ideas!

@seiyria
Copy link
Author

seiyria commented May 19, 2015

Ah, I figured out why. I bower installed your repo, but you never pushed tags to it, so I got 0.9. I'll try now and see if it works!

@seiyria
Copy link
Author

seiyria commented May 19, 2015

Yep, and it definitely works now! Thanks for pointing that out. When you attend to #7, make sure you push all your tags :P

Thanks a ton!

@seiyria seiyria closed this as completed May 19, 2015
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

2 participants