Some broker implementations may provide suitable interceptors for connection / disconnect events to enable this, but this is not a requirement for the protocol for brokers.
You can create a presence support system using the protocol features
You can read more here: https://github.com/mqtt/mqtt.imtqy.com/wiki/presence
In conclusion, when the client connects, he must define the message "Last Wish" 0for publication in the subject client/[client-id]with the flag saved. Then he must publish the message stored in the subject client/[client-id]with the value 1.
This means that anyone can subscribe to client/+and receive the current status of all known customers:
1 client/A , A0 client/A , A
, , . , . - , .