Skip to content

Commit c726c25

Browse files
committed
Return conn on swarm.dial
1 parent f2df558 commit c726c25

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ function Swarm (peerInfo) {
197197
gotMuxer(this.muxedConns[b58Id].muxer)
198198
}
199199

200+
return pt
201+
200202
function gotWarmedUpConn (conn) {
201203
attemptMuxerUpgrade(conn, (err, muxer) => {
202204
if (!protocol) {

tests/swarm-test.js

+28
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,19 @@ describe('high level API - 1st without stream multiplexing (on TCP)', function (
336336
})
337337
})
338338

339+
it('dial on protocol (returned conn)', (done) => {
340+
swarmB.handle('/apples/1.0.0', (conn) => {
341+
conn.pipe(conn)
342+
})
343+
344+
const conn = swarmA.dial(peerB, '/apples/1.0.0', (err) => {
345+
expect(err).to.not.exist
346+
})
347+
conn.end()
348+
conn.on('data', () => {}) // let it flow.. let it flooooow
349+
conn.on('end', done)
350+
})
351+
339352
it('dial to warm a conn', (done) => {
340353
swarmA.dial(peerB, (err) => {
341354
expect(err).to.not.exist
@@ -618,6 +631,21 @@ describe('high level API - with everything mixed all together!', function () {
618631
})
619632
})
620633

634+
it('dial from tcp to tcp+ws (returned conn)', (done) => {
635+
swarmB.handle('/grapes/1.0.0', (conn) => {
636+
conn.pipe(conn)
637+
})
638+
639+
const conn = swarmA.dial(peerB, '/grapes/1.0.0', (err, conn) => {
640+
expect(err).to.not.exist
641+
expect(Object.keys(swarmA.muxedConns).length).to.equal(1)
642+
})
643+
conn.end()
644+
645+
conn.on('data', () => {}) // let it flow.. let it flooooow
646+
conn.on('end', done)
647+
})
648+
621649
it('dial from tcp+ws to tcp+ws', (done) => {
622650
swarmC.handle('/mamao/1.0.0', (conn) => {
623651
conn.pipe(conn)

0 commit comments

Comments
 (0)