hypercore-protocol
Advanced tools
Comparing version 6.11.0 to 6.11.1
@@ -322,3 +322,3 @@ var stream = require('readable-stream') | ||
this._remoteFeeds[id] = this._feed(feed.discoveryKey) | ||
feed.remoteId = id | ||
this._remoteFeeds[id].remoteId = id | ||
@@ -325,0 +325,0 @@ this.emit('feed', feed.discoveryKey) |
{ | ||
"name": "hypercore-protocol", | ||
"version": "6.11.0", | ||
"version": "6.11.1", | ||
"description": "Stream that implements the hypercore protocol", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -15,15 +15,25 @@ # hypercore-protocol | ||
var protocol = require('hypercore-protocol') | ||
var stream = protocol() | ||
// open a feed specified by a 32 byte key | ||
var feed = stream.feed(Buffer.from('deadbeefdeadbeefdeadbeefdeadbeef')) | ||
// create two streams with hypercore protocol | ||
var streamA = protocol({ id: 'a' }) | ||
var streamB = protocol({ id: 'b' }) | ||
feed.request({block: 42}) | ||
feed.on('data', function (message) { | ||
console.log(message) // contains message.index and message.value | ||
// open two feeds specified by a 32 byte key | ||
var key = Buffer.from('deadbeefdeadbeefdeadbeefdeadbeef') | ||
var feed = streamA.feed(key) | ||
var remoteFeed = streamB.feed(key) | ||
// add data to feed | ||
feed.data({ index: 1, value: '{ block: 42 }'}) | ||
// listen data in remoteFeed | ||
remoteFeed.on('data', function (message) { | ||
console.log(message.value.toString()) | ||
}) | ||
stream.pipe(anotherStream).pipe(stream) | ||
streamA.pipe(streamB).pipe(streamA) | ||
``` | ||
`output => { block: 42 }` | ||
## API | ||
@@ -44,3 +54,4 @@ | ||
encrypt: true, // set to false to disable encryption if you are already piping through a encrypted stream | ||
timeout: 5000 // stream timeout. set to 0 or false to disable. | ||
timeout: 5000, // stream timeout. set to 0 or false to disable. | ||
extensions: [], // names of extensions to use for replication. Must be sorted alphanumerically for handshaking to work | ||
} | ||
@@ -146,2 +157,10 @@ ``` | ||
#### `feed.extension(name, message)` | ||
Send an `extension` message. `name` must be in `extensions` list. See the [schema.proto](schema.proto) file for more information. | ||
#### `feed.on('extension', name, message)` | ||
Emitted when an `extension` message has been received. | ||
#### `feed.on('close')` | ||
@@ -148,0 +167,0 @@ |
15
test.js
@@ -564,1 +564,16 @@ var tape = require('tape') | ||
}) | ||
tape('feed channel ids are set up correctly', function (t) { | ||
var a = protocol() | ||
var b = protocol() | ||
a.feed(KEY) | ||
a.pipe(b).pipe(a) | ||
b.once('feed', function () { | ||
var ch2 = b.feed(KEY) | ||
t.ok(ch2.id > -1) | ||
t.ok(ch2.remoteId > -1) | ||
t.end() | ||
}) | ||
}) |
69728
2078
202