<commit_before># The `ThaliEmitter` class

The `ThaliEmitter` class is a bridge between the native Cordova plugin and JavaScript to give you an easy to use interface for broadcasting availability and to connect and disconnect from peer clients.

## Usage

This is the basic usage to listen for the `peerAvailabilityChanged` event as well as start broadcasting the availability of the current device.

```js
var emitter = new ThaliEmitter();

emitter.on('peerAvailabilityChanged', function (peers) {
  // Handle the peers status changed
  peers.forEach(function (peer) {
    console.log('Peer Identifier: %s', peer.peerIdentifier);
    console.log('Peer is available? %s', peer.isAvailable);
  });
});

emitter.startBroadcasting('me', 9001, function (err) {
  if (err) {
    console.log(err);
  } else {
    console.log('We are now broadcasting on port 9001');
  }
});
```

## Methods

### `ThaliEmitter.prototype.startBroadcasting(deviceName, portNumber, callback)`

This method starts advertising or broadcasting its availability at the following port that PouchDB/Express-PouchDB is listening.  

#### Arguments:

1. `deviceName` : `String` – the device name.
2. `portNumber` : `Number` – obtained by the user of the code which indicates the port number of our local PouchDB/Express-PouchDB
3. `callback` : `Function` – must be in the form of the following, `function (err)` where:
  - `err` : `Error` – an `Error` if one occurred, else `null`

#### Example:

```js
emitter.startBroadcasting('me', 9001, function (err) {
  if (err) {
    console.log(err);
  } else {
    console.log('We are now broadcasting on port 9001');
  }
});
```<commit_msg>Adding better description to the ThaliEmitter class<commit_after># The `ThaliEmitter` class

The `ThaliEmitter` class is a bridge between the native connectivity API and JavaScript to use the Thali local discovery and peer to peer capabilities with TCP/IP servers and clients without the rest of the Thali infrastructure needed.  This is intended to eventually be moved to its own NPM module.

## Usage

This is the basic usage to listen for the `peerAvailabilityChanged` event as well as start broadcasting the availability of the current device.

```js
var emitter = new ThaliEmitter();

emitter.on('peerAvailabilityChanged', function (peers) {
  // Handle the peers status changed
  peers.forEach(function (peer) {
    console.log('Peer Identifier: %s', peer.peerIdentifier);
    console.log('Peer is available? %s', peer.isAvailable);
  });
});

emitter.startBroadcasting('me', 9001, function (err) {
  if (err) {
    console.log(err);
  } else {
    console.log('We are now broadcasting availability on port 9001');
  }
});
```

## Methods

### `ThaliEmitter.prototype.startBroadcasting(deviceName, portNumber, callback)`

This method starts advertising or broadcasting its availability at the following port that PouchDB/Express-PouchDB is listening.  

#### Arguments:

1. `deviceName` : `String` – the device name.
2. `portNumber` : `Number` – obtained by the user of the code which indicates the port number of our local PouchDB/Express-PouchDB
3. `callback` : `Function` – must be in the form of the following, `function (err)` where:
  - `err` : `Error` – an `Error` if one occurred, else `null`

#### Example:

```js
emitter.startBroadcasting('me', 9001, function (err) {
  if (err) {
    console.log(err);
  } else {
    console.log('We are now broadcasting on port 9001');
  }
});
```
{'fraction_non_alphanumeric': 0.11372207716855237, 'fraction_numerical': 0.011024078909196402, 'mean_word_length': 4.421383647798742, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '2095887', 'n_tokens_mistral': 1041, 'n_tokens_neox': 985, 'n_words': 400}