# ataraxia-local

> Machine-local transport for Ataraxia P2P messaging

Latest version **0.12.0** (published 2021-12-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install ataraxia-local
pnpm add ataraxia-local
yarn add ataraxia-local
bun add ataraxia-local
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.12.0 |
| Published | 2021-12-18 |
| First published | 2017-11-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 54.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 79 |
| Maintainers | aholstenson |

## Links

- npm: https://www.npmjs.com/package/ataraxia-local
- Repository: https://github.com/aholstenson/ataraxia.git#master
- Homepage: https://github.com/aholstenson/ataraxia/tree/master#readme
- Issues: https://github.com/aholstenson/ataraxia/issues
- npm.io page: https://npm.io/package/ataraxia-local

## Dependencies (5)

- [atvik](https://npm.io/package/atvik.md) ^3.2.0
- [debug](https://npm.io/package/debug.md) ^4.3.3
- [ataraxia-transport](https://npm.io/package/ataraxia-transport.md) ^0.12.0
- [local-machine-network](https://npm.io/package/local-machine-network.md) ^1.0.0
- [ataraxia-transport-streams](https://npm.io/package/ataraxia-transport-streams.md) ^0.12.0

## Recent versions

- 0.12.0 (latest) — 2021-12-18
- 0.11.0 — 2021-06-17
- 0.10.0 — 2021-06-07
- 0.9.1 — 2021-06-04
- 0.9.0 — 2021-06-04
- 0.8.2 — 2020-04-18
- 0.8.1 — 2020-04-17
- 0.8.0 — 2020-04-12
- 0.7.2 — 2018-12-05
- 0.7.1 — 2018-11-27
- 0.7.0 — 2018-11-25
- 0.6.1 — 2018-02-13
- 0.6.0 — 2018-02-04
- 0.5.2 — 2017-12-08
- 0.5.1 — 2017-12-06
- … 14 more at https://npm.io/package/ataraxia-local/versions

## README

# ataraxia-local

[![npm version](https://img.shields.io/npm/v/ataraxia-local)](https://www.npmjs.com/package/ataraxia-local)
[![Dependencies](https://img.shields.io/librariesio/release/npm/ataraxia-local)](https://libraries.io/npm/ataraxia-local)
[![Typedoc](https://img.shields.io/badge/typedoc-ataraxia--local-%23fff)](https://aholstenson.github.io/ataraxia/modules/ataraxia_local.html)

Machine-local transport for [Ataraxia](https://github.com/aholstenson/ataraxia).
This transport connects together instances on the same machine via a Unix
socket.

## Usage

```
npm install --save ataraxia-local
```

To use only the machine-local transport:

```javascript
import { Network, AnonymousAuth } from 'ataraxia';
import { MachineLocalTransport } from 'ataraxia-local';

// Setup a network
const net = new Network({
  name: 'name-of-your-app-or-network',

  transports: [
    new MachineLocalTransport()
  ]
});

await net.join();
```

`onLeader` can be used to start a secondary network transport that
will handle connections to other machines:

```javascript
import { Network, AnonymousAuth } from 'ataraxia';
import { TCPTransport, TCPPeerMDNSDiscovery } from 'ataraxia-tcp';
import { MachineLocalTransport } from 'ataraxia-local';

// Setup a network
const net = new Network({
  name: 'name-of-your-app-or-network',
});

net.addTransport(new MachineLocalTransport({
  onLeader: () => {
    /*
    * The leader event is emitted when this instance becomes the leader
    * of the machine-local network. This instance will now handle
    * connections to other machines in the network.
    */
    net.addTransport(new TCPTransport({
      discovery: new TCPPeerMDNSDiscovery(),

      authentication: [
        new AnonymousAuth()
      ]
    }));
  }
});

await net.join();
```

## API

* `new MachineLocalTransport(options)`

  Create a new instance of the transport.

  * `options`
    * `path?: string`, path of the local socket. If not specified the transport 
      defaults to creating a socket in the temporary directory of the system 
      using the name of the network.
    * `onLeader?: () => void`, function that will be run if this instance 
      becomes the leader of the local network.

* `onLeader(callback: () => void)`

  Event emitted if this transport becomes the leader of the local network.

---
_Source: https://npm.io/package/ataraxia-local · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
