hypercore-protocol-substream
Advanced tools
Comparing version 2.0.5 to 2.0.6
18
index.js
@@ -29,4 +29,6 @@ const _debug = require('debug') | ||
this._onDestroyed = this._onDestroyed.bind(this) | ||
this._onUnpipe = this._onUnpipe.bind(this) | ||
this.feed.once('close', this._onDestroyed) | ||
this.feed.on('extension', this._onExtension) | ||
this.feed.stream.on('unpipe', this._onUnpipe) | ||
} | ||
@@ -40,2 +42,6 @@ | ||
delSub (sub) { | ||
if (sub.state === INIT || sub.state === ESTABLISHED) { | ||
console.warn('Warn: mainstream closed while substream was initializing or active') | ||
sub._transition(CLOSING) | ||
} | ||
if (typeof sub.rid !== 'undefined') { | ||
@@ -48,2 +54,9 @@ delete this._ridTable[sub.rid] | ||
// Forward unpipe events to active substreams | ||
_onUnpipe (src) { | ||
this.subs.forEach(s => { | ||
if (s) s.emit('unpipe', src) | ||
}) | ||
} | ||
_onDestroyed () { | ||
@@ -82,2 +95,5 @@ this.feed.off('extension', this._onExtension) | ||
transmit (buffer) { | ||
if (!this.feed.stream.writable) { | ||
return console.warn('Substream trying to write to non writable stream') | ||
} | ||
this.feed.extension(EXTENSION, buffer) | ||
@@ -245,3 +261,3 @@ } | ||
assert(feed.stream) | ||
assert(!feed.stream.destroyed, 'Can\'t initalize substream on an already destroyed stream') | ||
if (typeof name === 'string') name = Buffer.from(name) | ||
@@ -248,0 +264,0 @@ assert(Buffer.isBuffer(name), '"namespace" must be a String or a Buffer') |
{ | ||
"name": "hypercore-protocol-substream", | ||
"version": "2.0.5", | ||
"version": "2.0.6", | ||
"description": "Create independent virtual streams on a hypercore-protocol stream", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
25156
550