RangerMauve / hyperswarm-universal-chat

A basic demo showing how you can make a gossip based p2p chat using hyperswarm.
MIT License
29 stars 0 forks source link

hyperswarm-universal-chat

A basic demo showing how you can make a p2p chat using hyperswarm.

Screenshot of it working in CLI and browser

Intro

Chat apps are the hello world of p2p stuff, here's a hello world you can build off of.

Properties:

API

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')
})

How?

Areas for improvement (WONTFIX)