@cio/duplex-emitter
Use two way event system for client/server communication.
Uses module duplex-emitter.
Install
npm install @cio/duplex-emitter --save
Usage
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 onevar buildCio = cio = ; // provide the module name to load it for the specific type of socketcio;cio; // OR: provide the functionvar fn = ;cio;cio; // tell this listener to do its thing for this clientvar options = duplexEmitter:true client = cio server = cio; // 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;// 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.