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

Client-driven option to enable websocket binary write #1338

Closed
smaldini opened this issue Oct 9, 2013 · 4 comments
Closed

Client-driven option to enable websocket binary write #1338

smaldini opened this issue Oct 9, 2013 · 4 comments

Comments

@smaldini
Copy link
Contributor

smaldini commented Oct 9, 2013

Would be great to have a per request attribute based switch to enable binary write onto this connection. A similar pattern is used with TrackMessageLength attribute.
Global attribute switch is a bit too wide a scope as some browser support websocket but don't support arraybuffer or blob (IE comes to mind). If the client can present a flag simply populated by "supportBinary:!!window.ArrayBuffer" or similar then the server could write bytes.

That would complete a story to easily enable byte streaming (mainly used for media frames) from server to client.
To fix client to server stream, this Atmosphere/atmosphere-javascript#38 should be just enough (combined with a Streaming Websocket handler).

jfarcand added a commit that referenced this issue Oct 15, 2013
@jfarcand
Copy link
Member

This is fairly simple to do right now with today's 2.1.0-SNAPSHOT. Just do:

  • client : Add a special header to request object, or append a query string ?supportBinary:!!window.ArrayBuffer
  • server : If you use a WebSocketHandler, just do
if (webSocket.resource().getRequest().getHeader('supportBinary') ... ) {
     webSocket.binaryWrite(true).write(...);

or when the webSocketHandler.onOpen gets called, just do

if (webSocket.resource().getRequest().getHeader('supportBinary') ... ){
     webSocket.binaryWrite(true);
}

Let me know if that works and I can add official support client side.

@smaldini
Copy link
Contributor Author

In fact, I don't think that is the most convenient way, could we have a defined header name to use (and implement this logic under the hood). That instead of creating an additional websocket handler to just hook into onOpen event seems just easier for the lazy geeks like me :D

@jfarcand
Copy link
Member

Ok added `AtmosphereResource.forceBinaryWrite' API.

@jfarcand
Copy link
Member

Fixed and documented

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