hapijs / nes

WebSocket adapter plugin for hapi routes
Other
502 stars 87 forks source link

Client Doesn't Work With Node? #258

Closed framerate closed 5 years ago

framerate commented 5 years ago

Reading through docs and issues it would seem that the client is browser/node compatible, but

https://github.com/hapijs/nes/blob/819b6c402ed416de318e46f7845bee78c6b488e2/lib/client.js#L139

That line implies that when used with Node there is no WebSocket implementation?

Output when trying some of the simplest examples from the ReadMe:

(node:14692) UnhandledPromiseRejectionWarning: TypeError: h.WebSocket is not a constructor
    at h._connect (/home/justin/code/doomtrooper/dt-ai-agent/node_modules/nes/dist/client.js:1:2415)

I tried polyfilling a websocket lib (ws) to nes.Client.Websocket but then I just get "socket error".

I couldn't find anything in the docs or the issue tracker. I'm assuming all the users are using browser/electron (like I normally am). Is it possible to use this with Node?

Any help is appreciated and I can PR an update to the README after I figure it out. Thanks!

hueniverse commented 5 years ago

Should work just fine.

See: https://github.com/hapijs/nes/blob/master/lib/index.js#L134

and the tests in test/client.js

framerate commented 5 years ago

Thanks @hueniverse. I'll assume maybe it's a dependency or even local env problem and I'll investigate further. Examples are definitely failing for me tonight.

framerate commented 5 years ago

I ended up forking and saw that the line you linked had WebSocket === null. I investigated every possible problem and in the end npm install nes was NOT installing ws. I nuked my project and started over and it started working.

Guessing it was related to package-lock.json somehow, but if anyone else is seeing this problem just double check that node_modules/ws exists and you should be fine. Sorry @hueniverse! Crisis averted!

lock[bot] commented 4 years ago

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.