<commit_before>The Radiodan client is installed as an npm module, which means server-side
nodejs code can access the objects. We've also provided a [connect
middleware][1] to provide access to the same objects in the browser.

# Using the middleware

Using [Express][2]:
```javascript
var app      = require('express')();
var radiodan = require('radiodan-client');

// mount the middleware at /radiodan
// allow requests from other domains (default: false)
app.use('/radiodan',
  radiodan.middleware({crossOrigin: true})
);

// access at http://localhost:5000
app.listen(5000);
```

# Accessing the client-side objects
** TODO: Add as AMD module? **

# Listening for events

[1]: https://github.com/senchalabs/connect
[2]: http://expressjs.com/<commit_msg>Add rough copy for Middleware<commit_after>The Radiodan client is installed as an npm module, which means server-side
nodejs code can access the objects. We've also provided a [connect
middleware][1] to provide access to the same objects in the browser.

# Using the middleware

Using [Express][2]:
```javascript
var app      = require('express')();
var radiodan = require('radiodan-client');

// mount the middleware at /radiodan
// allow requests from other domains (default: false)
app.use('/radiodan',
  radiodan.middleware({crossOrigin: true})
);

// access at http://localhost:5000
app.listen(5000);
```

# Accessing the client-side objects

In your HTML page, link to the radiodan client code (assuming you've mounted the
middleware at `/radiodan`):

```html
<script src="/radiodan/client.js"></script>
```

This will attach the `Radiodan` object to `window`.

## Objects exposed by the client-side API

* [Player](../api/player.md)
* [Audio Device](../api/audio.md)

## Accessing Objects Example

To get an instance of player with id of `main`:

```javascript
var player = window.Radiodan.player.get('main');
```

# Sending Commands

The API for each object applies to both the client-side and server-side
variants. On the client-side, each command is sent back to the middleware via an
AJAX request.

# Listening To Events

Events are emitted via an [EventSource][3] interface. The Radiodan objects
encapsulate this and re-emit events using an [EventEmitter][4] object.

[1]: https://github.com/senchalabs/connect
[2]: http://expressjs.com/
[3]: https://developer.mozilla.org/en-US/docs/Web/API/EventSource
[4]: http://nodejs.org/api/events.html
{'fraction_non_alphanumeric': 0.12572614107883817, 'fraction_numerical': 0.011618257261410789, 'mean_word_length': 4.555299539170507, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6119050', 'n_tokens_mistral': 755, 'n_tokens_neox': 720, 'n_words': 267}