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

Omit protocols for native WebSockets in browsers only. Fixes TypeErrors, see issue 82 #83

Merged
merged 1 commit into from
Jan 26, 2016

Conversation

binarykitchen
Copy link
Contributor

No description provided.

@mcollina
Copy link
Collaborator

Just to clarify, is this a Safari only issue? test worked fine in Chrome.
In case, would you mind adding that in the comment?

// special constructor treatment for native websockets in browsers, see
// https://github.com/maxogden/websocket-stream/issues/82
if (isNative && isBrowser && !protocols) {
socket = new WS(target)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this logic I can't see any way to pass protocols without also passing options as the 3rd argument. Wouldn't that cause the same error this PR is trying to fix for anyone wanting to use specific subprotocols?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

according to the w3.org, there is no options parameter for native websockets, see https://www.w3.org/TR/2011/WD-websockets-20110419/#the-websocket-interface

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I'm talking about the optional protocols argument which is in the spec.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right. have a look at the if clause if (isNative && isBrowser && !protocols) {

it skips when a protocol exist and executes the code in the else clause which passes on the optional protocols argument

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this fail in the case where you need to pass protocols to a native websockets impl? From some testing in safari it looks like any call w/ arguments.length > 2 will throw a TypeError.

ISTM we could just drop the !protocols check from the first case -- something like this:

if (isNative && isBrowser) {
  socket = new WS(target, protocols)
} else {

WFM at least.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that we need to pass protocols from the browsers. This is used by MQTT.js (as an example).

@jnordberg
Copy link
Collaborator

Maybe a simpler solution to this would be to let ws-fallback.js drop the options argument?

@binarykitchen
Copy link
Contributor Author

@mcollina no, it also happens on chrome under mac osx, not just safari

@binarykitchen
Copy link
Contributor Author

@jnordberg i do not follow you - feel free to add this with or after my commit

@mcollina
Copy link
Collaborator

@binarykitchen I've tested with latest Chrome and latest Safari and I do not see the issue in #82.

Which version of Safari/Chrome are you having issues with?

@binarykitchen
Copy link
Contributor Author

@mcollina Chrome v31.0.1650.63 on Mac OS X 10.11.2 after running for two days without any restarts.

Haven't tested this issue on Safari.

The bug is difficult to reproduce I must admit. If you want to be 100% sure, maybe raise this on the Chromium Bug Tracker and question the native WebSocket implementation there?

@deanlandolt
Copy link
Collaborator

@binarykitchen FWIW this issue is easy for me to repro in Safari on OSX 10.10.4 (though I've never hit it in chrome). See: #83 (comment) -- this should let us pass protocols in all cases.

Another alternative is just wrapping in a try and falling back to the 2-arity call, w/ perhaps another try falling back to the 1-arity call (sans protocols). Kinda sloppy, but ultimately still leaves us in a predictable state.

@mcollina
Copy link
Collaborator

My problem here is that I cannot reproduce, and it does not seem an error that could pops up after 2 days of activity.

@deanlandolt if you can reproduce consistently, would you mind checking if passing protocols in all cases is good, i.e. if the problem is only in passing options?

If that's the case, I presume that is the way to go.

@mafintosh @maxogden what do you think?

@deanlandolt
Copy link
Collaborator

I verified (on OSX 10.10.4 in Safari 8.0.7) that passing protocols is safe when undefined, null, or []. I can't say whether it would throw on specific values of protocols, but presumably we'd want it to fail loudly in these cases anyway. I also verified that passing a third option (even undefined) always throws.

@mcollina
Copy link
Collaborator

@binarykitchen would you mind updating your PR and removing the protocols check and passing it back to the constructor?

@deanlandolt
Copy link
Collaborator

I wasn't sure what the preferred workflow was for this case, so I just sent a PR on top of this commit's PR to @binarykitchen branch: https://github.com/binarykitchen/websocket-stream/pull/1

@mcollina
Copy link
Collaborator

you can also send another PR here, I'll get that merged and released asap.

@deanlandolt deanlandolt mentioned this pull request Jan 26, 2016
@mcollina mcollina merged commit cd25146 into max-mapper:master Jan 26, 2016
@binarykitchen
Copy link
Contributor Author

sorry for my late response. was away and then github was down heh.

thanks @deanlandolt for your PR. had a quick look, all looks. thanks guys!

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

Successfully merging this pull request may close these issues.

4 participants