in node.js and socket.io, many events can be handled by one function:
socket.on( 'async.popular_qtns', rows.bind(socket) );
socket.on( 'async.recent_qtns', rows.bind(socket) );
socket.on( 'async.enum_chn', rows.bind(socket) );
socket.on( 'async.enum_tag', rows.bind(socket) );
function rows() {
var socket = this;
switch( socket.?? ) {
case 'async.popular_qtns': // blah blah
break;
case 'async.recent_qtns': // blah blah
break;
}
}
how do I get the event name, eg, ‘async.enum_tag’ associated with the socket.on()?
I don’t think the event name is reported to the callback function. You could try something like this:
Or, probably better: