<commit_before>import User from "./User";

class UserWorld{
  constructor(){
    this.users = {};
  }

  onWebsocketMessage(key, msg){
    if(key === "id"){
      this.users[msg.id] = new User(msg.name, msg.id, msg.wsConnection);
      let peers = [];
      for(let peer in this.users){
        if(this.users[peer]){
          let localPeer = this.users[peer];
          peers.push({id:localPeer.id, name:localPeer.name});
        }
      }
      msg.wsConnection.id = msg.id;
      msg.wsConnection.send(JSON.stringify({
        type:"peers",
        peers: peers
      }));
      this.brodcastToUsers({
        type:"join",
        user:{id:msg.id, name:msg.name}
      }, [this.users[msg.id]]);
    } else if(key === "disconnect"){
      this.userDied(this.users[msg.id]);
    } else if(key === "offer"){
      this.propogateRequestToUser(JSON.stringify({type: msg.type, to:msg.to,
         from:msg.from, offer:msg.offer}), msg.to, msg.from);
    } else if(key === "answer"){
      this.propogateRequestToUser(JSON.stringify({type: msg.type, to:msg.to,
         from:msg.from, answer:msg.answer}), msg.to, msg.from);<commit_msg>Added jsDocs to UserWorld.js<commit_after>import User from "./User";

/** Class representing the users who are currently playing*/
class UserWorld{
  /**
  * Creates list to represent users
  * @constructor
  */
  constructor(){
    this.users = {};
  }

  /**
  * runs task based on key provided
  * @param {String} key the task to be runs
  * @param {String} msg the new user data
  */
  onWebsocketMessage(key, msg){
    if(key === "id"){
      this.users[msg.id] = new User(msg.name, msg.id, msg.wsConnection);
      let peers = [];
      for(let peer in this.users){
        if(this.users[peer]){
          let localPeer = this.users[peer];
          peers.push({id:localPeer.id, name:localPeer.name});
        }
      }
      msg.wsConnection.id = msg.id;
      msg.wsConnection.send(JSON.stringify({
        type:"peers",
        peers: peers
      }));
      this.brodcastToUsers({
        type:"join",
        user:{id:msg.id, name:msg.name}
      }, [this.users[msg.id]]);
    } else if(key === "disconnect"){
      this.userDied(this.users[msg.id]);
    } else if(key === "offer"){
      this.propogateRequestToUser(JSON.stringify({type: msg.type, to:msg.to,
         from:msg.from, offer:msg.offer}), msg.to, msg.from);
    } else if(key === "answer"){
      this.propogateRequestToUser(JSON.stringify({type: msg.type, to:msg.to,
         from:msg.from, answer:msg.answer}), msg.to, msg.from);
{'fraction_non_alphanumeric': 0.17106819077650767, 'fraction_numerical': 0.0, 'mean_word_length': 2.6361031518624642, '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': '4583487', 'n_tokens_mistral': 857, 'n_tokens_neox': 850, 'n_words': 165}