{"name":"libp2p-multiplex","version":"0.3.5","description":"multiplex implementation wrapper that is compatible with libp2p Stream Muxer expected interface","main":"src/index.js","scripts":{"lint":"gulp lint","build":"gulp build","test":"gulp test","test:node":"gulp test:node","test:browser":"gulp test:browser","release":"gulp release","release-minor":"gulp release --type minor","release-major":"gulp release --type major","coverage":"gulp coverage","coverage-publish":"aegir-coverage publish"},"repository":{"type":"git","url":"git+https://github.com/libp2p/js-libp2p-multiplex.git"},"keywords":["IPFS"],"author":{"name":"David Dias","email":"daviddias@ipfs.io"},"license":"MIT","bugs":{"url":"https://github.com/libp2p/js-libp2p-multiplex/issues"},"homepage":"https://github.com/libp2p/js-libp2p-multiplex#readme","devDependencies":{"aegir":"^9.3.3","chai":"^3.5.0","interface-stream-muxer":"^0.5.5","libp2p-websockets":"^0.9.1","pre-commit":"^1.2.2","pull-pair":"^1.1.0"},"dependencies":{"multiplex":"github:diasdavid/multiplex","pull-catch":"^1.0.0","pull-stream":"^3.5.0","pull-stream-to-stream":"^1.3.3","stream-to-pull-stream":"^1.7.2"},"contributors":[{"name":"David Dias","email":"daviddias.p@gmail.com"},{"name":"Francisco Baio Dias","email":"xicombd@gmail.com"},{"name":"Friedel Ziegelmayer","email":"dignifiedquire@gmail.com"},{"name":"Richard Littauer","email":"richard.littauer@gmail.com"},{"name":"Stephen Whitmore","email":"stephen.whitmore@gmail.com"},{"name":"Victor Bjelkholm","email":"victorbjelkholm@gmail.com"},{"name":"greenkeeperio-bot","email":"support@greenkeeper.io"}],"gitHead":"1c08ce0d845df9e14d662d9985b84f2da19ea9aa","_id":"libp2p-multiplex@0.3.5","_shasum":"ae91ef295bb7132c7a371665392b750e737d3f06","_from":".","_npmVersion":"3.10.9","_nodeVersion":"6.9.2","_npmUser":{"name":"daviddias","email":"daviddias.p@gmail.com"},"dist":{"shasum":"ae91ef295bb7132c7a371665392b750e737d3f06","tarball":"http://registry-npm.ywwl.com/libp2p-multiplex/download/libp2p-multiplex-0.3.5.tgz","integrity":"sha512-NxYVR2zAYgAywc7mKatuCsZ4OXKDSHY/cecsAoicOMwTEYGL/NncgVUCr9uNGPN/px1brvZ/45w8GAQPIvLfeA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIF3qgLHO4hOttPjyLGboyCwNAT4kpbAAvAva3P5Ur/zIAiEAidYI0WOZhQQyIx1bA7PhIvXouDM8vJODd/eZyThCWFc="}],"size":5413,"noattachment":false,"key":"/libp2p-multiplex/-/libp2p-multiplex-0.3.5.tgz"},"maintainers":[{"name":"daviddias","email":"daviddias.p@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/libp2p-multiplex-0.3.5.tgz_1485443740671_0.5265100952237844"},"directories":{},"readme":"js-libp2p-multiplex\n===================\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Build Status](https://travis-ci.org/libp2p/js-libp2p-multiplex.svg?style=flat-square)](https://travis-ci.org/libp2p/js-libp2p-multiplex)\n![](https://img.shields.io/badge/coverage-%3F-yellow.svg?style=flat-square)\n[![Dependency Status](https://david-dm.org/libp2p/js-libp2p-multiplex.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-multiplex)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> multiplex implementation wrapper that is compatible with libp2p Stream Muxer expected interface\n\n[![](https://github.com/libp2p/interface-stream-muxer/raw/master/img/badge.png)](https://github.com/libp2p/interface-stream-muxer)\n\n## Usage\n\nLet's define a `listener.js`, which starts a TCP server on port 9999\nand waits for a connection. Once we get a connection, we wait for\na stream. And finally, once we have the stream, we pull the data\nfrom that stream, and printing it to the console.\n\n```JavaScript\nconst multiplex = require('libp2p-multiplex')\nconst tcp = require('net')\nconst pull = require('pull-stream')\nconst toPull = require('stream-to-pull-stream')\n\nconst listener = tcp.createServer((socket) => {\n  console.log('[listener] Got connection!')\n\n  const muxer = multiplex.listener(toPull(socket))\n\n  muxer.on('stream', (stream) => {\n    console.log('[listener] Got stream!')\n    pull(\n      stream,\n      pull.drain((data) => {\n        console.log('[listener] Received:')\n        console.log(data.toString())\n      })\n    )\n  })\n})\n\nlistener.listen(9999, () => {\n  console.log('[listener] listening on 9999')\n})\n```\n\nNow, let's define `dialer.js` who will connect to our `listener` over a TCP socket. Once we have that, we'll put a message in the stream for our `listener`.\n\n```JavaScript\nconst multiplex = require('libp2p-multiplex')\nconst tcp = require('net')\nconst pull = require('pull-stream')\nconst toPull = require('stream-to-pull-stream')\n\nconst socket = tcp.connect(9999)\n\nconst muxer = multiplex.dialer(toPull(socket))\n\nconsole.log('[dialer] opening stream')\nconst stream = muxer.newStream((err) => {\n  console.log('[dialer] opened stream')\n  if (err) throw err\n})\n\npull(\n  pull.values(['hey, how is it going. I am the dialer']),\n  stream\n)\n```\n\nNow we can first run `listener.js` and then `dialer.js` to see the\nfollowing output:\n\n*listener.js*\n\n```\n$ node listener.js\n[listener] listening on 9999\n[listener] Got connection!\n[listener] Got stream!\n[listener] Received:\nhey, how is it going. I am the dialer\n```\n\n*dialer.js*\n\n```\n$ node dialer.js\n[dialer] opening stream\n[dialer] opened stream\n```\n\n## API\n\n```js\nconst multiplex = require('libp2p-multiplex')\n```\n\n#### var multi = multiplex(transport, isListener)\n\nReturns a new multiplexert that multiplexes over the duplex stream `transport`.\n`isListener` should be true when this multiplexer will be used to listen for\nstreams.\n\n#### multiplex.newStream(function (err, stream) {})\n\nCreates a new stream over the original `transport`. The resultant stream is\nprovided asynchronously via the callback.\n\n#### multiplex.on('stream', function (stream) {})\n\nEmits an event when a new stream is received by the other side of the transport.\n\n#### multiplex.close()\n\nCloses the stream (from either side).\n\n#### multiplex.on('close')\n\nEmitted when the stream has been closed.\n\n#### multiplex.on('error')\n\nEmitted when the stream produces an error.\n\n## Install\n\n```sh\n> npm install libp2p-multiplex\n```\n","publish_time":1485443742524,"_cnpm_publish_time":1485443742524,"dist-tags":{"latest":"0.5.1"}}