tubemail-mdns

Tube Mail peer discovery using mDNS

Usage no npm install needed!

<script type="module">
  import tubemailMdns from 'https://cdn.skypack.dev/tubemail-mdns';
</script>

README

Tube Mail: Discovery mDNS

This is just a helper module for Tube Mail. This module can be used to enable mDNS-based discovery.

Example

// npm install tubemail tubemail-mds
const fs = require('fs');
const tubemail = require('tubemail');

const toBuffer = (obj) => Buffer.from(obj.toString());

tubemail.join({
    key: fs.readFileSync('./hood.peer1.key'),
    cert: fs.readFileSync('./hood.peer1.crt'),
    ca: fs.readFileSync('./hood.crt'),
    discovery: require('tubemail-mdns');
}).then((hood) => {
    // Send the current time every second
    setInterval(() => hood.send(toBuffer(new Date())), 1000);

    // Say hello to new neighs
    hood.on('foundNeigh', (n) => n.send(toBuffer(`Hello ${n.info.subject.commonName}!`)));
});