I have a simple module like this:
module.exports = function (io, c) {
c.on('connection', function (socket) {
var customVariable = 0;
socket.on('test', function (data) {
customVariable = 5;
});
});
When i set customVariable to for example 5 it becomes 5 for every connected user.
I want to store some variables for each individual user. How can i achieve this? I use Node.js 6 with socket.io lib (latest). Is it wise to use this method OR should I make an array/collection and assign my variables to my socket id like;
var users = [
socketId: {
//my data goes here...
}
];
select user_id from sessions where socket_id = ?everytime a request made to my socket.io server instead of just sayingarr[socketId].user_id. Am I thinking still wrong? Should I even query against db each time?