<commit_before>var EventEmitter = require('eventemitter2').EventEmitter2,
    util = require('util'),
    Discovery = require('./Discovery'),
    axon = require('axon'),
    Subscriber = require('./Subscriber'),
    Requester = require('./Requester');


var Sockend = function(io, advertisement, discoveryOptions) {
    EventEmitter.call(this, {
        wildcard: true, // should the event emitter use wildcards.
        delimiter: '::', // the delimiter used to segment namespaces, defaults to `.`.
        newListener: false, // if you want to emit the newListener event set to true.
        maxListeners: 2000 // the max number of listeners that can be assigned to an event, defaults to 10.
    });

    advertisement = advertisement || {};
    advertisement.axon_type = 'sockend';
    this.advertisement = advertisement;

    var that = this,
        d = Discovery(advertisement, discoveryOptions);

    var namespaces = {};

    d.on('added', function(obj) {
        if (obj.advertisement.axon_type != 'rep') return;
        if (obj.advertisement.key != advertisement.key) return;

        var namespace = obj.advertisement.namespace,
            normalizedNamespace =  namespace || '';

        if (namespaces['/' + normalizedNamespace]) return;

        namespaces['/' + normalizedNamespace] = true;
        obj.namespace = namespace;

        var requester = new Requester({
            name: 'sockendReq',
            namespace: namespace,
            key: that.advertisement.key
        }, discoveryOptions);
        obj.requester = requester;

        obj.requesterSocketHandler = function(socket) {
            obj.advertisement.respondsTo.forEach(function(topic) {
                socket.on(topic, function(data, cb) {
                    if (arguments.length == 1 && typeof data == 'function') {
                        cb = data;
                        data = null;
                    }

                    var req = {
                        type: topic,
                        data: data
                    };

                    requester.send(req, cb);
                });
            });
        };

        requester.on('ready', function() {
            var server = io.sockets;
            if (namespace) server = io.of('/' + namespace);
            server.on('connection', obj.requesterSocketHandler);
        });
    });

    d.on('added', function(obj) {
        if (obj.advertisement.axon_type != 'pub-emitter') return;<commit_msg>Make data in callbacks empty object in sockend for easier use, instead of null.<commit_after>var EventEmitter = require('eventemitter2').EventEmitter2,
    util = require('util'),
    Discovery = require('./Discovery'),
    axon = require('axon'),
    Subscriber = require('./Subscriber'),
    Requester = require('./Requester');


var Sockend = function(io, advertisement, discoveryOptions) {
    EventEmitter.call(this, {
        wildcard: true, // should the event emitter use wildcards.
        delimiter: '::', // the delimiter used to segment namespaces, defaults to `.`.
        newListener: false, // if you want to emit the newListener event set to true.
        maxListeners: 2000 // the max number of listeners that can be assigned to an event, defaults to 10.
    });

    advertisement = advertisement || {};
    advertisement.axon_type = 'sockend';
    this.advertisement = advertisement;

    var that = this,
        d = Discovery(advertisement, discoveryOptions);

    var namespaces = {};

    d.on('added', function(obj) {
        if (obj.advertisement.axon_type != 'rep') return;
        if (obj.advertisement.key != advertisement.key) return;

        var namespace = obj.advertisement.namespace,
            normalizedNamespace =  namespace || '';

        if (namespaces['/' + normalizedNamespace]) return;

        namespaces['/' + normalizedNamespace] = true;
        obj.namespace = namespace;

        var requester = new Requester({
            name: 'sockendReq',
            namespace: namespace,
            key: that.advertisement.key
        }, discoveryOptions);
        obj.requester = requester;

        obj.requesterSocketHandler = function(socket) {
            obj.advertisement.respondsTo.forEach(function(topic) {
                socket.on(topic, function(data, cb) {
                    if (arguments.length == 1 && typeof data == 'function') {
                        cb = data;
                        data = {};
                    }

                    var req = {
                        type: topic,
                        data: data
                    };

                    requester.send(req, cb);
                });
            });
        };

        requester.on('ready', function() {
            var server = io.sockets;
            if (namespace) server = io.of('/' + namespace);
            server.on('connection', obj.requesterSocketHandler);
        });
    });

    d.on('added', function(obj) {
        if (obj.advertisement.axon_type != 'pub-emitter') return;
{'fraction_non_alphanumeric': 0.11943887775551103, 'fraction_numerical': 0.0036072144288577155, 'mean_word_length': 1.944542772861357, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4575104', 'n_tokens_mistral': 1346, 'n_tokens_neox': 1238, 'n_words': 329}