Reputation: 7330
connection
disconnect
custom-event
Are these string available somewhere on the socket
object on the server-side? in case the socket object is passed around, otherwise I'll passing another param with event as well and function signature would be as follows.
io.on('connection', function(socket) {
doSomething(socket, 'connection');
socket.on('disconnect', function(){
doSomething(socket', 'disconnect');
}
}
function doSomething(socket, eventName) {
// is there a way to get this event name from socket object itself?
}
Upvotes: 0
Views: 368
Reputation: 707158
Are these string available somewhere on the socket object on the server-side?
No. If you want an event name passed to your function, you need to pass it yourself like your own example shows. It is not part of the socket
object because (with async operations in-flight) multiple events could be in-flight at the same time so the socket
object is not a safe place to store the "current" event.
Upvotes: 1