<commit_before>// Create a socket plugin
const socketIO = require('socket.io');
const extend = require('extend');

const listeners = {};

module.exports = {
  name: 'socket',
  options: {},
  router: (path, middle) => {
    listeners[path] = listeners[path] || [];
    listeners[path].push(middle);
  },
  launch: ctx => {
    ctx.io = socketIO(ctx.server);
    ctx.io.on('connect', socket => {
      for (name in listeners) {
        listeners[name].forEach(cb => {
          socket.on(name, data => {
            cb(extend({}, ctx, { path: name, socket: socket, data: data }));
          });
        });
      }
    });
  }
};<commit_msg>the callback function of router.socket('connect', callback) will be called when a new socket connection connected. by this, you kan listen a connect event<commit_after>// Create a socket plugin
const socketIO = require('socket.io');
const extend = require('extend');

const listeners = {};

module.exports = {
  name: 'socket',
  options: {},
  router: (path, middle) => {
    listeners[path] = listeners[path] || [];
    listeners[path].push(middle);
  },
  launch: ctx => {
    ctx.io = socketIO(ctx.server);
    ctx.io.on('connect', socket => {
      for (name in listeners) {
        if (name !== 'connect') {
          listeners[name].forEach(cb => {
            socket.on(name, data => {
              cb(extend({}, ctx, { path: name, socket: socket, data: data }));
            });
          });
        }
      }
      if (listeners['connect']) {
        listeners['connect'].forEach(cb => {
          cb(extend({}, ctx, { socket: socket }));
        })
      }
    });
  }
};
{'fraction_non_alphanumeric': 0.17980295566502463, 'fraction_numerical': 0.0, 'mean_word_length': 2.4722222222222223, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, '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': '4637816', 'n_tokens_mistral': 479, 'n_tokens_neox': 488, 'n_words': 120}