Client code:
var app = {
data: {
user: null
}
};
var client = {
connect: function () {
client.data.socket.on('connectCallback', function (obj) {
if (obj.userFound) {
app.data.user = obj.user;
return app.data.user;
}
});
/**
Other callbacks
**/
};
};
app.data.user
is always null
, I also tried a second function to change the variable. The obj returned by the server isn't null
, I already checked that.
using code like var foo = client.data.socket.on
didn't work because than foo is a socket.io object. Also passing a custom callback function didn't work , because i can't pass it to the socket.io callback.
I don't wan't to do an ajax call, as some people think.