{"name":"simple-message-channels","version":"1.1.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":"86aa23da7397be4de8e0557e68ef3775f4542b7e","_id":"simple-message-channels@1.1.1","_nodeVersion":"10.16.0","_npmVersion":"6.9.0","dist":{"integrity":"sha512-jXKdngau+H4nbzaAdC2lZNJgQ+fsLLxc5CHuIDIiA1ck8LslWAcNCfo6WJxHePl9ARzJc6qzy+T7SttmNpdV9A==","shasum":"326a22e87f888f319da05112f5db8f56c651f721","tarball":"http://registry-npm.ywwl.com/simple-message-channels/download/simple-message-channels-1.1.1.tgz","fileCount":7,"unpackedSize":9842,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdZ8oMCRA9TVsSAnZWagAAMqkP+wbrU8Dsd6gq1uDr2HGz\nVoA5wZ34rBsX2aYC5BItL5d7BUS68PDt5f7xpmyOZcABeGLwoPUdBWxe1nF9\n2hMRljeQnbtVbQsWI/tEDJwHxxNDnMULivWyjdQvwDH37wrJu7gLIn0jBg1G\nelif99/V2AmEcP7MCb95ZzI3P13c4FB/3wtKR/uTbG3B23DwHLNpI4ulE1Uh\nut/It8xuxz68hbB2we159479PXQkQUFFXoMxICx0QRlfwcuAFe4VNMexhTBX\noIOlF9SO6BejGp+jUDl9mIu9WQSNx4ZMesWTN2absVgNVYbDlzNZk/stdNz8\ncNcTD4ttgpoySfbV0Uzdb0zwU50yb9n9CP0GdIv6eAf3dsRhV/Zj+xsG9Xyf\n3R/C4Qyv6LdMEd0Sb6FaKlmOXR7JBZwDkupEr4LYdxwARoH/vuyQiTwRk0bR\ntYu74Kza/qQUn9GvuehFheS7+OtAysjxHgYm0WDftw5rVo5ZlGJL/d+SRnuH\nDb7zhL+TfoeAIpXdwLY3e7Df1kmZRv6kmZVfq3pn2bw59tWlDlarWjMTw7ki\nhaj4/7obpvgY44N7F90bOiIwus77Ko/2sK9OsbP2A38IH/ze+xRVG2W9JJFM\nVy9m+uKPcsyuK4f5ViDWUy4n9XY+vqZFljUoenwdmmb4C10vlFpQlu9HtEtm\nszNh\r\n=EkBU\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCacYf85CPA8XnNHHMYi8KZl40D39rWKS/2YCiccnpumQIgMNLfCwsIhrwUOPggW/aTX2pCE2ik5SUzKM95wQElp0c="}],"size":3347,"noattachment":false,"key":"/simple-message-channels/-/simple-message-channels-1.1.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.1.1_1567083019464_0.9295307217782194"},"_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":1567083019643,"_cnpm_publish_time":1567083019643,"dist-tags":{"latest":"1.2.1"}}