diff --git a/src/index.js b/src/index.js index 27eb70bf..eddc858b 100644 --- a/src/index.js +++ b/src/index.js @@ -197,6 +197,8 @@ function Swarm (peerInfo) { gotMuxer(this.muxedConns[b58Id].muxer) } + return pt + function gotWarmedUpConn (conn) { attemptMuxerUpgrade(conn, (err, muxer) => { if (!protocol) { diff --git a/tests/swarm-test.js b/tests/swarm-test.js index fbd892c0..6c0c3b42 100644 --- a/tests/swarm-test.js +++ b/tests/swarm-test.js @@ -336,6 +336,19 @@ describe('high level API - 1st without stream multiplexing (on TCP)', function ( }) }) + it('dial on protocol (returned conn)', (done) => { + swarmB.handle('/apples/1.0.0', (conn) => { + conn.pipe(conn) + }) + + const conn = swarmA.dial(peerB, '/apples/1.0.0', (err) => { + expect(err).to.not.exist + }) + conn.end() + conn.on('data', () => {}) // let it flow.. let it flooooow + conn.on('end', done) + }) + it('dial to warm a conn', (done) => { swarmA.dial(peerB, (err) => { expect(err).to.not.exist @@ -618,6 +631,21 @@ describe('high level API - with everything mixed all together!', function () { }) }) + it('dial from tcp to tcp+ws (returned conn)', (done) => { + swarmB.handle('/grapes/1.0.0', (conn) => { + conn.pipe(conn) + }) + + const conn = swarmA.dial(peerB, '/grapes/1.0.0', (err, conn) => { + expect(err).to.not.exist + expect(Object.keys(swarmA.muxedConns).length).to.equal(1) + }) + conn.end() + + conn.on('data', () => {}) // let it flow.. let it flooooow + conn.on('end', done) + }) + it('dial from tcp+ws to tcp+ws', (done) => { swarmC.handle('/mamao/1.0.0', (conn) => { conn.pipe(conn)