kanaka/websockify — pull request #137 by kousu (2014-09-15 02:23:44+00:00)
Title: Add "text" subprotocol, and make it the default.

Websockify previously forced you to specify, "binary" or "base64"
when constructing a WebSocket, forcing you to either handle Blobs
or start all your processing in btoa().

This patch gives a mode to websockify to pass data unprocessed without
marking it with the 0x2 opcode that makes browsers interpret websocket
frames as Blobs. This lets client code that works against other WebSocket
implementations, such as AutobahnPython, to also work unchanged.

In code, the difference is, previously you would have to do:
```
var ws = new WebSocket("ws://localhost:8080", "binary")
ws.onmessage = function(e) {
var F = new FileReader();
var payload = null;
F.readAsText(e.data);
F.onloadend = function() {
payload = F.result;
}
}
```

or

```
var ws = new WebSocket("ws://localhost:8080", "base64")
ws.onmessage = function(e) {
var payload = btoa(e.data);
}
```

Now you can just do

```
var ws = new WebSocket("ws://localhost:8080")
ws.onmessage = function(e) {
var payload = e.data;
}
```

This patch still *allows* the old way to work (in particular, when pushing
lots of data, careful Blob processing of should help performance.. I think.)

I believe that this patch fulfills the original request in #17.