remote-event-emitter
Deliver Node's EventEmitter events over Unix sockets or TCP connections 🚀
About
This module allows forwarding events (including JSON-serialisable arguments to the events) to another process, with the receiving end behaving as if the events were emitted locally. You can use this for IPC communications where one-directional messaging is needed (ie. one process sends events and another process receives them).
The events are delivered as follows:
- The consumer (process which wants to receive events) creates a Unix socket or TCP connection and start listening for connections
- The provider (process which wants to send events) connects to this socket and starts emitting events locally just like any other
EventEmitter
instance - viaemitter.emit('event', ...args)
- The consumer emits a
connection
event every time someone connects to the socket. This event will receive a single argument, asource
, which basically mirrors the event emitter from the provider side (it will emit the events the provider emits in the other process)
Installation
Install this package on both ends and use either the Consumer
or Producer
class.
npm install --save remote-event-emitter
Usage
Consumer
const consumer = // Bind to a socketawait consumer// Or, bind to a TCP port 12345await consumer // Handle for incoming connectionsconsumer // When you no longer want to accept new connections from providers// This will close the socket.await consumer
Provider
// The socket must exist, otherwise an error will be thrownconst provider = address: '/tmp/my-fancy.sock' provider // Always close the connection when you are done sending eventsprovider
Reference implementations
See mocha-reporter-remote for a reference implementation on the provider and atom-ide-mocha for the consumer side.
License
See the LICENSE file for information.