mirror of
https://github.com/fluencelabs/js-libp2p-websockets
synced 2025-04-25 12:12:35 +00:00
add filter
This commit is contained in:
parent
03de3c49ef
commit
1473964c15
@ -29,6 +29,7 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/diasdavid/js-libp2p-websockets#readme",
|
"homepage": "https://github.com/diasdavid/js-libp2p-websockets#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"mafmt": "^1.0.1",
|
||||||
"multiaddr": "^1.1.1",
|
"multiaddr": "^1.1.1",
|
||||||
"simple-websocket": "github:diasdavid/simple-websocket#ec31437"
|
"simple-websocket": "github:diasdavid/simple-websocket#ec31437"
|
||||||
},
|
},
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// const debug = require('debug')
|
// const debug = require('debug')
|
||||||
// const log = debug('libp2p:tcp')
|
// const log = debug('libp2p:tcp')
|
||||||
// const multiaddr = require('multiaddr')
|
|
||||||
const SWS = require('simple-websocket')
|
const SWS = require('simple-websocket')
|
||||||
|
const mafmt = require('mafmt')
|
||||||
|
|
||||||
exports = module.exports = WebSockets
|
exports = module.exports = WebSockets
|
||||||
|
|
||||||
@ -73,8 +73,7 @@ function WebSockets () {
|
|||||||
|
|
||||||
this.filter = (multiaddrs) => {
|
this.filter = (multiaddrs) => {
|
||||||
return multiaddrs.filter((ma) => {
|
return multiaddrs.filter((ma) => {
|
||||||
// TODO
|
return mafmt.WebSockets.matches(ma)
|
||||||
// https://github.com/whyrusleeping/js-mafmt/pull/2
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,4 +52,15 @@ describe('libp2p-websockets', function () {
|
|||||||
conn.end()
|
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()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user