npm.io
1.2.0 • Published 6 years ago

rx-ipc

Licence
MIT
Version
1.2.0
Deps
2
Size
12 kB
Vulns
0
Weekly
0
Stars
1

RxJS Utility for Electron IPC

Modules

Proxy Observables

Create an Observable in one process, and remotely observe it from another.

In Renderer Process
import "rx-ipc/add/operator/proxify";
import { of } from "rxjs/observable/of";
import { v4 as uuid } from "node-uuid";
import { ipcRenderer as ipc } from "electron";

const channel = "some-identifier";
const proxiedEvents = of("foo").proxify({ ipc, channel, uuid });

proxiedEvents.subscribe(({ observer, payload }) => {
  // maps to a "proxy report"
  // `observer` = "next"; `payload` = "foo"
  console.log(`Routed { ${payload} } to { ${observer} } callback in main`);
});
In Main Process
/** In Main Process */
import { createProxy } from "rx-ipc";
import { ipcMain as ipc } from "electron";

const channel = "some-identifier"; // must match the channel of renderer
createProxy({ channel, ipc, uuid }).subscribe((payload) => {
  // Will receive "payload" (from the report above)
  // `payload` = "foo"
  console.log(`Message From Renderer: ${message}`);
});

Note: You could swap the MainProcess and RendererProcess code snippets above, and it would still work

TODO

  1. Upgrade to RxJS v6. At the moment, I'm consuming this in an app that requires RxJS v5.

Keywords