Socket.IO Transport Close Trouble

Hi there.
I’m having a lot of trouble with socket.io. I am coding this to be able to create a room, join it, and then use socket.io to play a game between the people. This is really just a coding challenge to see if I can code something using socket.io from scratch. The problem is that when one client disconnects, all of the other clients disconnect. Here is the code:

<script>
        
      var code;
      var codes;
      var socket = io();
      var log;
      var variable = false;
      var nick = null;
      var me = {};
      
      socket.on("com", function(type, arg1) {
        switch (type) {
          case "joined": 
            document.getElementById("getKey").innerHTML = ""
          break;
          case "dataSendCodes":
            codes = arg1;
          break;
          case "dataSendLogs":
            log = arg1;
          break;
        }
      });
      
      socket.on('connect', function() {
        console.log("socket connected");
        socket.on("disconnect", function(reason) {
          console.log("disconnected - " + reason);
          console.log(socket.id);
        });
      });
      socket.on('connect_error', function(error) {
        console.log(error);
      });
        
      function fetchcodes() {
        socket.emit("comm","getData");
        console.log("Data fetch request sent");
          if (log != undefined & codes != undefined) {
            return true;
          } else {
            return false;
          }
      }
      
      function createRoom() {
          fetchcodes();
          setTimeout(function() {           
            createcode();
          }, 2500);
      }
      
      
      function createcode() {
        for (code = Math.floor(Math.random() * 99999999) + 1; codes[code] != undefined; code = Math.floor(Math.random() * 99999999) + 1) {
          console.log("NOPE!");
        }
          socket.emit("comm", 'createcode', code);
          document.getElementById("codeBox").innerHTML = "<p class='JoinText'>Code: " + code + "</p>"
          socket.emit("comm", "join", code, nick, true);
          me.nick = nick;
          me.id = socket.id;
          me.room = code;
          me.admin = true;
          console.log(me.room);
        }
      
    </script>

And server side:

// server.js
// where your node app starts

// we've started you off with Express (https://expressjs.com/)
// but feel free to use whatever libraries or frameworks you'd like through `package.json`.
const express = require("express");
const app = express();
const server = require("http").Server(app);
const io = require("socket.io")(server);

// make all the files in 'public' available
// https://expressjs.com/en/starter/static-files.html
app.use(express.static("public"));

// https://expressjs.com/en/starter/basic-routing.html
app.get("/", (request, response) => {
  response.sendFile(__dirname + "/join.html");
});

app.get("/admin", (request, response) => {
  response.sendFile(__dirname + "/twotruthsandalieadmin.html");
});

var Codes = {};

var Log = {};

io.on("connection", function (socket) {
  socket.on("disconnect", function() {
    var check = io.sockets.clients(Log[socket.id].room);
    if (check == 0) {
      delete Codes[Log[socket.id].room];
    }
    delete Log[socket.id];
  });
  socket.on("comm", function(type, arg1, arg2, arg3) {
    console.log("comm");
    switch (type) {
      case "getData":
        console.log("get data");
        io.to(socket.id).emit("com","dataSendCodes",Codes);
        io.to(socket.id).emit("com","dataSendLogs",Log);
        console.log("emitted");
        break;
      case "join":
        socket.join(arg1, function () {
          console.log("joined " + socket.id + "to a room");
          io.to(arg1).emit("com","joined");
        });
        Log[socket.id] = {nick: arg2,id: socket.id,room: arg1,admin: arg3};
      break;
      case "createcode":
        Codes[arg1] = arg1;
      break;
    }
  });
});

function reset() {
  Log = {};
  Codes = {};
}


server.listen(process.env.PORT);

The disconnect reason is transport close, meaning it lost connection but it only happens when another client is disconnected. There isn’t any code that should be closing the connection server side as far as I can see.
Any help is appreciated!