GPII/universal — pull request #303 by javihernandez (2014-12-24 02:07:21+00:00)
Title: GPII-989: Adding FlowManager's browserChannel and WebSockets settings handler

## Description of changes and additions in this pull request

This pull request consists on *two parts*:

1. A new route in the flow manager, the *browserChannel*
2. The new *WebSockets settings handler*

### The browser channel
This new route can be reached at _http://localhost:8081/browserChannel_
where our web socket server is listening for new clients (browsers).
This new route's handler takes care of:
1. Registering new clients (browsers)
2. Delivering the requested settings to the new client (if any)
3. Making sure that the client will be removed from the system after being disconnected

### The WebSockets settings handler
This new settings handler is where lives all the logic behind the browser channel, since it is who keeps in memory both the settings and the registered clients.

## How it works?

This small and documented client illustrates the workflow.

```javascript
var io = require("socket.io-client");

// The client starts the communication
//
var socket = io.connect("http://localhost:8081/browserChannel");

// When the connection is done, the client tells to the flow manager its id
//
socket.on("connect", function () {
console.log("## Socket connected");
socket.send("org.chrome.cloud4chrome");
});

// Right after sending the id to the flow manager, the server will return back
// the current settings in the system (if any)
//
socket.on("connectionSucceeded", function (settings) {
console.log("## Received the following settings: " + JSON.stringify(settings));
});

// By listening to this signal, the client will be notified when the system has
// new settings to be applied on the client side
//
socket.on("onBrowserSettingsChanged", function (newSettings) {
console.log("## Got newSettings: " + JSON.stringify(newSettings));
});
```

The _contract API_ between client and server can be explained as follows:

* After connecting to the flow manager, the client sends a socket message to the channel, which is basically a string containing the *id* of the client. ie: _org.chrome.cloud4chrome_

* When the flow manager emits either the _connectionSucceeded_ (after being registered) or the _onBrowserSettingsChanged_ (after a user login/logout) signal to the client, it is delivering the current available settings for the client in the following way:
```
{
"screenReaderTTSEnabled":false,
"highContrastEnabled":true,
"invertColours":false,
"magnifierEnabled":true,
"magnification":2,
"fontSize":"medium",
"simplifier":false,
"highContrastTheme":"white-black"
}
```

## Testing

This new feature can be seen in action (in linux) by using this extension https://github.com/GutiX/chrome4cloud/commit/3d064bb7efc93bf90fde90b0192c273fb76817e5

Right now this pull request includes a very basic solution entry for GNU/Linux, so if you want to test it either on Windows or Mac, you will need to include the same entry in the corresponding solution registry of your platform.