LearnBoost/engine.io-client — pull request #244 by rase- (2014-02-01 01:03:17+00:00)
Title: Binary support

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.