Wednesday, 7 June 2017

Undefined of socket object value - socket.io

been with this problem for a day. I'm encountering an undefined value for my socket object when I access it in other socket.on. Here's what I have:

socket.on('new:user', function(data){
        if(online_users.indexOf(data) !== -1) {

        } else {
            socket.fullname = data.fullname;

            // I can get the value here (not undefined)
            console.log(socket.fullname);

            online_users.push(data);

            io.sockets.emit('online_users',online_users);
        }
    });

    // List different of logged in users
    socket.on('load:user',function(data){

        // This is where I encounter the undefined value
        console.log(socket.fullname);

        io.sockets.emit('online_users',online_users);
    });



via Sydney Loteria

No comments:

Post a Comment