1.0.30 • Published 2 years ago

ipc-evo v1.0.30

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years 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

2 years ago

1.0.28

2 years ago

1.0.30

2 years ago

1.0.27

2 years ago

1.0.26

2 years ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago