hypercore-protocol-substream
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -25,3 +25,3 @@ const _debug = require('debug') | ||
this.cork() | ||
if (typeof key === 'string') key = Buffer.from(key) | ||
this.id = key || randbytes() | ||
@@ -28,0 +28,0 @@ this.state = INIT |
{ | ||
"name": "hypercore-protocol-substream", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Create independent virtual streams on a hypercore-protocol stream", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -8,2 +8,5 @@ # hypercore-protocol-substream | ||
```js | ||
// Substreams can be created on any | ||
const substream = require('hypercore-protocol-substream') | ||
@@ -13,3 +16,2 @@ const protocol = require('hypercore-protocol') | ||
// From a replication stream | ||
const core = hypercore(storage, key) | ||
@@ -24,3 +26,3 @@ | ||
// Connected event is fired when a virtual stream with the same | ||
// namespace have been initialized by the remote. | ||
// namespace have been initialized on the remote end. | ||
virt1.on('connected', (virt1) => { | ||
@@ -49,10 +51,14 @@ virt1.write('Hello remote!') | ||
// You can listen for incoming streams without any knowledge of the namespace. | ||
stream.on('substream-connected', handshake => { | ||
const connectionHandler = (handshake) => { | ||
if (handshake.payload === 'Please Respond') { | ||
const virtual3 = substream(stream, handshake.id) | ||
virtual3.end('Hey!') | ||
} | ||
}) | ||
} | ||
stream.on('substream-connected', connectionHandler) | ||
stream.once('end', () => stream.off('substream-connected', connectionHandler) | ||
// Alternatively create a manual hyperprotocol-stream | ||
/* | ||
* Alternatively create a manual hyperprotocol-stream | ||
*/ | ||
const key = Buffer.alloc(32) | ||
@@ -63,2 +69,3 @@ key.write('encryption secret') | ||
const vitual4 = substream(stream2, Buffer.from('dc')) | ||
``` | ||
@@ -65,0 +72,0 @@ |
NPM Shrinkwrap
Supply chain riskPackage contains a shrinkwrap file. This may allow the package to bypass normal install procedures.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
96847
8
2498
113
1
1