I can not find the way how to detect that the room is already empty or doesn’t exist anymore. We need this ability to make necessary changes in database. Is it possible?
Your best approach is to use prosody module, you can use the speakerstats as an example. It detects when room is being destroyed so it can do some post meeting stuff https://github.com/jitsi/jitsi-meet/blob/master/resources/prosody-plugins/mod_speakerstats_component.lua#L206