diff --git a/package.json b/package.json index 12613b4..5fb3a86 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ }, "homepage": "https://github.com/diasdavid/js-libp2p-websockets#readme", "dependencies": { + "mafmt": "^1.0.1", "multiaddr": "^1.1.1", "simple-websocket": "github:diasdavid/simple-websocket#ec31437" }, diff --git a/src/index.js b/src/index.js index d1f13a2..f93b17f 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,7 @@ // const debug = require('debug') // const log = debug('libp2p:tcp') -// const multiaddr = require('multiaddr') const SWS = require('simple-websocket') +const mafmt = require('mafmt') exports = module.exports = WebSockets @@ -73,8 +73,7 @@ function WebSockets () { this.filter = (multiaddrs) => { return multiaddrs.filter((ma) => { - // TODO - // https://github.com/whyrusleeping/js-mafmt/pull/2 + return mafmt.WebSockets.matches(ma) }) } } diff --git a/tests/libp2p-websockets-test.js b/tests/libp2p-websockets-test.js index 4c34321..f75d14a 100644 --- a/tests/libp2p-websockets-test.js +++ b/tests/libp2p-websockets-test.js @@ -52,4 +52,15 @@ describe('libp2p-websockets', function () { conn.end() }) }) + + it('filter', (done) => { + const mh1 = multiaddr('/ip4/127.0.0.1/tcp/9090') + const mh2 = multiaddr('/ip4/127.0.0.1/udp/9090') + const mh3 = multiaddr('/ip4/127.0.0.1/tcp/9090/websockets') + + const valid = ws.filter([mh1, mh2, mh3]) + expect(valid.length).to.equal(1) + expect(valid[0]).to.deep.equal(mh3) + done() + }) })