Options
All
  • Public
  • Public/Protected
  • All
Menu

Module ataraxia

Mesh networking with peer-to-peer messaging for NodeJS and the browser. Ataraxia connects different instances together and allows messages to be passed between these instances. Some instances may act as routers for other instances to create a partially connected mesh network.

Network is the main class used to join a network:

import { Network, AnonymousAuth } from 'ataraxia';
import { TCPTransport, TCPPeerMDNSDiscovery } from 'ataraxia-tcp';

// Setup a network with a TCP transport
const net = new Network({
name: 'name-of-your-app-or-network',
transports: [
new TCPTransport({
// Discover peers using mDNS
discovery: new TCPPeerMDNSDiscovery(),
// Setup anonymous authentication
authentication: [
new AnonymousAuth()
]
})
]
});

net.onNodeAvailable(node => {
console.log('A new node is available', node);
});

net.onMessage(msg => {
console.log('A new message was received');
});

// Join the network
await net.join();

Authentication is provided via AnonymousAuth or SharedSecretAuth.

Index

References

AnonymousAuth

Re-exports AnonymousAuth

AuthProvider

Re-exports AuthProvider

SharedSecretAuth

Re-exports SharedSecretAuth

SharedSecretAuthOptions

Re-exports SharedSecretAuthOptions

Transport

Re-exports Transport

Type aliases

MessageData

MessageData<MessageTypes, T>: MessageTypes[T]

Type for picking out the data type of a message.

Type parameters

  • MessageTypes: object

  • T: keyof MessageTypes

MessageType

MessageType<MessageTypes>: keyof MessageTypes & string

Type for defining the type of message.

Type parameters

  • MessageTypes: object

MessageUnion

MessageUnion<MessageTypes>: { [ P in keyof MessageTypes]: P extends string ? Message<MessageTypes, P> : never }[keyof MessageTypes]

Type generator for creating a union of Message types. This allows for checks like this:

if(msg.type === 'type') {
// Type of data will be inferred from type
const data = msg.data;
}

Type parameters

  • MessageTypes: object

Generated using TypeDoc