{"name":"simple-message-channels","version":"1.2.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":"5bcf1e469c7bc6308c0857aad32c3a0d88a98101","_id":"simple-message-channels@1.2.0","_nodeVersion":"10.16.3","_npmVersion":"6.9.0","dist":{"integrity":"sha512-nhGGCqmTGAG7fMgvL/JHoWlA8KO9J0JPFIKch6hLAVKDi9ms0v1uKHrcE6zHv3chxOVUCxRAoK7mKObPGVEUwA==","shasum":"51cf40b0dc730f61823e58dbd8ad37a57e112709","tarball":"http://registry-npm.ywwl.com/simple-message-channels/download/simple-message-channels-1.2.0.tgz","fileCount":7,"unpackedSize":11679,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdnaV2CRA9TVsSAnZWagAAa64P/1AgjKdDtAHhp1Ic7ES7\nHmCivrhm+zrQ9nd6j65EYPnO4uARnv9hADhCjQl7lplUl2LstiDOjK6sCcKw\nyospgLi+xZK99XKCXpH9kOzREI/BoOHlcnrgxYnaT1YC6yH4Y2whSUqB0DTH\noQ+ZVmE8tbHBVUQ1HYuBtczlDChhSel6Idvt9WF/boo7zK1NYb5r7mj/N+Jd\nQL+CbnJe5kJKUcKdaOQ/fW0UxkOcFY0+Fw04afYYdgBhAIerfPPaKJVoDVts\nhk25TGioF0vXezeb3Q81Ck5GKUlxf6fxftpBdF/2UoFajZzAwR6SKre0uguN\nef9m6jJKJuwg64ktMhCB8IDySdjkOa+SEJ96xJau19J7xLTwUPA9FRupzfRy\nmJ68eBZ6MiWIhOkzhwmdSJZmHU3/XcQHD6/gvePa794GHrfddqM806XLVJXl\nu/l0eQxYz23tJf94i1yh6qO2EqBZnU/sei8410oR0Rssl+lj02Xu9WsFG+Ec\nYP1K8Yaje/NcA6GYiUs4XATHwp09cwxN5uCD8rfApoWEEN6YKPSCenc1185A\nV8xofPyY3vo8qEt3m7txiHKpA1nhn/iOB9B5ze+4zYqVc8KZ3bUG5+fNgyaM\n/PedSQ7HRpeGwXLr2hZSMiLIH+J4SHVe0kJq7IDnE/fFhbWo9ZRfu+9byeI8\nOY86\r\n=MQLs\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCz6Gg7USPPVTUDqADPAwbOf9iZ6sR1WvALqRB4Bb6ZUwIhAN5+BKHplvwv8dh/0WpW0NJN/BcPkQjZ+fdkOQaaTjOS"}],"size":3618,"noattachment":false,"key":"/simple-message-channels/-/simple-message-channels-1.2.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.2.0_1570612597707_0.7604325820192193"},"_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":1570612597869,"_cnpm_publish_time":1570612597869,"dist-tags":{"latest":"1.2.1"}}