pladaria / reconnecting-websocket

Reconnecting WebSocket. For Web, React Native, cli (Node.js)
MIT License
1.23k stars 199 forks source link

TypeError in Safari 9.1.2 #3

Closed marco-a closed 8 years ago

marco-a commented 8 years ago

I get a TypeError: WebSocket constructor not set. Set "options.constructor" error message in Safari 9.1.2 (11601.7.7) when using browserify 13.1.0 and reconnecting-websocket.

Test to reproduce:

browserify -r reconnecting-websocket:websocket > websocket.js

<!DOCTYPE HTML>
<html>
<head>
<script src="websocket.js" type="text/javascript"></script>
</head>
<body>
<script>
    var websocket = require('websocket');

    var ws = new websocket('ws://localhost:1337');
</script>
</body>
</html>

OS I'm using is Mac OS X 10.11.6 (15G31) El Capitan.

pladaria commented 8 years ago

Thanks for reporting. It seems that in safari typeof WebSocket === 'object' while in other browsers typeof WebSocket === 'function'. Will fix that asap

pladaria commented 8 years ago

The issue should have been fixed. Please, ping me if you have any problems.

Thanks!

juice49 commented 8 years ago

👀 Sorry, I didn't read this thread properly and came to the same conclusion! Sorry. Still seems to be an issue in the current version though.

Ah, yes. I see the fix was applied in the isGlobalWebSocket function, but not further down (line 81 of index.ts).


Hi, still seems to be a problem with this. Apologies, I'm currently debugging the built code, I'll try and fix in the source and PR later.

The problem is old Safari reports typeof WebSocket as "object", not "function". This fails the check in line 63 of the built code:

if (typeof config.constructor !== 'function') {
  throw new TypeError('WebSocket constructor not set. Set `options.constructor`');
}

You can recreate this on desktop if you use the stable Safari version (Safari Tech Preview reports typeof WebSocket as "function').

marco-a commented 8 years ago

It is not working for me either.

pladaria commented 8 years ago

I've published a new package: 1.4.3 Thanks for the feedback!

juice49 commented 8 years ago

@pladaria Looks like the new version didn't make it to npm, the latest version is 1.4.0.

pladaria commented 8 years ago

Published again. Sorry for the inconveniences.

juice49 commented 8 years ago

Thanks!

Gladkov-Art commented 8 years ago

Doesn't work for me. Still have the same issue. React-native 0.30.0 and reconnecting-websocket 1.4.3

pladaria commented 8 years ago

Published 1.4.4 which fixes WebSocket detection for ReactNative Tested using React Native 0.31.0 (iOS)

Thanks for your feedback