{"id":13567841,"url":"https://github.com/statianzo/pmrpc","last_synced_at":"2025-04-13T14:41:12.147Z","repository":{"id":57162570,"uuid":"149678162","full_name":"statianzo/pmrpc","owner":"statianzo","description":"JSON-RPC over postMessage","archived":false,"fork":false,"pushed_at":"2020-05-03T20:36:01.000Z","size":57,"stargazers_count":6,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-16T03:14:37.481Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/statianzo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-20T22:32:03.000Z","updated_at":"2023-04-28T03:18:52.000Z","dependencies_parsed_at":"2022-09-09T10:22:21.632Z","dependency_job_id":null,"html_url":"https://github.com/statianzo/pmrpc","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statianzo%2Fpmrpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statianzo%2Fpmrpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statianzo%2Fpmrpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statianzo%2Fpmrpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/statianzo","download_url":"https://codeload.github.com/statianzo/pmrpc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240086522,"owners_count":19745828,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T13:02:45.599Z","updated_at":"2025-02-23T14:32:03.204Z","avatar_url":"https://github.com/statianzo.png","language":"TypeScript","funding_links":[],"categories":["TypeScript","Libraries"],"sub_categories":[],"readme":"# @statianzo/pmrpc\n\n[![Build Status](https://travis-ci.org/statianzo/pmrpc.svg?branch=master)](https://travis-ci.org/statianzo/pmrpc)\n\nJSON-RPC implemented using postMessage API\n\n## Installation\n\n```sh\nnpm install @statianzo/pmrpc\n```\n\n## Usage\n\n### iframe within parent\n\n```js\nimport JsonRpc from './JsonRpc';\n\nconst rpc = new JsonRpc({\n  methods: {\n    greet: name =\u003e `Hello ${name}`\n  },\n  source: window\n});\n```\n\n\n### Parent window\n\n```js\nimport JsonRpc from './JsonRpc';\n\nconst rpc = new JsonRpc({\n  destination: iframe.contentWindow\n});\n\nrpc\n  .call('greet', 'World')\n  .then(response =\u003e {\n    console.log(response); // \"Hello World\"\n  });\n```\n\n## JsonRpc Options\n\n- `origin` - (Default: `*`) Origin to send messages\n- `methods` - (Default: `{}`) An object of exposed methods. Returning a Promise will defer responding until the promise has completed\n- `source` - The source EventTarget to mount JSON rpc on (`Window`, `MessagePort`, etc)\n- `destination` - Target MessageEventSource to send requests to\n\n## API\n\n### JsonRpc.apply(method, [arg1, arg2, ...])\n\nInvoke a remote rpc method with an array of arguments (like `Function.apply`).\nReturns a `Promise` with the result of the request. Errors from the endpoint\nwill result in a rejected promise.\n\n### JsonRpc.call(method, ...args)\n\nInvoke a remote rpc method with a variadic list of arguments (like\n`Function.call`). Returns a `Promise` with the result of the request.\nErrors from the endpoint will result in a rejected promise.\n\n### JsonRpc.mount(source)\n\nMount JsonRpc to a source EventTarget (Window, MessagePort, Worker). This is\ncalled automatically when a `source` is passed to the constructor.\n\n### JsonRpc.unmount()\n\nDetach the event listener from the JsonRpc instance's `source`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstatianzo%2Fpmrpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstatianzo%2Fpmrpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstatianzo%2Fpmrpc/lists"}