{"id":19415798,"url":"https://github.com/jurca/post-message-rpc","last_synced_at":"2025-08-17T20:10:54.272Z","repository":{"id":35142748,"uuid":"209513680","full_name":"jurca/post-message-rpc","owner":"jurca","description":"An RPC-like library for contexts connected via the postMessage API with TypeScript support.","archived":false,"fork":false,"pushed_at":"2025-01-21T20:44:05.000Z","size":556,"stargazers_count":2,"open_issues_count":3,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-08T18:33:25.983Z","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/jurca.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-09-19T09:25:39.000Z","updated_at":"2025-01-21T20:44:01.000Z","dependencies_parsed_at":"2025-04-14T12:34:05.654Z","dependency_job_id":"3d0912e4-9914-4433-a8a4-07954049f222","html_url":"https://github.com/jurca/post-message-rpc","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/jurca/post-message-rpc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jurca%2Fpost-message-rpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jurca%2Fpost-message-rpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jurca%2Fpost-message-rpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jurca%2Fpost-message-rpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jurca","download_url":"https://codeload.github.com/jurca/post-message-rpc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jurca%2Fpost-message-rpc/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270899582,"owners_count":24664720,"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","status":"online","status_checked_at":"2025-08-17T02:00:09.016Z","response_time":129,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-11-10T12:44:34.696Z","updated_at":"2025-08-17T20:10:54.250Z","avatar_url":"https://github.com/jurca.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# post-message-rpc\n\n[![Build Status](https://travis-ci.org/jurca/post-message-rpc.svg?branch=master)](https://travis-ci.org/jurca/post-message-rpc)\n[![npm](https://img.shields.io/npm/v/@jurca/post-message-rpc.svg)](https://www.npmjs.com/package/@jurca/post-message-rpc)\n[![License](https://img.shields.io/npm/l/@jurca/post-message-rpc.svg)](LICENSE)\n![npm type definitions](https://img.shields.io/npm/types/@jurca/post-message-rpc.svg)\n\nAn RPC-like library for contexts connected via the postMessage API with\nTypeScript support.\n\n## Installation\n\n`post-message-rpc` is available as npm package, you can use `npm` to install\nit:\n\n```\nnpm install --save @jurca/post-message-rpc\n```\n\n## Usage\n\nThere is separate API for the \"server\" (the RPC methods provider) and the\nclient.\n\n### RPC Server\n\nUse the `createServer` function to create an RPC server expecting procedure\ncalls from other contexts:\n\n```javascript\nimport {createServer} from '@jurca/post-message-rpc'\n\ncreateServer('channel ID', ['whitelist', 'of', 'origins'], {\n  foo(x, y) {\n    return x + y\n  },\n  bar(x) { // procedures may be asynchronous\n    return new Promise((resolve) =\u003e setTimeout(resolve, x)).then(() =\u003e x)\n  },\n  baz() {\n    // Errors thrown (synchronously or asynchronously) by procedures will be\n    // propagated to the client.\n    return Promise.reject(new Error('This is an error'))\n  },\n})\n```\n\nUsing an empty array will allow calls from any origin, but is is strongly\nrecommended for security reasons to always use an origin whitelist.\n\n### RPC Client\n\nUse the `createClient` function to create an RPC client. Use the same channel\nID as the one used to create the RPC server you want to communicate with (Each\ncontext may contain multiple servers and/or clients).\n\n```javascript\nimport {createClient} from '@jurca/post-message-rpc'\n\n(async () =\u003e {\n  const client = await createClient(\n    iframeWindow,\n    {\n      // Connection options, consumed by the @jurca/post-message-p2p package.\n\n      // A string, number, symbol, boolean, null or undefined identifying the\n      // communication channel with the peer.\n      channel: 'channel ID',\n      // An optional timeout for receiving a confirmation that the peer has\n      // received the message, defaults to 10 seconds. Specified in\n      // milliseconds, must be a positive integer.\n      timeout: 100,\n      // The optional origin that is allowed to receive messages sent through\n      // this connection. Defaults to '*', but is recommended to be set for\n      // security reasons.\n      origin: 'https://some.origin.org',\n      // The optional number of retries when trying to perform a handshake\n      // with the provided peer. The connection will not be established if the\n      // peer will not be responding to the handshake messages. Defaults to 2.\n      handshakeRetries: 2,\n      // An optional delay between handshake attempts in milliseconds.\n      // Defaults to 500.\n      handshakeRetryDelay: 3000,\n    },\n    {\n      // This is a template listing the methods exposed by the server that the\n      // client intends to use. While it would be possible to create an\n      // implementation that uses the Proxy API rendering this argument not\n      // needed, it would break compatibility with Internet Explorer.\n      foo: null,\n      bar: null,\n    },\n  )\n\n  const firstResult = await client.foo(10, 12) // firstResult = 22\n  const otherResult = await client.bar(500) // otherResult = 500\n\n  try {\n    await client.baz()\n  } catch (error) {\n    // The error will have the name, message and stack correctly set. The\n    // stack will be the correct stack of the error thrown by the procedure at\n    // the server.\n  }\n})()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjurca%2Fpost-message-rpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjurca%2Fpost-message-rpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjurca%2Fpost-message-rpc/lists"}