Permalink
Browse files
quick and dirty proof of concept for sharing key on connect - thanks @…
- Loading branch information...
Showing
with
31 additions
and
2 deletions.
-
+15
−1
hyperchat.js
-
+16
−1
listener.js
|
|
@@ -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') })
|
|
|
})
|
|
|
}
|
|
|
|
|
|
@@ -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