{"name":"simple-message-channels","version":"1.1.0","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":"bc1321ab62e7236d9244ef84e3885fbcf86427d7","_id":"simple-message-channels@1.1.0","_nodeVersion":"10.16.0","_npmVersion":"6.9.0","dist":{"integrity":"sha512-c3y7zsXmauiL+NQ1hqsbOvB/rIaw3s4o1Oz9oetc+Z4iaGp+Nb96HQSywO503xU+mj2tCjNlbTe9rvIXv+prqg==","shasum":"64ebe619dcad4bac5e23674721694dcfb71ff21c","tarball":"http://registry-npm.ywwl.com/simple-message-channels/download/simple-message-channels-1.1.0.tgz","fileCount":7,"unpackedSize":9794,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdZ8G0CRA9TVsSAnZWagAAho0QAJisWfHZWK72jKITJUXq\n155u8dDiUSdKEPBVEWM0rvP+i3HzDoIKfVJ+KGQYxXSAD9glcCZDZZFPOdBw\nlFa9o7N0PkaF7wDLqSuZg5NqQ1ieYdyUl7KwOtgIHxB/2dVpFUu6+faaUDh8\nhd47O5q9Ds4SQlIxhQ8sEOzf2arhnI4j6NrVy6I0C6pqWPJ05nK8yNBQapY9\n3OcXxbpRjCi5FKzoQyymdtoP8oKiK3T9lb1jdYggFtZFOLdVIu5vEk7PSDuG\nRtevUEAhiFa9b5EUa3V4tq7gibMK4XrAUWq2+XZrej34g+SJV8MdP3IrE9Hx\nDQ0DNFoscuBCiBEA/Oi0LeMDwdZhYfvo5PLlakzD1ChTucoDempl5WAqzAOB\nhY6iaGtx6M0DMVHppvWduhgbPoC/PwvYia1ShkzOh6f7GDNdKMuQhTLmBNPo\nSPsw4O6Oxtiwstqdly/swp9NGnRuL4FSQzWRJylr1LhEiaTyerlTXJ7EMv3l\nR9KnPhPx1Wkuw3AQ3/PUhHhVZyV7sSh7eyJqgd63ccI3+zFQ1QjeV9CPWi3q\nEjMZ5EseweGZxHSOgZMY2AlVnghEYAXapM6kMtyPa1Dwvt/pc5T+GbnxdWap\nJyoymJsrEk07C8lf3e/WvdMpX0trO8rs7qP0K5ipegtf9727BD9QuDBUligz\nX0F2\r\n=2QO8\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFGMKaXdIsKpVFxYcbtG794k/PxMxyoiYgssbytOVkAOAiALMhIFl/+icuiQuuYeb+XFLvzEMIYw88pzXHhkB6iISw=="}],"size":3337,"noattachment":false,"key":"/simple-message-channels/-/simple-message-channels-1.1.0.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.0_1567080883667_0.9311013423336287"},"_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":1567080883794,"_cnpm_publish_time":1567080883794,"dist-tags":{"latest":"1.2.1"}}