this is my websocket:
const server = require("http").createServer();
const options = {
  cors: true,
};

const fs = require('fs');

function userInfo(username, socketid, position = 1) {
  this.UserId = username;
  this.SocketId = socketid;
  this.Position = position;
  this.active = false;
  this.joinTime = new Date();
}

var activeUsers = [];

function saveUsersToFile(users) {
  const existingUsers = JSON.parse(fs.readFileSync("users.json", "utf-8"));

  // Combine the existing users with the new users
  const allUsers = existingUsers.concat(users);

  // Write the combined list of users back to the file
  fs.writeFileSync("users.json", JSON.stringify(allUsers));
}

let totalUsers = [];
try {
  const data = fs.readFileSync("users.json", "utf8");
  totalUsers = JSON.parse(data);
} catch (err) {
  console.error(err);
}

// console.log('total users' + totalUsers.length);

const io = require("socket.io")(server, options);

io.on("connection", function (socket) {
  console.log("Client has connected!");

  socket.on("new user", function (data) {
    socket.userId = data;
    
    activeUsers.push(new userInfo(data, socket.id, 0, false));
    saveUsersToFile(activeUsers.slice(-1));
    // io.emit("new user", [...activeUsers]);
    var queuePosition = activeUsers
      .map((object) =&gt; object.SocketId)
      .indexOf(socket.id) + 1;
    // socket.broadcast.emit("new user", data, queuePosition)
    socket.emit("queue position", queuePosition);
    
    if (queuePosition != -1) {
        activeUsers.map((user) =&gt; {
            if (user.SocketId === socket.id) {
                user.Position = queuePosition;
            }
            return user;
        });
        // ...
    }
    
    
    socket.broadcast.emit(
      "user queue",
      queuePosition,
      socket.userId,
      socket.id
    );
    socket.broadcast.emit("user list", activeUsers);

    console.log("new user " + data + "  postion " + queuePosition + '  id' + socket.id);
  });


  socket.on("position check", () =&gt; {
    var queuePosition = activeUsers
      .map((object) =&gt; object.SocketId)
      //.Position
      .indexOf(socket.id) + 1;
    console.log("checking pos  " + socket.UserId + "  " + queuePosition);
    console.log(activeUsers);
    if (queuePosition != -1) {
      
      socket.emit("queue position", queuePosition);
      socket.broadcast.emit(
        "user queue",
        queuePosition,
        socket.userId,
        socket.id
      );

    }
  });

  socket.on("get user list", () =&gt; {
    socket.emit("user list", activeUsers);
  });
  
  socket.on("get total users", () =&gt; {
    socket.emit("totalUsers", totalUsers);
  });
  
  socket.on('updatedUserList', (data) =&gt; {
    data.forEach((user, index) =&gt; {
        user.Position = index + 1;
    });
    activeUsers = data
    console.log(activeUsers);
    io.emit('user list', activeUsers);
  });
  

  socket.on("remove user", (data) =&gt; {
      const index = activeUsers.findIndex((user) =&gt; user.SocketId === data);
      activeUsers.splice(index, 1);
      activeUsers.forEach((user, index) =&gt; {
        // Update the position of each user based on their current index in the list
        if (user.Position !== 0) {
          user.Position = index + 1;
        }
      });
      
      io.emit("user list", activeUsers);
      console.log("user disconnected " + data);
      console.log(activeUsers);
  });
  
  socket.on("active user", function (socketId) {
    const user = activeUsers.find(u =&gt; u.SocketId === socketId);
    if (user) {
      user.Position = 0;
      io.emit("user list", activeUsers);
      console.log(`User ${user.UserId} is now active.`);
    }
  });
   
  socket.on("disconnect", () =&gt; {
    var index = activeUsers.map((object) =&gt; object.SocketId).indexOf(socket.id);
    if (index != -1) {
      activeUsers.splice(
        activeUsers.map((object) =&gt; object.SocketId).indexOf(socket.id),
        1
      );
    }
    console.log("user disconnected " + socket.userId);

    socket.broadcast.emit("user disconnected", socket.id);

    socket.broadcast.emit("user list", activeUsers);
  });
  
});

console.log("Server started.");
server.listen(3000);

I'm currently having the issue that when the user's phone simply goes to sleep or they leave the browser they get disconnected and I would like disconnection to only happen on tab close or hard refresh. How could I approach this?