<commit_before>import { LWEvents } from '../lib/collections/lwevents/collection';
import { newMutation } from './vulcan-lib';
import Users from '../lib/collections/users/collection';
import { ForwardedWhitelist } from './forwarded_whitelist';
import { Accounts } from 'meteor/accounts-base';
import { Meteor } from 'meteor/meteor';

let dummyUser: DbUser|null = null;
async function getDummyUser(): Promise<DbUser> {
  if (!dummyUser) dummyUser = Users.findOne();
  if (!dummyUser) throw Error("No users in the database, can't get dummy user")
  return dummyUser;
}
getDummyUser();

Meteor.onConnection(async (connection) => {
  let currentUser = await getDummyUser();
  const ip = (connection.httpHeaders && connection.httpHeaders["x-real-ip"]) || connection.clientAddress;
  
  newMutation({
    collection: LWEvents,
    document: {
      name: 'newConnection',
      important: false,
      properties: {
        ip: ip,
        id: connection.id,
      }
    },
    currentUser: currentUser,
    validate: false,
  })
  //eslint-disable-next-line no-console
  console.info("new Meteor connection:", connection)

  connection.onClose(() => {
    //eslint-disable-next-line no-console
    console.info("closed Meteor connection:", connection)
    newMutation({
      collection: LWEvents,
      document: {
        name: 'closeConnection',
        important: false,
        properties: {
          ip: ip,
          id: connection.id,
        }
      },
      currentUser: currentUser,
      validate: false,
    })
  })
})

Accounts.onLogin(async (login) => {
  const document = {
    name: 'login',
    important: false,
    userId: login.user && login.user._id,
    properties: {
      type: login.type,
      id: login.connection && login.connection.id,
      ip: login.connection && ForwardedWhitelist.getClientIP(login.connection),
      userAgent: login.connection && login.connection.httpHeaders && login.connection.httpHeaders['user-agent'],<commit_msg>Reduce gigantic console message for Meteor websocket connect/disconnect<commit_after>import { LWEvents } from '../lib/collections/lwevents/collection';
import { newMutation } from './vulcan-lib';
import Users from '../lib/collections/users/collection';
import { ForwardedWhitelist } from './forwarded_whitelist';
import { Accounts } from 'meteor/accounts-base';
import { Meteor } from 'meteor/meteor';

let dummyUser: DbUser|null = null;
async function getDummyUser(): Promise<DbUser> {
  if (!dummyUser) dummyUser = Users.findOne();
  if (!dummyUser) throw Error("No users in the database, can't get dummy user")
  return dummyUser;
}
getDummyUser();

Meteor.onConnection(async (connection) => {
  let currentUser = await getDummyUser();
  const ip = (connection.httpHeaders && connection.httpHeaders["x-real-ip"]) || connection.clientAddress;
  
  newMutation({
    collection: LWEvents,
    document: {
      name: 'newConnection',
      important: false,
      properties: {
        ip: ip,
        id: connection.id,
      }
    },
    currentUser: currentUser,
    validate: false,
  })
  //eslint-disable-next-line no-console
  console.info(`new Meteor connection from ${connection.clientAddress}`);

  connection.onClose(() => {
    //eslint-disable-next-line no-console
    console.info(`closed Meteor connection from ${connection.clientAddress}`);
    newMutation({
      collection: LWEvents,
      document: {
        name: 'closeConnection',
        important: false,
        properties: {
          ip: ip,
          id: connection.id,
        }
      },
      currentUser: currentUser,
      validate: false,
    })
  })
})

Accounts.onLogin(async (login) => {
  const document = {
    name: 'login',
    important: false,
    userId: login.user && login.user._id,
    properties: {
      type: login.type,
      id: login.connection && login.connection.id,
      ip: login.connection && ForwardedWhitelist.getClientIP(login.connection),
      userAgent: login.connection && login.connection.httpHeaders && login.connection.httpHeaders['user-agent'],
{'fraction_non_alphanumeric': 0.13225806451612904, 'fraction_numerical': 0.0, 'mean_word_length': 3.2656084656084654, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '6710083', 'n_tokens_mistral': 1216, 'n_tokens_neox': 1181, 'n_words': 274}