0.12.0 • Published 2 years ago

ataraxia-local v0.12.0

Weekly downloads
3
License
MIT
Repository
github
Last release
2 years ago

ataraxia-local

npm version Dependencies Typedoc

Machine-local transport for 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:

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:

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.

0.12.0

2 years ago

0.11.0

3 years ago

0.10.0

3 years ago

0.9.0

3 years ago

0.9.1

3 years ago

0.8.2

4 years ago

0.8.1

4 years ago

0.8.0

4 years ago

0.7.2

5 years ago

0.7.1

5 years ago

0.7.0

5 years ago

0.6.1

6 years ago

0.6.0

6 years ago

0.5.2

6 years ago

0.5.1

6 years ago

0.5.0

6 years ago

0.4.4

6 years ago

0.4.3

6 years ago

0.4.2

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.2

6 years ago

0.3.0

6 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago