<commit_before>const WebSocket = require('ws');
const express = require('express');
const SocketServer = require('ws').Server;
const uuidV1 = require('node-uuid');
const randomPrompt = require('./random-prompt.js');
let listOfUsers = []; // A list of all the users

// Set the port to 3001
const PORT = 3001;

const sentence = randomPrompt();

// Create a new express server
const server = express()
   // Make the express server serve static assets (html, javascript, css) from the /public folder
  .use(express.static('public'))
  .listen(PORT, '0.0.0.0', 'localhost', () => console.log(`Listening on ${ PORT }`));

// Create the WebSockets server
const wss = new SocketServer({ server });

function generateUserName() {
  let first = ['Gli', 'Shla', 'Gla', 'Blo', 'La', 'Flo', 'Ju', 'Plu'];
  let last = ['nkus', 'mbus', 'rbonzo', 'mbo', 'nkey', 'ngus', 'ster'];
  let firstRandom = Math.floor(Math.random() * (7));
  let lastRandom = Math.floor(Math.random() * (6));
  return (first[firstRandom] + last[lastRandom]);
}

wss.broadcast = function broadcast(data) {
  wss.clients.forEach((client) => {
    if (client.readyState === WebSocket.OPEN) {
      client.send(data);
    }
  });
};

// let clientName = {
//   name: "Anonymous",
//   type: "clientName"
// }

let clientCount = {
  count: 0,
  type: "clientCount"
}

let topicMessage = {
  topic: sentence,
  type: "incomingTopic"
}
// Set up a callback that will run when a client connects to the server
// When a client connects they are assigned a socket, represented by
// the ws parameter in the callback.
wss.on('connection', (ws) => {
  let clientName = generateUserName();
  listOfUsers.push(clientName);
  let healthCount = wss.clients.size + 2
  clientCount.count = wss.clients.size;
  //wss.broadcast(JSON.stringify(clientName));
  wss.broadcast(JSON.stringify(clientCount));
  wss.broadcast(JSON.stringify(topicMessage));

  ws.on('message', (data) => {
    let post = JSON.parse(data);
    let id = uuidV1();

    switch(post.type) {

      case 'postMessage':
        let outputPost = {
          type: 'incomingMessage',
          content: {
            id: id,
            post: post.content,
            health: healthCount,
            maxHealth: healthCount,
            name: clientName,<commit_msg>Adds unique username display for each connection<commit_after>const WebSocket = require('ws');
const express = require('express');
const SocketServer = require('ws').Server;
const uuidV1 = require('node-uuid');
const randomPrompt = require('./random-prompt.js');
let listOfUsers = []; // A list of all the users

// Set the port to 3001
const PORT = 3001;

const sentence = randomPrompt();

// Create a new express server
const server = express()
   // Make the express server serve static assets (html, javascript, css) from the /public folder
  .use(express.static('public'))
  .listen(PORT, '0.0.0.0', 'localhost', () => console.log(`Listening on ${ PORT }`));

// Create the WebSockets server
const wss = new SocketServer({ server });

function generateUserName() {
  let first = ['Gli', 'Shla', 'Gla', 'Blo', 'La', 'Flo', 'Ju', 'Plu'];
  let last = ['nkus', 'mbus', 'rbonzo', 'mbo', 'nkey', 'ngus', 'ster'];
  let firstRandom = Math.floor(Math.random() * (7));
  let lastRandom = Math.floor(Math.random() * (6));
  return (first[firstRandom] + last[lastRandom]);
}

wss.broadcast = function broadcast(data) {
  wss.clients.forEach((client) => {
    if (client.readyState === WebSocket.OPEN) {
      client.send(data);
    }
  });
};


let clientCount = {
  count: 0,
  type: "clientCount"
}

let topicMessage = {
  topic: sentence,
  type: "incomingTopic"
}
// Set up a callback that will run when a client connects to the server
// When a client connects they are assigned a socket, represented by
// the ws parameter in the callback.
wss.on('connection', (ws) => {
  let clientName = generateUserName();
  listOfUsers.push(clientName);
  let healthCount = wss.clients.size + 2
  clientCount.count = wss.clients.size;
  
  //wss.broadcast(JSON.stringify(clientName));
  wss.broadcast(JSON.stringify(clientCount));
  wss.broadcast(JSON.stringify(topicMessage));

  ws.on('message', (data) => {
    let post = JSON.parse(data);
    let id = uuidV1();

    switch(post.type) {
      case 'incomingUser':
        let outputUser = {
          type: 'outgoingUser',
          content: {
            userName: clientName,
          }
        }
        wss.broadcast(JSON.stringify(outputUser));
        break;
      case 'postMessage':
        let outputPost = {
          type: 'incomingMessage',
          content: {
            id: id,
            post: post.content,
            health: healthCount,
            maxHealth: healthCount,
            name: clientName,
{'fraction_non_alphanumeric': 0.15279241306638566, 'fraction_numerical': 0.007586933614330875, 'mean_word_length': 3.2375, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '5794107', 'n_tokens_mistral': 1523, 'n_tokens_neox': 1485, 'n_words': 414}