# @ameerthehacker/frame-rpc

> Communication between browser windows using jsonrpc

Latest version **0.0.6** (published 2022-01-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install @ameerthehacker/frame-rpc
pnpm add @ameerthehacker/frame-rpc
yarn add @ameerthehacker/frame-rpc
bun add @ameerthehacker/frame-rpc
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.6 |
| Published | 2022-01-23 |
| First published | 2022-01-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 20.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 21 |
| Author | Ameer Jhan |
| Maintainers | ameerthehacker |
| Keywords | iframe, jsonrpc |

## Links

- npm: https://www.npmjs.com/package/@ameerthehacker/frame-rpc
- Repository: https://github.com/ameerthehacker/iframe-rpc
- Homepage: https://github.com/ameerthehacker/iframe-rpc#readme
- Issues: https://github.com/ameerthehacker/iframe-rpc/issues
- npm.io page: https://npm.io/package/@ameerthehacker/frame-rpc

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.0.6 (latest) — 2022-01-23
- 0.0.5 — 2022-01-23
- 0.0.4 — 2022-01-23
- 0.0.3 — 2022-01-23
- 0.0.2 — 2022-01-23
- 0.0.1 — 2022-01-23

## README

# Frame RPC

Iframe/Window communications using post messages is such a pain in the arse

- Manage handshakes
- We don't get strong contract
- Write never ending switch statements

This reimagines Iframe communication using JSON RPC. What if you can just call a function to do something in your iframe without thinking in terms of postmessages and get something back without thinking about listening for messages?

## Demo

Play with sandbox [here](https://codesandbox.io/s/frame-rpc-main-window-m3mnx?file=/src/App.tsx)

## How to use it?

### In the Iframe application

```js
import { createBackend } from '@ameerthehacker/frame-rpc';

createBackend({
  add: (num1, num2) => {
    return num1 + num2;
  },
});
```

### In the main application

```js
import { FrameRPC } from '@ameerthehacker/frame-rpc';

const iframeElement = document.getElementById('iframe-element');
const iframeRPC = new FrameRPC(iframeElement.contentWindow);

await iframeRPC.handshake();

const frontend = iframeRPC.createFrontend();
const result = await frontend.add(2, 5);

// will print 7 😃
console.log(result);
```

You can have strong contracts using typescript generic and you can refer to the code in playground for samples.

### Try locally

```
yarn
yarn start
```

## License

MIT © [Ameer Jhan](mailto:ameerjhanprof@gmail.com)

---
_Source: https://npm.io/package/@ameerthehacker/frame-rpc · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
