My code structure is designed as follows:
//Route Handler that triggers when a user 'creates a session'
app.post('/route', async (req, res) => {
let var1 = [];
let var2 = [];
io.on('connection', (socket) => {
//Utilizing var1 and var2 here
socket.on('event', () => {
// Utilizing var1 and var2 here
});
});
});
While my code operates effectively during one ongoing session, introducing a second user accessing the route alters the variables for active sessions leading to undesirable outcomes.
Instead of instantiating the variables upon each connection, I aim to have them set up with every occurrence of the 'sessionMade' event. Placing the variables within a socket method restricts their use for other socket.on methods.
I am seeking a solution where all sockets and global variables are contained within one session. Any assistance provided would be greatly valued. Thank you.