Connect nodes, such as NodeJS-apps or browsers, together and send messages between them. Provides a mesh network with peer-to-peer messaging, allowing messages to be routed between nodes that are not directly connected with each other.
To setup your own network install the ataraxia
package and at least one
transport such as ataraxia-tcp
:
$ npm install ataraxia ataraxia-tcp
A network can then be created and joined:
import { Network, AnonymousAuth } from 'ataraxia';
import { TCPTransport, TCPPeerMDNSDiscovery } from 'ataraxia-tcp';
const net = new Network({
name: 'ataraxia-example',
transports: [
new TCPTransport({
discovery: new TCPPeerMDNSDiscovery(),
authentication: [
new AnonymousAuth()
]
})
]
});
net.onNodeAvailable(node => {
console.log('A new node is available:', node.id);
node.send('hello')
.catch(err => console.log('Unable to send hello'));
});
net.onMessage(msg => {
console.log('A message was received', msg.type, 'with data', msg.data, 'from', msg.source.id);
});
// Join the network
await net.join();
Generated using TypeDoc