Unregister disconnected users

I could not find a solution to this maybe because of bad search keywords, so I would appreciate it if someone could give me a hint.

I am using Asterisk via Openfire XMPP connection.
Openfire -> Asterisk connection is always done through a single Asterisk user (ex. 101).
We will probably change it to individual user accounts in the future.
Users access to Openfire from their browsers.
When a user closes a browser, user - Openfire connection is closed but the user remains registered in Asterisk.
We will try to send hangup message when a tab or window is closed, but I guess this problem will happen in many cases.

Is there a way to automatically unregister such users?

Thank you very much.