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

Binary support #123

Open
benbro opened this issue Oct 20, 2012 · 4 comments
Open

Binary support #123

benbro opened this issue Oct 20, 2012 · 4 comments

Comments

@benbro
Copy link

benbro commented Oct 20, 2012

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
Copy link
Owner

gimite commented Oct 22, 2012

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.

@benbro
Copy link
Author

benbro commented Oct 22, 2012

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
Copy link
Owner

gimite commented Oct 22, 2012

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

@benbro
Copy link
Author

benbro commented Oct 22, 2012

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants