Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

remote-event-emitter

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remote-event-emitter

Deliver events remotely over Unix sockets or TCP connections using standard EventEmitter

latest
Source
npmnpm
Version
1.2.0
Version published
Maintainers
2
Created
Source

remote-event-emitter

Build Status Coverage Status Built with GNU Make Required Node.js version

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:

Installation

Install this package on both ends and use either the Consumer or Producer class.

npm install --save remote-event-emitter

Usage

Consumer

import { Consumer } from 'remote-event-emitter'

const consumer = new Consumer()
// Bind to a socket
await consumer.listen({ address: '/tmp/my-fancy.sock' })
// Or, bind to a TCP port 12345
await consumer.listen({ address: 12345 })

// Handle for incoming connections
consumer.on('connection', source => {
  // The events emitted on source will match the events emitted
  // in the provider process
  source.on('hello', string, flag => {
    console.log(string)   // -> "world"
    console.log(flag)   // true
  })

  source.once('close', () => {
    console.log('Client disconnected!')
  })
})

// When you no longer want to accept new connections from providers
// This will close the socket.
await consumer.close()

Provider

import { Provider } from 'remote-event-emitter'

// The socket must exist, otherwise an error will be thrown
const provider = new Provider({ address: '/tmp/my-fancy.sock' })

provider.emit('hello', 'world', true)

// Always close the connection when you are done sending events
provider.end()

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.

Keywords

emitter

FAQs

Package last updated on 12 Feb 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts