<commit_before>

module.exports = function(server, io, log, config) {

    function Client(socket, socketManager) {
        this.id = socket.id;
        this.socket = socket;
        this.reconnected = 0;
    }

    Client.prototype.setCredentials = function(creds) {
        this.credentials = creds;
    };

    Client.prototype.setDeviceInfo = function(deviceInfo) {
        this.deviceInfo = deviceInfo;
    };

    Client.prototype.emit = function(event, payload) {
        this.socket.emit(event, payload);
        //TODO: Handle completion through promise
    };

    Client.prototype.on = function(event, handler) {
        this.socket.on(event, handler);
    };

    Client.prototype.addHandler = function(handlerSpec) {
        this.socket.on(handlerSpec.key, handlerSpec.handler.bind(handlerSpec.scope));
    };

    return Client;
};<commit_msg>Make sure to share client context when handler is called<commit_after>

module.exports = function(server, io, log, config) {

    function Client(socket, socketManager) {
        this.id = socket.id;
        this.socket = socket;
        this.reconnected = 0;
    }

    Client.prototype.setCredentials = function(creds) {
        this.credentials = creds;
    };

    Client.prototype.setDeviceInfo = function(deviceInfo) {
        this.deviceInfo = deviceInfo;
    };

    Client.prototype.emit = function(event, payload) {
        this.socket.emit(event, payload);
        //TODO: Handle completion through promise
    };

    Client.prototype.on = function(event, handler) {
        this.socket.on(event, handler);
    };

    Client.prototype.addHandler = function(handlerSpec) {
        var _this = this;
        this.socket.on(handlerSpec.key, function(event) {

            // We wrap the received event to share our client context with handlers
            handlerSpec.handler.bind(handlerSpec.scope)({
                data:event,
                context: {
                    client: _this
                }
            });

        });
    };

    return Client;
};
{'fraction_non_alphanumeric': 0.11160275319567355, 'fraction_numerical': 0.0009832841691248771, 'mean_word_length': 2.2875605815831985, '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': '599326', 'n_tokens_mistral': 576, 'n_tokens_neox': 554, 'n_words': 117}