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

Binary support #123

Open benbro opened 11 years ago

benbro commented 11 years ago

WebSocket support sending and receiving binary data. Is it possible that web-socket-js will handle this transparently for the user? In case of a binary message, it will base64 encode it, will call send_binary to so the flash socket will decode it and send it as binary. The flash socket will do the same in the opposite direction. When it will receive a binary packet, it will base64 encode it and call onbinarymessage on js. the binaryType attribute will tell the js to use a blob or array buffer for the binary message.

Makes sense?

Thanks

gimite commented 11 years ago

We had a discussion about it, and we decided not to add binary support for web-socket-js: #89

In short:

benbro commented 11 years ago

I agree that web-socket.js should be compatible with native WebSocket without adding custom syntax. It's possible to use a polyfill to add array buffer and blob support to older browsers.

Typed arrays https://github.com/mozilla/pdf.js/blob/master/web/compatibility.js#L21 Array Buffer http://www.calormen.com/polyfill/typedarray.js Blob https://github.com/eligrey/BlobBuilder.js

I'm using the first link from pdf.js successfully. Haven't tried the second and third links but they look good.

This could be very useful for projects such as noVNC.

gimite commented 11 years ago

Yeah, it should workaround the first issue, but the second issue remains.

benbro commented 11 years ago

Issue 2 is the fault of browsers that implemented unstable versions of the spec with unprefixed object. web-socket.js doesn't make anything worse for these browsers but improve it for other browsers.