ataraxia-local
![Typedoc](https://img.shields.io/badge/typedoc-ataraxia--local-%23fff)
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';
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';
const net = new Network({
name: 'name-of-your-app-or-network',
});
net.addTransport(new MachineLocalTransport({
onLeader: () => {
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.