web-socket-js icon indicating copy to clipboard operation
web-socket-js copied to clipboard

Binary support

Open benbro opened this issue 13 years ago • 4 comments

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

benbro avatar Oct 20 '12 06:10 benbro

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.

gimite avatar Oct 22 '12 03:10 gimite

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.

benbro avatar Oct 22 '12 04:10 benbro

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

gimite avatar Oct 22 '12 04:10 gimite

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.

benbro avatar Oct 22 '12 06:10 benbro