Configure connection with duplex-emitter

Usage no npm install needed!

<script type="module">
  import cioDuplexEmitter from 'https://cdn.skypack.dev/@cio/duplex-emitter';



Build Status Dependency Status npm version

Use two way event system for client/server communication.

Uses module duplex-emitter.


npm install @cio/duplex-emitter --save


Uses duplex-emitter to setup a two-way remote event communication.

Enable it with the duplexEmitter:true options property and it will produce a socket.duplexEmitter sub-property and emit a 'duplex-emitter' event.

// get the `cio` module's builder function and build one
var buildCio = require('cio')
  , cio = buildCio();

// provide the module name to load it for the specific type of socket

// OR: provide the function
var fn = require('@cio/duplex-emitter');

// tell this listener to do its thing for this client
var options = { duplexEmitter:true }
  , client = cio.client(options)
  , server = cio.server(options);

// the result is sockets connect (client and server client) it will do:
//   socket.duplexEmitter = DuplexEmitter(socket);
//   socket.emit('duplex-emitter', socket.duplexEmitter, socket);
// so, you can do this for both `client` and `server`
client.on('duplex-emitter', function(emitter, socket) {
  emitter.on('some-event', someListener);
  // and more...
// NOTE: it emits 'emitter' in `nextTick()` so you have a chance to add
// a listener for that event before it is emitted.

// if you specify key/cert, and optionally `ca`, values
// then it'll use `tls.connect()` instead for secure communication.

MIT License