In socket.io server a property can be added to the socket.data
object. How do I access such a property at the client side (socket.io-client
)?.
// Server code
io.on('connection', socket => {
socket.data.customId = getCustomId();
io.emit('connected', {success: 'true'})
})
// Client code
socket = io('http://localhost:5000');
socket.on('connected', data => {
console.log('SOCKET_DATA:', socket)
console.log('SOCKET_CUSTOM-ID:', socket.data.customId); // produces 'undefined'
})
I would like to access the customId
I added at the server from the client side. The data
attribute don't even exist on the socket
object displayed at the console at the client side.