{"name":"simple-message-channels","version":"0.0.0","description":"Simple streamable state machine that implements a useful channel, message-type, message pattern","main":"index.js","dependencies":{"varint":"^5.0.0"},"devDependencies":{"standard":"^13.1.0"},"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","_id":"simple-message-channels@0.0.0","_nodeVersion":"10.16.0","_npmVersion":"6.9.0","dist":{"integrity":"sha512-w4fxaHwEUpSrkNajZena+JuGjMCVI4DhmmsrGAa6etOHKojwuIaKR3Y7n4mF3e+JfDdwe2lCAyrjedmSFog+zg==","shasum":"db1eaa1202b105ceefec5224887438b960426417","tarball":"http://registry-npm.ywwl.com/simple-message-channels/download/simple-message-channels-0.0.0.tgz","fileCount":5,"unpackedSize":7204,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdTYdiCRA9TVsSAnZWagAAEWIP/iRHgoQ+XUlYGZw2FP71\nHeFJ/EuVlX2/AU4RWqT26QokxDLoXBMCI1hrL8HSLpDih47oslXoXoIsj+oA\nVeGpv40GKxE/ccFiAzpqm06JdiYdEap8pbIlU/nhV5JbJ/mm17i4/65K8jxx\nYCW1PQ3XhzIe/eYSdIqyHB15R3kBXGS5/NLvCTn6YAqTFwDiOBxZe6paFSIz\nzmBQI/VgiVnC8HhFHwW2hPhu9H3QaLPKgv+A3dOb/VHUNmH6dl5NGc3kVqgO\nK+kUhGrKF+go8OomCJgb/9+G9HmRprBOuNJK973UDYgoyPR/ZgGO0bO7rgio\nr5N1scNCrC7llDhdmUCEoYkzECQ7vcteMcBzWukoaYGHLYB/rpW0ZtIXQ94j\nZ7QXCoLpR+oyRad1IbLsbn7bMdTYVVTKP7jfxIzdTm346X2zLJ0N7WHvcBCb\ne7RYBdXOqcbsVHO5UftetqpspicfPRzU/dHcrnIZPQ23Qsv5vREJjDICDN0Z\n+vzzXHBEqEJtz+egyQLtqVJVATHmMTNXgN3fWybK0K+HUJ9n9Lya4GoYZHXX\nKtP9ZDCJqwP272vxwnaoe7XSRB/91hnPWGlQck5aC52OCB7mhevUuDShg6em\n6VsRJQsjdSpKEjAibufbfwDnrvAHWOTq8r7VSiJuWO3B81wv2kSrpfLa6dQU\nHcZ8\r\n=kDgh\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDoPMUqWUKYt9FNgxeievaWtz8N43vYroMwayorMOvRpAIhAILsNCNr/pZ05pL7QsTdTmWsLnkCkHowSnaecZ9Bum/f"}],"size":2741,"noattachment":false,"key":"/simple-message-channels/-/simple-message-channels-0.0.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_0.0.0_1565362017902_0.2613699501357276"},"_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":1565362018080,"_cnpm_publish_time":1565362018080,"dist-tags":{"latest":"1.2.1"}}