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 #244

Merged
merged 40 commits into from Feb 19, 2014
Merged

Binary support #244

merged 40 commits into from Feb 19, 2014

Conversation

rase-
Copy link
Contributor

@rase- rase- commented Feb 1, 2014

This pull request answers to the issue of sending binary data over engine.io. Please take a look at the engine.io pull request for more details about binary on different transport methods.

With these changes binary data can be sent from the server to the client, and the other way around. The API for sending binary data is the same as for sending utf-8 strings, but binary types are detected. When a client on a browser calls socket.send for an ArrayBuffer, or an ArrayBufferView the data is sent as binary. For a node server the possibilities are the aforementioned, and also Buffer. The data is then received as binary on the other end.

On a browser client, the data is by default received as an ArrayBuffer, but can be changed to Blob via setting socket.binaryType = 'blob'. If Blob is not supported, the default type is used. On a Node client the default type is Buffer, but can be set to ArrayBuffer with socket.binaryType = 'arraybuffer'. If ArrayBuffer is not supported on browsers, then an object like this is returned: { base64: true, data: data }, where data contains the binary data as a base64 string.

The server needs to know when a client doesn't support XHR2 for binary data, so the client notifies the server of this by adding a b64 query parameter to the handshaking request. This will lead to binary messages travelling base64 encoded, even when using XHR polling.

@@ -131,6 +131,7 @@ function Socket(uri, opts){
this.upgrade = false !== opts.upgrade;
this.path = (opts.path || '/engine.io').replace(/\/$/, '') + '/';
this.forceJSONP = !!opts.forceJSONP;
this.forceBase64 = !!opts.forceBase64;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should document this

@rase-
Copy link
Contributor Author

rase- commented Feb 1, 2014

Thanks for the comments. I'll make the style changes. I totally agree about the test. I'll look into the feature detecting binary support for WebSockets. When it comes to base64 encoding, it is actually currently automatically decoded and handed in as binary if binary types are supported. Maybe this didn't come across that well from my documentation. I'll make that better.

rauchg added a commit that referenced this pull request Feb 19, 2014
@rauchg rauchg merged commit f00b6bd into socketio:master Feb 19, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants