{"_id":"message-pair","_rev":"480977","name":"message-pair","description":"Small module to implement a \"message name to id\" pairing protocol","dist-tags":{"latest":"2.0.1"},"maintainers":[{"name":"mafintosh","email":""}],"time":{"modified":"2021-08-05T09:36:56.000Z","created":"2019-10-12T16:11:41.334Z","2.0.1":"2019-10-12T19:39:51.492Z","2.0.0":"2019-10-12T19:17:32.470Z","1.2.0":"2019-10-12T18:48:04.054Z","1.1.0":"2019-10-12T18:38:35.985Z","1.0.0":"2019-10-12T16:12:01.483Z","0.0.0":"2019-10-12T16:11:41.334Z"},"users":{},"author":{"name":"Mathias Buus","url":"@mafintosh"},"repository":{"type":"git","url":"git+https://github.com/mafintosh/message-pair.git"},"versions":{"2.0.1":{"name":"message-pair","version":"2.0.1","description":"Small module to implement a \"message name to id\" pairing protocol","main":"index.js","dependencies":{"codecs":"^2.0.0"},"devDependencies":{"standard":"^14.3.1","tape":"^4.11.0"},"scripts":{"test":"standard && tape test.js"},"repository":{"type":"git","url":"git+https://github.com/mafintosh/message-pair.git"},"author":{"name":"Mathias Buus","url":"@mafintosh"},"license":"MIT","bugs":{"url":"https://github.com/mafintosh/message-pair/issues"},"homepage":"https://github.com/mafintosh/message-pair","gitHead":"c68866926d5b1c7c30ef30186ecb77925d5df1de","_id":"message-pair@2.0.1","_nodeVersion":"10.16.3","_npmVersion":"6.9.0","dist":{"shasum":"13e1e6d77894932a7fb01a9676350a7422d2ec52","size":3623,"noattachment":false,"key":"/message-pair/-/message-pair-2.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/message-pair/download/message-pair-2.0.1.tgz"},"maintainers":[{"name":"mafintosh","email":""}],"_npmUser":{"name":"mafintosh","email":"mathiasbuus@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/message-pair_2.0.1_1570909191391_0.3128393163170864"},"_hasShrinkwrap":false,"publish_time":1570909191492,"_cnpm_publish_time":1570909191492,"deprecated":"see abstract-extension instead"},"2.0.0":{"name":"message-pair","version":"2.0.0","description":"Small module to implement a \"message name to id\" pairing protocol","main":"index.js","dependencies":{"codecs":"^2.0.0"},"devDependencies":{"standard":"^14.3.1","tape":"^4.11.0"},"scripts":{"test":"standard && tape test.js"},"repository":{"type":"git","url":"git+https://github.com/mafintosh/message-pair.git"},"author":{"name":"Mathias Buus","url":"@mafintosh"},"license":"MIT","bugs":{"url":"https://github.com/mafintosh/message-pair/issues"},"homepage":"https://github.com/mafintosh/message-pair","gitHead":"75570245f54519c8b1c04ded54689680e5cdeb7b","_id":"message-pair@2.0.0","_nodeVersion":"10.16.3","_npmVersion":"6.9.0","dist":{"shasum":"1b807e5506ce0cbd1d33a635db368368ccf820e3","size":3550,"noattachment":false,"key":"/message-pair/-/message-pair-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/message-pair/download/message-pair-2.0.0.tgz"},"maintainers":[{"name":"mafintosh","email":""}],"_npmUser":{"name":"mafintosh","email":"mathiasbuus@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/message-pair_2.0.0_1570907852347_0.9340365664461008"},"_hasShrinkwrap":false,"publish_time":1570907852470,"_cnpm_publish_time":1570907852470,"deprecated":"see abstract-extension instead"},"1.2.0":{"name":"message-pair","version":"1.2.0","description":"Small module to implement a \"message name to id\" pairing protocol","main":"index.js","dependencies":{"codecs":"^2.0.0"},"devDependencies":{"standard":"^14.3.1","tape":"^4.11.0"},"scripts":{"test":"standard && tape test.js"},"repository":{"type":"git","url":"git+https://github.com/mafintosh/message-pair.git"},"author":{"name":"Mathias Buus","url":"@mafintosh"},"license":"MIT","bugs":{"url":"https://github.com/mafintosh/message-pair/issues"},"homepage":"https://github.com/mafintosh/message-pair","gitHead":"5622630a1739acdf9d97ae16d2bdeff1d3e66eb9","_id":"message-pair@1.2.0","_nodeVersion":"10.16.3","_npmVersion":"6.9.0","dist":{"shasum":"c91f0c2828227f242fb231325ba5c38453b1c60a","size":3450,"noattachment":false,"key":"/message-pair/-/message-pair-1.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/message-pair/download/message-pair-1.2.0.tgz"},"maintainers":[{"name":"mafintosh","email":""}],"_npmUser":{"name":"mafintosh","email":"mathiasbuus@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/message-pair_1.2.0_1570906083874_0.9810752463097234"},"_hasShrinkwrap":false,"publish_time":1570906084054,"_cnpm_publish_time":1570906084054,"deprecated":"see abstract-extension instead"},"1.1.0":{"name":"message-pair","version":"1.1.0","description":"Small module to implement a \"message name to id\" pairing protocol","main":"index.js","dependencies":{"codecs":"^2.0.0"},"devDependencies":{"standard":"^14.3.1","tape":"^4.11.0"},"scripts":{"test":"standard && tape test.js"},"repository":{"type":"git","url":"git+https://github.com/mafintosh/message-pair.git"},"author":{"name":"Mathias Buus","url":"@mafintosh"},"license":"MIT","bugs":{"url":"https://github.com/mafintosh/message-pair/issues"},"homepage":"https://github.com/mafintosh/message-pair","gitHead":"17099a4aedac6d8c754bbe6daedaac3d4f79798d","_id":"message-pair@1.1.0","_nodeVersion":"10.16.3","_npmVersion":"6.9.0","dist":{"shasum":"21a5040fa6e91fe7d7b8eb5af94b65f0c2d0c35a","size":3418,"noattachment":false,"key":"/message-pair/-/message-pair-1.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/message-pair/download/message-pair-1.1.0.tgz"},"maintainers":[{"name":"mafintosh","email":""}],"_npmUser":{"name":"mafintosh","email":"mathiasbuus@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/message-pair_1.1.0_1570905515885_0.2787645174333522"},"_hasShrinkwrap":false,"publish_time":1570905515985,"_cnpm_publish_time":1570905515985,"deprecated":"see abstract-extension instead"},"1.0.0":{"name":"message-pair","version":"1.0.0","description":"Small module to implement a \"message name to id\" pairing protocol","main":"index.js","dependencies":{"codecs":"^2.0.0"},"devDependencies":{"standard":"^14.3.1","tape":"^4.11.0"},"scripts":{"test":"standard && tape test.js"},"repository":{"type":"git","url":"git+https://github.com/mafintosh/message-pair.git"},"author":{"name":"Mathias Buus","url":"@mafintosh"},"license":"MIT","bugs":{"url":"https://github.com/mafintosh/message-pair/issues"},"homepage":"https://github.com/mafintosh/message-pair","gitHead":"bbd805b18799af4ed868ff67359921c73e8c71a1","_id":"message-pair@1.0.0","_nodeVersion":"10.16.3","_npmVersion":"6.9.0","dist":{"shasum":"7f1a0f9dd082b11aa38968ddccae530db301a5b2","size":3417,"noattachment":false,"key":"/message-pair/-/message-pair-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/message-pair/download/message-pair-1.0.0.tgz"},"maintainers":[{"name":"mafintosh","email":""}],"_npmUser":{"name":"mafintosh","email":"mathiasbuus@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/message-pair_1.0.0_1570896721261_0.8492566474947509"},"_hasShrinkwrap":false,"publish_time":1570896721483,"_cnpm_publish_time":1570896721483,"deprecated":"see abstract-extension instead"},"0.0.0":{"name":"message-pair","version":"0.0.0","description":"Small module to implement a \"message name to id\" pairing protocol","main":"index.js","dependencies":{"codecs":"^2.0.0"},"devDependencies":{"standard":"^14.3.1","tape":"^4.11.0"},"scripts":{"test":"standard && tape test.js"},"repository":{"type":"git","url":"git+https://github.com/mafintosh/message-pair.git"},"author":{"name":"Mathias Buus","url":"@mafintosh"},"license":"MIT","bugs":{"url":"https://github.com/mafintosh/message-pair/issues"},"homepage":"https://github.com/mafintosh/message-pair","gitHead":"6d1c4ffe07bd6077a390bb3107485e314cb1f58f","_id":"message-pair@0.0.0","_nodeVersion":"10.16.3","_npmVersion":"6.9.0","dist":{"shasum":"7ba001a679e5f3bd9bf4becf660b662768692249","size":3418,"noattachment":false,"key":"/message-pair/-/message-pair-0.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/message-pair/download/message-pair-0.0.0.tgz"},"maintainers":[{"name":"mafintosh","email":""}],"_npmUser":{"name":"mafintosh","email":"mathiasbuus@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/message-pair_0.0.0_1570896701210_0.7108718219489587"},"_hasShrinkwrap":false,"publish_time":1570896701334,"_cnpm_publish_time":1570896701334,"deprecated":"see abstract-extension instead"}},"readme":"# message-pair\n\nSmall module to implement a \"message name to id\" pairing protocol, useful for implementing stuff like user defined messages\nin an RPC system without having to send over the full message name every time.\n\n... you probably don't need this :)\n\n```\nnpm install message-pair\n```\n\n## Usage\n\n``` js\nconst MessagePair = require('message-pair')\n\nconst messages = new MessagePair()\n\nconst m = messages.add('message-name', {\n  onmessage (message) {\n    console.log('received message', message)\n  }\n})\n\n// local id of this message is 0\nconsole.log('local id of this message is', m.id)\n\nconst another = new MessagePair()\n\n// add as many messages as you want\nanother.add('another-message-name')\nconst n = another.add('message-name')\n\n// remote id of \"message-name\" is 1\nconsole.log('remote id of this message is', n.id)\n\n// pair the two by exchanging the message names once\nconst remote = messages.remote()\nremote.update(another.names())\n\n// then pass the id and message\n// will trigger m.onmessage\nremote.onmessage(n.id, n.encode('hi'))\n```\n\n## API\n\n#### `const messages = new MessagePair(handlers)`\n\nCreate a new MessagePair instance.\n\nWhenever the messages are updated `handler.onnamesupdate()` will\nbe called if provided.\n\n#### `const msg = messages.add(name, handlers)`\n\nAdd a new message. `name` should be the string name of a message.\n\n* `handlers.encoding` is an optional encoding for the message payload. Can be either `json`, `utf-8`, `binary` or any abstract encoding.\n* `handlers.onmessage(message, context)` is called when a message has been received and pairing.\n* `handlers.onerror(error, context)` is called when a message fails to decode.\n\n#### `msg.destroy()`\n\nRemoves the message from the pairing instance.\n\n#### `msg.id`\n\nThe local id of the message. Send this over the wire instead of the message name after exchanging the initial message names.\n\n#### `const bool = msg.remoteSupports()`\n\nTrue if the remote also supports this message. Note that nothing bad will having from sending a message the remote does not support.\n\n#### `const buffer = msg.encode(message)`\n\nEncode a message to a buffer based on the message encoding.\n\n#### `const list = messages.names()`\n\nReturns a sorted list of message names. You need to pass this to another remote pairing instance somehow.\n\n#### `const remote = messages.remote()`\n\nCall this to setup remote pairing.\n\n#### `remote.update(names)`\n\nPass the names of another instance to setup the pairing\n\n#### `remote.onmessage(id, message, [context])`\n\nPair the remote id with the corresponding local message and call the onmessage handler.\nOptionally pass a context object that is simply passed along to the `message.onmessage` function\n\n## License\n\nMIT\n","_attachments":{},"homepage":"https://github.com/mafintosh/message-pair","bugs":{"url":"https://github.com/mafintosh/message-pair/issues"},"license":"MIT"}