@wranggle/rpc-ipc-transport

WranggleRpc transport for Ipc

Usage no npm install needed!

<script type="module">
  import wranggleRpcIpcTransport from 'https://cdn.skypack.dev/@wranggle/rpc-ipc-transport';
</script>

README

IpcTransport

A WranggleRpc transport using the Node IPC communication channel. Node sets this up automatically between parent and child processes when child_process.fork() is used.

Setup

  1. Install the packages:
yarn add @wranggle/rpc
# or
yarn add @wranggle/rpc-core @wranggle/rpc-ipc-transport 
# or
npm i @wranggle/rpc
# or 
npm i @wranggle/rpc-core @wranggle/rpc-ipc-transport 
  1. Import/require WranggleRpc and IpcTransport in your code:
const { WranggleRpc, IpcTransport } = require('@wranggle/rpc');

or

import { WranggleRpc, IpcTransport } from '@wranggle/rpc';

or

const { WranggleRpc } = require('@wranggle/rpc-core');
const { IpcTransport } = require('@wranggle/rpc-rpc-ipc-transport');

or

import { WranggleRpc, IpcTransport } from '@wranggle/rpc-core';
import { IpcTransport, IpcTransport } from '@wranggle/rpc-rpc-ipc-transport';

Example / using

Example / use

In the parent Node program:

const { fork } = require('child_process');
const { WranggleRpc, IpcTransport } = require('@wranggle/rpc');

const child = fork(pathToSomeChildScript, [ ], {
    stdio: [ 'pipe', 'pipe', 'pipe', 'ipc' ],
  });

const rpc = new WranggleRpc({
  transport: new IpcTransport({ 
    ipc: child,
  }),
  channel: 'some-channel'
});

const remote = rpc.remoteInterface();


// Can now add method handlers that the child can call with rpc.addRequestHandlerDelegate / rpc.addRequestHandler 
// Can call method handlers defined the child process with `remote`   

In the child (pathToSomeChildScript) program:

const { WranggleRpc, IpcTransport } = require('@wranggle/rpc');


const rpc = new WranggleRpc({
  transport: new IpcTransport({ 
    ipc: process,
  }),
  channel: 'some-channel'
});

const remote = rpc.remoteInterface();

// Can now add method handlers that the parent can call with rpc.addRequestHandlerDelegate / rpc.addRequestHandler 
// Can call method handlers defined on the parent process with `remote`