LearnBoost/engine.io — pull request #218 by rase- (2014-02-01 01:01:50+00:00)
Title: Binary support

This pull request answers issue #182 of sending binary data over engine.io. This issue involves also engine.io-client and engine.io-protocol. The work is still a bit ongoing, but I'd like to know what you guys think. This is my first OSS pull request, so be gentle. ;)

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. For details on how data is received on clients, consult the engine.io-client pull request. The server always receives all binary data as a `Buffer`, which is the type of the message in `on('message', fn)`.

Binary data can be sent over all transports. For XHR polling the default setting is using responseType of XHR2 to deliver binary data directly. If using JSONP polling, or XHR2 is not supported, all binary data is base64 encoded before transmitting. For more information on how the encoding happens, consult the engine.io-protocol pull request. Base64 encoding is the default options for FlashSockets. WebSockets have their own support for binary data. The engine.io client notifies the server for the possibly missing XHR2 support, so that the server knows whether to encode binary data as strings, or send them as binary.