Options
All
  • Public
  • Public/Protected
  • All
Menu

Machine local transport. Uses Unix sockets to connect to peers on the same machine.

Usage example:

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();

The event onLeader or the option MachineLocalTransportOptions.onLeader can be used to perform actions if the transport instance becomes the leader of nodes running on the local machine.

Example starting a TCP transport when becoming the leader:

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();

Hierarchy

Index

Constructors

constructor

Properties

Protected debug

debug: Debugger

Protected Readonly peers

peers: Set<Peer>

Accessors

leader

  • get leader(): boolean

onLeader

  • get onLeader(): Subscribable<this, []>
  • Event emitted if this instance becomes the leader of nodes running on this local machine.

    instance.onLeader(() => {
    // Do something here, such as starting another transport
    });

    Returns Subscribable<this, []>

    subscribable

onPeerConnect

  • get onPeerConnect(): Subscribable<this, [peer: Peer]>
  • Event for when a new peer is connected via this transport.

    Returns Subscribable<this, [peer: Peer]>

    Subscribable that can be used to register listeners

started

  • get started(): boolean

transportOptions

Methods

Protected addPeer

  • addPeer(peer: Peer): void

start

stop

  • stop(): Promise<boolean>

Generated using TypeDoc