Permalink
Browse files

quick and dirty proof of concept for sharing key on connect - thanks @…

  • Loading branch information...
e-e-e committed Jul 5, 2017
1 parent 484396c commit d8785452ace43ac6fa7de1191ad0e4d4ef811285
Showing with 31 additions and 2 deletions.
  1. +15 −1 hyperchat.js
  2. +16 −1 listener.js
View
@@ -38,7 +38,21 @@ class Hyperchat extends events.EventEmitter {
if (err) throw err
this.emit('ready')
this.ready = true
this.swarm = hyperdiscovery(this.feed)
const archive = this.feed
this.swarm = hyperdiscovery(this.feed, {
stream: function (peer) {
const stream = archive.replicate({
live: true,
upload: true,
download: true,
userData: archive.key
})
stream.on('handshake', () => {
console.log('HANDSHAKE RECIEVER', stream.remoteUserData.toString('hex'))
})
return stream
}
})
this.swarm.once('connection', () => { this.emit('connection') })
})
}
View
@@ -30,7 +30,22 @@ class Listener {
connect () {
console.log('Listening to:', this.key)
this.swarm = hyperdiscovery(this.feed)
const archive = this.feed
const receiver = this.receiver.feed
this.swarm = hyperdiscovery(this.feed, {
stream: function (peer) {
const stream = archive.replicate({
live: true,
upload: true,
download: true,
userData: receiver.key
})
stream.on('handshake', () => {
console.log('HANDSHAKE LISTENER', stream.remoteUserData.toString('hex'))
})
return stream
}
})
this.swarm.once('connection', () => {
this.lastVersion = this.feed.length
this.receiver.emit('listening', { key: this.key })

0 comments on commit d878545

Please sign in to comment.