{"_id":"@brandwatch/frame-rpc","_rev":"1-c5375e766113ff5beabfd4ebc0bf96a4","name":"@brandwatch/frame-rpc","dist-tags":{"latest":"2.0.1"},"versions":{"2.0.1":{"name":"@brandwatch/frame-rpc","version":"2.0.1","description":"rpc between iframes and windows using postMessage with no serialization","main":"index.js","dependencies":{"isarray":"^2.0.5","url-parse":"^1.2.0"},"devDependencies":{"tape":"^5.2.0"},"scripts":{"test":"tape test/*.js"},"repository":{"type":"git","url":"git://github.com/substack/frame-rpc.git"},"homepage":"https://github.com/substack/frame-rpc","keywords":["browser","iframe","window","rpc","dom"],"author":{"name":"James Halliday","email":"mail@substack.net","url":"http://substack.net"},"license":"MIT","gitHead":"e0fc3bb3b8881ba9207e74be08d60ce30e8dce89","bugs":{"url":"https://github.com/substack/frame-rpc/issues"},"_id":"@brandwatch/frame-rpc@2.0.1","_nodeVersion":"12.18.3","_npmVersion":"7.5.4","dist":{"integrity":"sha512-CRxs+k7Sda0Xb0lqBwluWnft5+MRIdtdijMHb89nDLZocoFY1AlSkuJl4J3H1RDIxBNsgNfv5Zo6hWawg+CcgQ==","shasum":"f2f4354da8d5285db0f33d9c7f6ecf8371827574","tarball":"https://registry.npmjs.org/@brandwatch/frame-rpc/-/frame-rpc-2.0.1.tgz","fileCount":17,"unpackedSize":13649,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgNmrfCRA9TVsSAnZWagAAEnEP/3Xpv5H7+qCc5JyuwRMC\nadYB7EK+PAm4vqfsPSSqArDmaNttY5x8HWC6jz/3KmwzqWNL38CTN2fYzXsu\nU8qXrBPC0uvzsSxh0difQu5YXIHbGDyuGQTDfyhQyTkA/8GcEb5g/2/ZvlGg\n9LJC1vqCd7thOvWPHNdSpqDO9TFSMd74yjMcE+6X43YxnSJITBVnNSxBVfUo\nfex3Eu1Rd+2st1pgfzl47bQ+2cRMHedU/dJOJZ15UO8hgFw3Xh8RieuX0Dmo\nrneMR6A6UfeJCvuRMue9+TVipxTnYoTgCpYerMx+4OolNK2TLzn6H8fxrTE/\nHFoblBvhMEtmoWD1swbQml0ZFcZoNH4lIp06YNBxs3dYART1KG1oiZFkiTjY\nq99OGJ2tOAdUpkB2mIZb0NfuZ6ssGZWLuZDD9uOVr1Gvoe96BcHRg/s5eFWs\nR4YB1kDbh3BQymo7K0CHhF5JfDCXgpdp04YZYHHuGbn533I+wbmtsb0Nw19C\n81wIhYoMbS7qWH2IXbUXcqmhKzsEvetpljEbi1n5XksASzQ+EKs9U/rk8rMf\n7+YMcFpfC6V+qh1EtiX6BYIyI3CNHaeC7armgcxZV5vtLzqVXToB0qbxRUrl\nGWfUx+rD978DVWRgG3zc/1N8ES+oQxHgGnuQTTLB2763FvaUbYV8FppE134p\ntpGK\r\n=I0z5\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGznRHLUvs65wGi4UsOv6YeAE2WEnP/jAEogdBUNU9LGAiADyjzrGUFQPFEBRqL7rKdUmIP7GPchB9KxlJBVRad6wg=="}]},"_npmUser":{"name":"brandwatch","email":"opensource@brandwatch.com"},"directories":{},"maintainers":[{"name":"brandwatch","email":"opensource@brandwatch.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/frame-rpc_2.0.1_1614179039111_0.17649411342517562"},"_hasShrinkwrap":false}},"time":{"created":"2021-02-24T15:03:59.074Z","2.0.1":"2021-02-24T15:03:59.273Z","modified":"2022-04-04T20:26:45.236Z"},"maintainers":[{"name":"brandwatch","email":"opensource@brandwatch.com"}],"description":"rpc between iframes and windows using postMessage with no serialization","homepage":"https://github.com/substack/frame-rpc","keywords":["browser","iframe","window","rpc","dom"],"repository":{"type":"git","url":"git://github.com/substack/frame-rpc.git"},"author":{"name":"James Halliday","email":"mail@substack.net","url":"http://substack.net"},"bugs":{"url":"https://github.com/substack/frame-rpc/issues"},"license":"MIT","readme":"# frame-rpc\n\nrpc between iframes and windows using postMessage with no serialization\n\n[![build status](https://secure.travis-ci.org/substack/frame-rpc.png)](http://travis-ci.org/substack/frame-rpc)\n\n# example\n\nexpose a method from a page that will be loaded as an iframe:\n\n``` js\nvar RPC = require('frame-rpc');\nvar origin = document.referrer;\n\nvar rpc = RPC(window, window.parent, origin, {\n    beep: function (n, cb) {\n        document.querySelector('#n').textContent = n;\n        cb(n * 111);\n    }\n});\n```\n\nthen from the parent page containing the iframe:\n\n``` js\nvar RPC = require('frame-rpc');\nvar frame = document.querySelector('iframe');\nvar usrc = new URL(frame.getAttribute('src'));\nvar origin = usrc.protocol + '//' + usrc.host;\n\nframe.addEventListener('load', function (ev) {\n    var rpc = RPC(window, frame.contentWindow, origin);\n    rpc.call('beep', 5, function (result) {\n        document.querySelector('#result').textContent = result;\n    });\n});\n```\n\n# methods\n\n``` js\nvar RPC = require('frame-rpc')\n```\n\n## var rpc = RPC(src, dst, origin, methods)\n\nCreate a new `rpc` instance that listens for `'message'` events on `src`\nand writes data to `dst.postMessage()`.\n\n`origin` must be the URL of `dst`. Any messages from `src` that do not match\n`origin` are ignored. If `origin` is `'*'`, the location of incoming messages is\nnot checked and the output messages are sent to anyone listening. Use carefully.\n\nAny `methods` defined will be exposed to the other endpoint.\n\n`methods` can be an object with names that map to methods or a function\n`methods(rpc)` that returns an object to map names to methods.\n\nThe last argument of each function exposed in `methods` can be a callback to\nsend a response.\n\nThe protocol is symmetric so each side can expose methods to the other side.\n\n## rpc.call(method, args...)\n\nCall a `method` on the remote endpoint with some arguments `args..`.\n\nThe last argument can be a callback for receiving a reply.\n\n## rpc.apply(method, args)\n\nCall a `method` on the remote endpoint with an array of arguments `args`.\n\nThe last argument can be a callback for receiving a reply.\n\n## rpc.destroy()\n\nRemove the event listeners and don't respond to any more messages.\n\n# protocol\n\nThe protocol is designed to only listen to frame-rpc messages because often\nthere is a lot of noise over the postMessage event bus from other subsystems\n(polyfills for setImmediate send messages, for example).\n\nEach message is either a method request with parameters in `arguments`:\n\n``` js\n{\n  protocol: 'frame-rpc',\n  version: '1.0.0',\n  sequence: 123,\n  method: 'beep',\n  arguments: [ 5 ]\n}\n```\n\nor a callback response that contains the method result(s) in `arguments`:\n\n``` js\n{\n  protocol: 'frame-rpc',\n  version: '1.0.0',\n  response: 123,\n  arguments: [ 555 ]\n}\n```\n\nAll other messages that don't match these formats are ignored.\n\n# install\n\nWith [npm](https://npmjs.org) do:\n\n```\nnpm install frame-rpc\n```\n\nor fetch a pre-built version from [browserify-cdn](http://wzrd.in):\n\n[http://wzrd.in/standalone/frame-rpc@latest](http://wzrd.in/standalone/frame-rpc@latest)\n\n# license\n\nMIT\n","readmeFilename":"readme.markdown"}