{"name":"libp2p-multiplex","version":"0.1.0","description":"multiplex implementation wrapper that is compatible with libp2p Stream Muxer expected interface","main":"src/index.js","scripts":{"lint":"standard","test":"mocha tests/*-test.js","compliance":"node tests/compliance.js"},"repository":{"type":"git","url":"git+https://github.com/diasdavid/js-libp2p-multiplex.git"},"keywords":["IPFS"],"author":{"name":"David Dias","email":"daviddias@ipfs.io"},"license":"MIT","bugs":{"url":"https://github.com/diasdavid/js-libp2p-multiplex/issues"},"homepage":"https://github.com/diasdavid/js-libp2p-multiplex#readme","devDependencies":{"chai":"^3.5.0","interface-stream-muxer":"^0.3.1","pre-commit":"^1.1.2","standard":"^6.0.7","stream-pair":"^1.0.3","tape":"^4.2.0","timed-tape":"^0.1.0","mocha":"^2.4.5"},"dependencies":{"multiplex":"github:diasdavid/multiplex#3f15f490ed9244aa4108cebc3177c4aecff92312"},"gitHead":"feca2c64ec9040c9bad285a4c6c49b71faac37c8","_id":"libp2p-multiplex@0.1.0","_shasum":"7c962eaf47bf3b9ab3c2eee8ef1b325a4ff270bb","_from":".","_npmVersion":"3.8.0","_nodeVersion":"4.3.2","_npmUser":{"name":"daviddias","email":"daviddias.p@gmail.com"},"maintainers":[{"name":"daviddias","email":"daviddias.p@gmail.com"}],"dist":{"shasum":"7c962eaf47bf3b9ab3c2eee8ef1b325a4ff270bb","tarball":"http://registry-npm.ywwl.com/libp2p-multiplex/download/libp2p-multiplex-0.1.0.tgz","integrity":"sha512-OAQYtvhTEkALu4TxmSur5agHzseaGNqIFJ7SwnWgakqenqbF87mK2FOITERzgeV5jzRiIP4Cy5iPlSHIOOQzVw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCAps0ne/HSBKTXYMs6TxZnTtS54ZmNkMegc8wqQ0bMHQIgSJmHWVz+qZ9u0dThghHaRbLKm7T6pPlJ898WAQDurvo="}],"size":3071,"noattachment":false,"key":"/libp2p-multiplex/-/libp2p-multiplex-0.1.0.tgz"},"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/libp2p-multiplex-0.1.0.tgz_1457311906390_0.4500486378092319"},"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":1457311909957,"_cnpm_publish_time":1457311909957,"dist-tags":{"latest":"0.5.1"}}