max-mapper / websocket-stream

websockets with the node stream API
BSD 2-Clause "Simplified" License
667 stars 114 forks source link

what to do when WS is not a constructor? #111

Open binarykitchen opened 7 years ago

binarykitchen commented 7 years ago

for some exotic browsers i want to support, like opera, i see the WS is not a constructor error.

do you think you could add a workaround for that? if not, what else would you suggest in my place?

binarykitchen commented 7 years ago

silly me, wrong repo. will do this in https://github.com/websockets/ws

mcollina commented 7 years ago

no worries.

binarykitchen commented 7 years ago

sorry, reopening. moving this back here from https://github.com/websockets/ws/issues/1060

i guess it has something to do with the ws-fallback.js file.

mcollina commented 7 years ago

we do not have a ws-fallback here. What do you mean?

lpinca commented 7 years ago

https://github.com/maxogden/websocket-stream/blob/master/ws-fallback.js

I guess the Opera version is too old, for example in 11.50 you had to enable WebSocket manually to have the WebSocket object.

@binarykitchen you should download the Opera version that is giving you troubles, open the console and check if there is a global WebSocket object available.

binarykitchen commented 7 years ago

damn, cannot reproduce this anymore. wish i had noted down the exact opera version.

but still, i wonder what the recommendation is when ws being null is returned here https://github.com/maxogden/websocket-stream/blob/master/ws-fallback.js ?

maybe throw an exception somewhere saying that "your browser does not support WebSockets" or something like that?

lpinca commented 7 years ago

maybe throw an exception somewhere saying that "your browser does not support WebSockets" or something like that?

I think it makes sense.

limjiregister commented 5 years ago

I got this issue too. when I used wepback4.x to build, and ran it by 'node main.js', this error happened. How to fixed it?

dfoverdx commented 5 years ago

@limjiregister My solution was setting the target: 'node' in my webpack.config.js file.