{"name":"simple-message-channels","version":"1.1.2","description":"Simple streamable state machine that implements a useful channel, message-type, message pattern","main":"index.js","dependencies":{"varint":"^5.0.0"},"devDependencies":{"tape":"^4.11.0"},"scripts":{"test":"tape test.js"},"repository":{"type":"git","url":"git+https://github.com/mafintosh/simple-message-channels.git"},"author":{"name":"Mathias Buus","url":"@mafintosh"},"license":"MIT","bugs":{"url":"https://github.com/mafintosh/simple-message-channels/issues"},"homepage":"https://github.com/mafintosh/simple-message-channels","gitHead":"8b68dc93a381a7ab1b20194e939136b42d9b303b","_id":"simple-message-channels@1.1.2","_nodeVersion":"10.16.0","_npmVersion":"6.9.0","dist":{"integrity":"sha512-kGH9PY3OKaAF2MkDynTC8Rl8ezXcE2VPzvY3bbYtiCH5cGE2ZpXIXJ7K0HjfQ/n5nf4AGRro0rDr2J5EqR6NVg==","shasum":"f4e8f5a1bba1aac20621bdc824dff90f70cc32e2","tarball":"http://registry-npm.ywwl.com/simple-message-channels/download/simple-message-channels-1.1.2.tgz","fileCount":7,"unpackedSize":10359,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdcjaSCRA9TVsSAnZWagAA5NQP/jPyEvZTRhGrttjssGjh\ngs0NVgzoI0+L99G7ZIHUfntqgiEJ/1hju0SreBppRyWiwwKLavKJ+FxI69y1\nM31MkQNAk5v3mcgF26KxEjb1TDHO+pI3OScUydIU4wfTDjz/X+tavNv9GWFZ\nMdWBNzafNFnjX8NPGIJrfwwmZ+z2rtZOoCJCu/8s2NsnNfX3PGi+325FZOtY\nqNW0tE/UR0OO2uIFHdENbjS9ecCCeXT6dij7wmrgdLGMnCa563U+EmS7tyOP\n2K+5+MdjQXTkxZxdHb2k2hxG3z8VbR5XrpFMvwUlVVgDRAggvEITt1tYIUXK\nn31VAa5ytjkoWcbdNr+d9JUFlJ3rWyoQyvihjsExxDN0oJdUzDtkyJ2c1f1C\noayncqQ+BPZ68T3zJ2H9gSV1Mnw1CAQ9JQvpdSJuKCUseibxCN1Pqw2wTeu5\nSudVuYZpJGTR8Bq2iSbY4vVCItlERo1wsmI8llhi34WoGCNKLzrJgIfq7RtG\nahTZcXwr+9a3mYArHBBi/EQiGh/az/csicIYJLd7axYMA9tDr1px48GYuQrg\nMFMc76ukkx5Td+TVhTczMMp9xaaZmyRb4d1lsu09ukcFfAs2gslpYfWE3via\nMcnCfCRbtkFIzySVfdm7ntsEeToKQly2du9Nf+HcrN+tIFLFjF4d6UmJhU9w\n+J60\r\n=I92R\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIE15BW9OqDal79VRANdKAwBZ7oYYJQCGTAnoMht7PaziAiEAhM4m134gq2S93RxqUEqT8tj0mqhgyPSCUbPnakviw3Q="}],"size":3430,"noattachment":false,"key":"/simple-message-channels/-/simple-message-channels-1.1.2.tgz"},"maintainers":[{"name":"mafintosh","email":"mathiasbuus@gmail.com"}],"_npmUser":{"name":"mafintosh","email":"mathiasbuus@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/simple-message-channels_1.1.2_1567766161874_0.4736702199444962"},"_hasShrinkwrap":false,"readme":"# simple-message-channels\n\nSimple streamable state machine that implements a useful channel, message-type, message pattern\n\n```\nnpm install simple-message-channels\n```\n\n[![Build Status](https://travis-ci.org/mafintosh/simple-message-channels.svg?branch=master)](https://travis-ci.org/mafintosh/simple-message-channels)\n\n## Usage\n\n``` js\nconst SMC = require('simple-message-channels')\n\nconst a = new SMC({\n  onmessage (channel, type, message) {\n    console.log('Received a message on channel', channel) // a number\n    console.log('Message type is', type) // a number\n    console.log('And the message payload was', message) // a buffer\n  }\n})\n\nconst b = new SMC()\n\n// produce a payload\nconst payload = b.send(0, 1, Buffer.from('hi'))\n\n// somehow send it to the other instance (over a stream etc)\n// can arrive chunked as long as it arrives in order\na.recv(payload)\n```\n\n(This is the basic wire protocol used by hypercore, https://github.com/mafintosh/hypercore)\n\n## API\n\n#### `payloadBuffer = smc.send(channel, type, message)`\n\nEncode a channel, type, message to be sent to another person.\nChannel can be any number and type can be any 4 bit number.\nMessage should be a buffer.\n\n#### `success = smc.recv(payloadChunk)`\n\nParse a payload buffer chunk. Once a full message has been parsed\nthe `smc.onmessage(channel, type, message)` handler is called.\n\nReturns true if the chunk seemed valid and false if not.\nIf false is returned check `smc.error` to see the error it hit.\n\n#### `payloadBuffer = smc.sendBatch([{ channel, type, message }, ...])`\n\nEncodes a series of messages into a single paylaod buffer.\n\n## License\n\nMIT\n","publish_time":1567766162035,"_cnpm_publish_time":1567766162035,"dist-tags":{"latest":"1.2.1"}}