# @wexond/rpc-electron

> Type-safe inter-process communication for Electron

Latest version **1.0.3** (published 2021-02-06) · 0 weekly downloads

## Install

```sh
npm install @wexond/rpc-electron
pnpm add @wexond/rpc-electron
yarn add @wexond/rpc-electron
bun add @wexond/rpc-electron
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2021-02-06 |
| First published | 2020-11-05 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 23 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 36 |
| Maintainers | sential, xnerhu |
| Keywords | electron, typescript, ipc, grpc, main, renderer |

## Links

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

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.3 (latest) — 2021-02-06
- 1.0.2 — 2020-11-11
- 1.0.1 — 2020-11-05
- 1.0.0 — 2020-11-05

## README

# @wexond/rpc-electron

Type-safe communication between Electron processes.
No more remembering IPC channel names, parameters order and their types.

[![NPM](https://img.shields.io/npm/v/@wexond/rpc-electron.svg?style=flat-square)](https://www.npmjs.com/package/@wexond/rpc-electron)
[![NPM](https://img.shields.io/npm/dm/@wexond/rpc-electron?style=flat-square)](https://www.npmjs.com/package/@wexond/rpc-electron)

## Installation

```bash
$ npm install --save @wexond/rpc-electron @wexond/rpc-core
```

## Quick start

Here's an example of communication from the renderer process to the main process:

- Create a file that is imported in both main and renderer processes, for example `ping-pong.ts`:

```ts
import { RendererToMainChannel } from '@wexond/rpc-electron';

export interface PingPongService {
  ping(): string;
}

export const pingPongChannel = new RendererToMainChannel<PingPongService>(
  'ping-pong',
);
```

- Code for the renderer process:

```ts
import { ipcRenderer } from 'electron';
import { pingPongChannel } from './ping-pong';

const pingPongService = pingPongChannel.getInvoker();

(async () => {
  // Equivalent of |ipcRenderer.invoke|
  console.log(await pingPongService.ping()); // Prints `pong`.
})();
```

- Code for the main process:

```ts
import { RpcMainHandler } from '@wexond/rpc-electron';
import { PingPongService, pingPongChannel } from './ping-pong';

// Equivalent of |ipcMain.handle|
class PingPongHandler implements RpcMainHandler<PingPongService> {
  ping(): string {
    return 'pong';
  }
}

pingPongChannel.getReceiver().handler = new PingPongHandler();
```

### More examples

- [Renderer to Main](examples/renderer-to-main)

## Documentation

WIP

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