Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/RangerMauve/hyperswarm-universal-chat
A basic demo showing how you can make a gossip based p2p chat using hyperswarm.
https://github.com/RangerMauve/hyperswarm-universal-chat
Last synced: 4 months ago
JSON representation
A basic demo showing how you can make a gossip based p2p chat using hyperswarm.
- Host: GitHub
- URL: https://github.com/RangerMauve/hyperswarm-universal-chat
- Owner: RangerMauve
- License: mit
- Created: 2020-01-05T20:33:02.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-01-20T16:11:54.000Z (almost 5 years ago)
- Last Synced: 2024-06-22T15:54:59.521Z (6 months ago)
- Language: JavaScript
- Size: 311 KB
- Stars: 29
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hyperswarm-universal-chat
A basic demo showing how you can make a p2p chat using hyperswarm.![Screenshot of it working in CLI and browser](Universal.png)
## Intro
Chat apps are the hello world of p2p stuff, here's a hello world you can build off of.
## Properties:
- As P2P as it gets, no central authorities
- Works in node using hyperswarm and in the browser with hyperswarm-web
- Just echoes your peers' messages, nothing fancy
- Messages are totally ephemeral, if you missed it you missed it## API
```js
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?
- Join a channel
- Derive key by hashing channel name
- Look for peers using key
- Connect to as many as you can
- Parse the connection with NDJSON
- When you establish the connection, send the key you're connecting from
- When you get a connection, listen for the key before doing anything (read 32 bytes?)
- When you get a message, take the message and print it.## Areas for improvement (WONTFIX)
- Deduplicate connections (OH WELL, it's a demo, you can figure it out. :P)
- Gossip of messages from peers
- Usernames
- Verifying users with signed messages
- Encryption of connections