<commit_before>var fs = require('fs');
var path = require('path');
var chalk = require('chalk');
var logMsg = require('../utils').logMsg;
var genUID = require('../utils').genUID;
var ConnectionList = require('./ConnectionList');
var Client = require('./Client');

module.exports = function initDevtool(wsServer, httpServer, options){
  var clients = new ConnectionList(wsServer);
  // var inspectors = new ConnectionList(wsServer);
  var onClientConnectMode = null;
  var lastNum = 0;

  wsServer.addClientApi(path.join(__dirname, 'ws-client-api.js'));

  wsServer.on('connect', function(socket){
    //
    // client
    //
    socket.on('devtool:client connect', function(data, connectCallback){
      data = data || {};

      var clientId = data.clientId || genUID();
      var client = clients.get('id', clientId);

      if (!client)
      {
        client = new Client(clients, clientId, this, data);
        client.num = lastNum++;
      }
      else
      {
        client.update(data);
        client.setOnline(this);
      }

      this
        .on('devtool:client info', function(data){
          client.update(data);
          clients.notifyUpdates();
        })
        .on('devtool:session data', function(data){
          socket.to(client.room).emit('devtool:session data', data);
        })
        .on('disconnect', function(){
          client.setOffline();
        });

      // connected and inited
      connectCallback({
        clientId: clientId,
        inspectors: client.inspectors.length,
        num: client.num
      });

      if (typeof onClientConnectMode == 'function')
        onClientConnectMode(client);
    });

    //
    // inspector
    //
    socket.on('devtool:inspector connect', function(connectCallback){
      this.on('devtool:pick client', function(pickCallback){
        function startIdentify(client){
          client.emitIfPossible('devtool:identify', client.num, function(){
            pickCallback(client.id);
            stopIdentify();
          });
        }
        function stopIdentify(){
          onClientConnectMode = null;<commit_msg>server: proxy all parameters in session data request<commit_after>var fs = require('fs');
var path = require('path');
var chalk = require('chalk');
var logMsg = require('../utils').logMsg;
var genUID = require('../utils').genUID;
var ConnectionList = require('./ConnectionList');
var Client = require('./Client');

module.exports = function initDevtool(wsServer, httpServer, options){
  var clients = new ConnectionList(wsServer);
  // var inspectors = new ConnectionList(wsServer);
  var onClientConnectMode = null;
  var lastNum = 0;

  wsServer.addClientApi(path.join(__dirname, 'ws-client-api.js'));

  wsServer.on('connect', function(socket){
    //
    // client
    //
    socket.on('devtool:client connect', function(data, connectCallback){
      data = data || {};

      var clientId = data.clientId || genUID();
      var client = clients.get('id', clientId);

      if (!client)
      {
        client = new Client(clients, clientId, this, data);
        client.num = lastNum++;
      }
      else
      {
        client.update(data);
        client.setOnline(this);
      }

      this
        .on('devtool:client info', function(data){
          client.update(data);
          clients.notifyUpdates();
        })
        .on('devtool:session data', function(){
          var channel = socket.to(client.room);
          channel.emit.apply(channel, ['devtool:session data'].concat(Array.prototype.slice.call(arguments)));
        })
        .on('disconnect', function(){
          client.setOffline();
        });

      // connected and inited
      connectCallback({
        clientId: clientId,
        inspectors: client.inspectors.length,
        num: client.num
      });

      if (typeof onClientConnectMode == 'function')
        onClientConnectMode(client);
    });

    //
    // inspector
    //
    socket.on('devtool:inspector connect', function(connectCallback){
      this.on('devtool:pick client', function(pickCallback){
        function startIdentify(client){
          client.emitIfPossible('devtool:identify', client.num, function(){
            pickCallback(client.id);
            stopIdentify();
          });
        }
        function stopIdentify(){
          onClientConnectMode = null;
{'fraction_non_alphanumeric': 0.1424277456647399, 'fraction_numerical': 0.00046242774566473987, 'mean_word_length': 2.5546425636811834, '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': '1990997', 'n_tokens_mistral': 1221, 'n_tokens_neox': 1191, 'n_words': 249}