hypercore 10.0.0-alpha.38 → 10.0.0-alpha.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +14 -4
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -368,24 +368,34 @@ module.exports = class Hypercore extends EventEmitter {
|
|
|
368
368
|
}
|
|
369
369
|
|
|
370
370
|
replicate (isInitiator, opts = {}) {
|
|
371
|
+
// Only limitation here is that ondiscoverykey doesn't work atm when passing a muxer directly,
|
|
372
|
+
// because it doesn't really make a lot of sense.
|
|
373
|
+
if (Protomux.isProtomux(isInitiator)) return this._attachToMuxer(isInitiator, opts)
|
|
374
|
+
|
|
371
375
|
const protocolStream = Hypercore.createProtocolStream(isInitiator, opts)
|
|
372
376
|
const noiseStream = protocolStream.noiseStream
|
|
373
377
|
const protocol = noiseStream.userData
|
|
374
378
|
|
|
379
|
+
this._attachToMuxer(protocol, opts)
|
|
380
|
+
|
|
381
|
+
return protocolStream
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
_attachToMuxer (mux, opts) {
|
|
375
385
|
// If the user wants to, we can make this replication run in a session
|
|
376
386
|
// that way the core wont close "under them" during replication
|
|
377
387
|
if (opts.session) {
|
|
378
388
|
const s = this.session()
|
|
379
|
-
|
|
389
|
+
mux.stream.on('close', () => s.close().catch(noop))
|
|
380
390
|
}
|
|
381
391
|
|
|
382
392
|
if (this.opened) {
|
|
383
|
-
this.replicator.attachTo(
|
|
393
|
+
this.replicator.attachTo(mux)
|
|
384
394
|
} else {
|
|
385
|
-
this.opening.then(() => this.replicator.attachTo(
|
|
395
|
+
this.opening.then(() => this.replicator.attachTo(mux), mux.destroy.bind(mux))
|
|
386
396
|
}
|
|
387
397
|
|
|
388
|
-
return
|
|
398
|
+
return mux
|
|
389
399
|
}
|
|
390
400
|
|
|
391
401
|
get discoveryKey () {
|