gimite / web-socket-js

HTML5 Web Socket implementation powered by Flash
BSD 3-Clause "New" or "Revised" License
2.73k stars 489 forks source link

Fix for browser with partial WebSocket support #165

Closed KosBeg closed 9 years ago

KosBeg commented 9 years ago

Fix for browser with partial WebSocket support for using flash From Modernizr - https://github.com/Modernizr/Modernizr/blob/master/feature-detects/websockets.js#L28

gimite commented 9 years ago

What exactly is the issue when window.WebSocket.CLOSING is not 2?

KosBeg commented 9 years ago

When the browser has partial support for WebSocket, it has no header "Sec-WebSocket-Version" and therefore the server can be determined WebSocket version and do a "handshake", When the browser is "WebSocket.CLOSING == 2" it has full support for WebSocket and has a header "Sec-WebSocket-Version" This patch uses flash-socket in browsers with partial WebSocket support(Firefox 4-5, Chrome 4-14(I tested on Chrome 6), Safari 5-5.1, Opera 11.5, iOS Safari 4.3-5.1, Opera Mobile 12)

PS: http://caniuse.com/#feat=websockets (this fix for browser with notes 1 - "Partial support refers to the websockets implementation using an older version of the protocol and/or the implementation being disabled by default (due to security issues with the older protocol)") PPS: Sorry for my English =)

gimite commented 9 years ago

Policy of web-socket-js is to use native implementation when available (even if it's incomplete). So I would say the current behavior is intended.

If the user wants different policy (as yours for example), you can control the behavior by performing your own check and set:

WEB_SOCKET_FORCE_FLASH = true;

when you want to force Flash implementation.

Or, I believe your server can still detect the WebSocket version even if it misses Sec-WebSocket-Version. See: https://github.com/gimite/web-socket-ruby/blob/master/lib/web_socket.rb#L52 Not sure if you want to implement hixie-75 and 76 in your server, though.