1.0.30 • Published 10 months ago

ipc-evo v1.0.30

Weekly downloads
-
License
ISC
Repository
-
Last release
10 months ago

IPC Evolution

Node's module for local Inter Process Communication with full support for Linux, Mac and Windows. Simple use. Buffer enqueued and sync stream.

Install

npm i ipc-evo

Usage

const Ipc = require('ipc-evo');
const ipc = new Ipc('myAppName');

ipc.event('otherAppName').on('anyEvent', data => {
  // ... listen event from `otherAppName`
});

// ... send event to specific app
ipc.event('otherAppName').send('anyoneEvent', { hello: 'world' });

API

Use Events

const ipc = new Ipc('app1');

// send ways :

// ... send event to `app2`
ipc.event('app2').send('anyoneEvent', data);

// ... send event to `app2`
ipc.send('app2', 'anyoneEvent', data);

// ... send event to all connected apps
ipc.broadcast('anyoneEvent', data);

// listen ways :

ipc.event('app2').on('anyEvent', data => {
  // ... listen event from `app2`
});

ipc.on('app2', (event, data) => {
  // ... listen any event from `app2`
});

ipc.on([ 'app2', 'app3' ], (event, data) => {
  // ... listen any event from `app2` and `app3`
});

ipc.on('event', (appId, event, data) => {
  // ... listen all events from all apps
});

Use Services

// `app1` :
const ipc = new Ipc('app1');

// `app1` set services :
ipc.setServices({
  getItem(tableName, itemId){
    this.appId; // appId who calls
    return getItemFromDb(tableName, itemId);
  },
  saveItem(tableName, newItem){ // function many arguments dynamic
    return saveItemFromDb(newItem);
  }
});

/**************/

// `app2` :
const ipc = new Ipc('app2');

// return services avaiables and params names
const servicesTypes = await ipc.appServices('app1');

// `app2` accessing `app1` services
const item = await ipc.app('app1').getItem('user', '123123');
console.log(item); // prints result from other application

const anyValue = {
  // The object will remain almost intact in another application
  // Functions will be removed
  // Circular references are maintained
};
const result = await ipc.app('app1').saveItem('product', anyValue);

// ... broadcast function in many apps
const results = await ipc.app().functionInManyApps();
// Array with the results of all the applications that had this function
// In case of no function or error the default result is null

Events

ipc.apps(); // return appIds connecteds
ipc.on('start', ()    => { /**/ }); // When server starts
ipc.on('ready', appId => { /**/ }); // When ready connection from other application
ipc.on('close', appId => { /**/ }); // When close connection from other application
ipc.on('error', error => { /**/ }); // When any error in communication
ipc.on('event', (appId, event, data) => { /**/ }); // Events from all applications
ipc.on('reply', (appId, result, error) => { /**/ }); // Response from unreachable promises

Configs

const defaultOptionalConfigs = {
  timeoutService: Infinity,    // Timeout in milliseconds to any service call throws error
  rootPath:       '/tmp/app.', // Root path to socket IPC
  retryTime:      1000,        // Time in milliseconds to retry connection other application
  retryLimit:     Infinity     // Number of max tries to connection other application
};
const ipc = new Ipc('myAppName', defaultOptionalConfigs);

License

MIT License © Fellipe Paiva

1.0.29

10 months ago

1.0.28

10 months ago

1.0.30

10 months ago

1.0.27

12 months ago

1.0.26

1 year ago

1.0.24

1 year ago

1.0.23

1 year ago

1.0.22

1 year ago

1.0.21

1 year ago

1.0.20

1 year ago

1.0.19

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago