Binary support
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
We had a discussion about it, and we decided not to add binary support for web-socket-js: #89
In short:
- We anyway need ArrayBuffer or Blob to implement binary API, but there are not so many browsers which have ArrayBuffer or Blob but don't have native WebSocket.
- There are browsers which have native WebSocket but without binary support. web-socket-js uses native WebSocket when available. So binary API is still not available for those browsers.
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.
Yeah, it should workaround the first issue, but the second issue remains.
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.