-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
42 lines (25 loc) · 874 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
var util = require('util');
var stream = require('stream');
var crypto = require('crypto');
var PassThrough = stream.PassThrough || require('readable-stream').PassThrough;
var Listener = require('./lib/Listener');
util.inherits(EventTransmitter, PassThrough);
// main constructor
function EventTransmitter(opts) {
var hash;
PassThrough.call(this);
opts = opts || {};
hash = crypto.createHash('sha1', opts.delimeter || 'jambalaya');
hash.setEncoding('hex');
hash.end();
this.delimiter = '<' + hash.read().substr(0, 10) + '>';
this.opts = opts;
}
// prototype methods
EventTransmitter.prototype.transmit = function() {
var args = Array.prototype.slice.call(arguments);
this.push(this.delimiter + JSON.stringify(args) + this.delimiter);
};
// class statics
EventTransmitter.Listener = Listener;
module.exports = exports = EventTransmitter;