A basic demo showing how you can make a gossip based p2p chat using hyperswarm.
MIT License
A basic demo showing how you can make a p2p chat using hyperswarm.
Chat apps are the hello world of p2p stuff, here's a hello world you can build off of.
const HyperswarmUniversalChat = require('hyperswarm-universal-chat')
const chat = HyperswarmUniversalChat({
swarm: null // Optional hyperswarm instance
})
// Join a channel and start getting peers
const channel = chat.channel('some name, who cares what it is, really')
channel.on('message', (peer, {message}) => {
console.log(`${message}`)
})
channel.on('peer', (peer) => {
console.log(`* connected to ${peer} *`)
connection.once('end', () => {
console.log(`* disconnected from ${peer} *`)
})
})
channel.send('Hello world!')
channel.close()
chat.destroy(() => {
console.log('Quit')
})