Trigger onDeparture in a room on browser close/refresh

Currently onDeparture is triggered when user leaves the room.

Is there a way to see if user leaves when browser is refreshed or closed (or any other similar situation) ?

In my avatar chat, I just get more and more instances of the same avatar if the user has done something else than specifically left the room.

One idea I had might be to set timeout of the connection really short time, and use connection.sendKeepAlive(); in that short interval.

When the user isno longer connected, therefore the user cannot be in the room…