rstudio/shiny — pull request #146 by wch (2013-04-17 06:40:25+00:00)
Title: Add support for sending arbitrary messages to client

This does two things:

* Adds support for sending arbitrary JSON messages to the client.
* Adds support for registering Javascript callbacks on the client, to handle the JSON messages.

This will make it easier for app/package authors to add their own communication channels from the server to the client.

Example app at: https://github.com/wch/testapp/tree/master/message-handler

```
devtools::install_github('shiny', 'wch', 'sendmessage')
library(shiny)
runGitHub('testapp', 'wch', subdir='message-handler')
```

Notes:

* I removed `custom` message since it wasn't being used, and this does the same thing.
* The order in which the messages are dispatched was previously defined by the order of the `if` statements, but now the order is not specified, and is browser-dependent: http://stackoverflow.com/a/280861/412655 . If order is important, it could be implemented with an array.
* The order of `values` and `errors` is slightly different; the code for them was previously interleaved, but now it's not. I don't know if the old way was intentional or not.
* I _think_ that putting it in `exports.registerMessageHandler` is the right place, but I'm not 100% sure.