<commit_before>
"use strict";

var User = require('./User');
var Channel = require('./Channel');

var EventEmitter = require('events').EventEmitter;

var MumbleWrapper = function(connection) {
    this._users = {}; //Collect high-level information about users
    this._channels = {}; //Collect high-level information about channels
    this.sessions = {}; //Sessions to user map

    //TODO: We are storing the users twice to avoid some looping. Is this the
    //best approach?
    this.ready = false;
    this.connection = connection;
    this.rootChannel = undefined;
    this.user = undefined;
    this._gotServerSync;
    this._gotInitialPermissionQuery;
    this._gotInitialPing;

    // Generate list of free whisper target IDs.
    this.freeTargets = [];
    for( var i = 1; i <= 30; i++ ) {
        this.freeTargets.push( i );
    }

    /*
     * Forward all events from the connection
     */
    this.on('newListener', function (event, listener) {
        connection.on(event, listener);
    });

    connection.once('ping', this._initialPing.bind( this ) );
    connection.on('permissionQuery', this._permissionQuery.bind( this ) );
    connection.on('channelRemove', this._channelRemove.bind( this ));
    connection.on('userRemove', this._userRemove.bind( this ) );
    connection.on('serverSync', this._serverSync.bind( this ) );
    connection.on('userState', this._userState.bind( this ) );
    connection.on('channelState', this._channelState.bind( this ) );
    connection.on('textMessage', this._textMessage.bind( this ) );
};

MumbleWrapper.prototype = Object.create( EventEmitter.prototype );

MumbleWrapper.prototype._checkReady = function() {
    if(this._gotInitialPermissionQuery && this._gotServerSync && this._gotInitialPing && !this.ready) {
        this.ready = true;
        this.emit('ready');
    }
};

MumbleWrapper.prototype._initialPing = function(data) {
    this._gotInitialPing = true;
    this._checkReady();
}

MumbleWrapper.prototype._permissionQuery = function(data) {
    //TODO: Do something with the data
    this._gotInitialPermissionQuery = true;
    this._checkReady();
};

MumbleWrapper.prototype._serverSync = function(data) {
    this.session = data.session;
    this.maxBandwidth = data.maxBandwidth;
    this.user = this.sessions[this.session];
    this._gotServerSync = true;
    this._checkReady();
    //Is really everything ready when we receive this?
    //TODO: Is this a good idea?
};
<commit_msg>Do not wait for permission query to be ready.<commit_after>
"use strict";

var User = require('./User');
var Channel = require('./Channel');

var EventEmitter = require('events').EventEmitter;

var MumbleWrapper = function(connection) {
    this._users = {}; //Collect high-level information about users
    this._channels = {}; //Collect high-level information about channels
    this.sessions = {}; //Sessions to user map

    //TODO: We are storing the users twice to avoid some looping. Is this the
    //best approach?
    this.ready = false;
    this.connection = connection;
    this.rootChannel = undefined;
    this.user = undefined;
    this._gotServerSync;
    this._gotInitialPing;

    // Generate list of free whisper target IDs.
    this.freeTargets = [];
    for( var i = 1; i <= 30; i++ ) {
        this.freeTargets.push( i );
    }

    /*
     * Forward all events from the connection
     */
    this.on('newListener', function (event, listener) {
        connection.on(event, listener);
    });

    connection.once('ping', this._initialPing.bind( this ) );
    connection.on('channelRemove', this._channelRemove.bind( this ));
    connection.on('userRemove', this._userRemove.bind( this ) );
    connection.on('serverSync', this._serverSync.bind( this ) );
    connection.on('userState', this._userState.bind( this ) );
    connection.on('channelState', this._channelState.bind( this ) );
    connection.on('textMessage', this._textMessage.bind( this ) );
};

MumbleWrapper.prototype = Object.create( EventEmitter.prototype );

MumbleWrapper.prototype._checkReady = function() {
    if(this._gotServerSync && this._gotInitialPing && !this.ready) {
        this.ready = true;
        this.emit('ready');
    }
};

MumbleWrapper.prototype._initialPing = function(data) {
    this._gotInitialPing = true;
    this._checkReady();
},

MumbleWrapper.prototype._serverSync = function(data) {
    this.session = data.session;
    this.maxBandwidth = data.maxBandwidth;
    this.user = this.sessions[this.session];
    this._gotServerSync = true;
    this._checkReady();
    //Is really everything ready when we receive this?
    //TODO: Is this a good idea?
};

{'fraction_non_alphanumeric': 0.13333333333333333, 'fraction_numerical': 0.0012944983818770227, 'mean_word_length': 3.377714825306893, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5132707', 'n_tokens_mistral': 1347, 'n_tokens_neox': 1332, 'n_words': 322}