Turns a duplex streams into an event emitter.
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
tests
.gitignore
.travis.yml
README.md
index.js
package.json
parser.js
read_emitter.js
write_emitter.js

README.md

duplex-emitter

Build Status

browser support

Turns a duplex stream into an event emitter.

For instance, when you connect a TCP server and a TCP client using this, when the client emits, the event gets propagated to the server and vice-versa.

Create

var s = net.connect(...);

var duplexEmitter = require('duplex-emitter');
var emitter = duplexEmitter(s);

Emit

You can emit events. They will be serialized (to JSON) and piped to the stream.

emitter.emit('event1', arg1, arg2); // Send event to the other side

Receive

You can listen for events from the peer:

// Got event from the peer
emitter.on('event2', function(arg1, arg2), {
  //...
})