{"name":"simple-message-channels","version":"1.2.1","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":"318e0281eb3b491fc1715c69944e2f86e990f797","_id":"simple-message-channels@1.2.1","_nodeVersion":"10.16.3","_npmVersion":"6.9.0","dist":{"integrity":"sha512-knSr69GKW9sCjzpoy817xQelpOASUQ53TXCBcSLDKLE7GTGpUAhZzOZYrdbX2Ig//m+8AIrNp7sM7HDNHBRzXw==","shasum":"d827d3da0df1f862fd09b748457a01f9a0eb7ac3","tarball":"http://registry-npm.ywwl.com/simple-message-channels/download/simple-message-channels-1.2.1.tgz","fileCount":7,"unpackedSize":11693,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdnct/CRA9TVsSAnZWagAALY8P/j6bF+bzyTB0lPBgwJNX\nqL2dhM8qeh6VhGUXX032lBOpLPI4anLDZzpzgbr2Uq4Bw4lEXWNuG5onSLnL\ngfYJCzDxO7J5LRbfks2qt8Nn1kCsWzSwGyhqW+RnIONaTUyGDmGD4sw98Yt4\nML7JNWa7boST1/kYU2rTP99kt7uI4B2+nB8w77brZpf1WVqdMB6DtyHDZsIr\nnpQyIanp5F9X5gZWc/vpE3xwzyQw3nTqJ/qUafkpZdaxfEy5P3ppcu1S6dMs\nXOPJcvcVlvJTQogunpS8be8O1sDC6JDMgCBei3G86DGxgF+gE7yrn9B541sx\n4xmUIWmQX0iWQUkws/O7lFfDfqY97L6i6/KVds3TdESG8jUYOcTUscrye9X1\nud//+CF1RkJ4+7lrVwrX7+bKOe84XQVATgKjx4AIZZ4YIInoqdwIIB4vQ5XD\nmVJx92bInPm1Gql88BV2++o9EA2NIJEHiTj23nKcvssD6jMbDtD1Vcs/xALa\nZKFzCJJbSh5ZFOPQZ/OAyYl9wDuQ5BaS1mRbcwDHty8upbftIUXkJnvicKG0\n4kOlmiJ+48LHmJ9e98fGs59OiJNfCi7eSb5HHnAzwq13hBLCN3oOAq8jxUuv\nCo4v7fgqkNYraF3t3x5Fvfspmt1zs3uS8RygkzwRiVj4G0CG/0egcZ0/Y7QL\nDujR\r\n=XheD\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC63AuVKmU7QIvq2gZcYO0aI3AeaNW0OHKakb8+sKZ6swIhAOYL9cn46cnn2Da2XwUbgZqBwaIwZlJSM+LWVozFi49F"}],"size":3625,"noattachment":false,"key":"/simple-message-channels/-/simple-message-channels-1.2.1.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.2.1_1570622334533_0.29251376370660886"},"_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":1570622334699,"_cnpm_publish_time":1570622334699,"dist-tags":{"latest":"1.2.1"}}