fix: Fixes destroying main room when breakout rooms are enabled.

By the time the timer is fired the room maybe recreated (destroyed and created again) and we do not want to destroy it again. The timer was keeping a reference to the old room and is destroying it without notifying the future occupants(jicofo).
Drop save, as we do not need it before destroying, check lobby.
This commit is contained in:
Дамян Минков 2021-12-15 18:12:24 -06:00
parent 8fa22ce059
commit c8b5043d6b
1 changed files with 9 additions and 6 deletions

View File

@ -124,6 +124,7 @@ function broadcast_breakout_rooms(room_jid)
main_room._data.is_broadcast_breakout_scheduled = true; main_room._data.is_broadcast_breakout_scheduled = true;
main_room:save(true); main_room:save(true);
module:add_timer(BROADCAST_ROOMS_INTERVAL, function() module:add_timer(BROADCAST_ROOMS_INTERVAL, function()
local main_room, main_room_jid = get_main_room(room_jid);
main_room._data.is_broadcast_breakout_scheduled = false; main_room._data.is_broadcast_breakout_scheduled = false;
main_room:save(true); main_room:save(true);
@ -374,16 +375,16 @@ function exist_occupants_in_rooms(main_room)
end end
function on_occupant_left(event) function on_occupant_left(event)
local room = event.room; local room_jid = event.room.jid;
if is_healthcheck_room(room.jid) then if is_healthcheck_room(room_jid) then
return; return;
end end
local main_room, main_room_jid = get_main_room(room.jid); local main_room = get_main_room(room_jid);
if main_room._data.breakout_rooms_active and jid_node(event.occupant.jid) ~= 'focus' then if main_room._data.breakout_rooms_active and jid_node(event.occupant.jid) ~= 'focus' then
broadcast_breakout_rooms(room.jid); broadcast_breakout_rooms(room_jid);
end end
-- Close the conference if all left for good. -- Close the conference if all left for good.
@ -391,11 +392,13 @@ function on_occupant_left(event)
main_room._data.is_close_all_scheduled = true; main_room._data.is_close_all_scheduled = true;
main_room:save(true); main_room:save(true);
module:add_timer(ROOMS_TTL_IF_ALL_LEFT, function() module:add_timer(ROOMS_TTL_IF_ALL_LEFT, function()
-- we need to look up again the room as till the timer is fired, the room maybe already destroyed/recreated
-- and we will have the old instance
local main_room, main_room_jid = get_main_room(room_jid);
if main_room._data.is_close_all_scheduled then if main_room._data.is_close_all_scheduled then
module:log('info', 'Closing conference %s as all left for good.', main_room_jid); module:log('info', 'Closing conference %s as all left for good.', main_room_jid);
main_room:set_persistent(false); main_room:set_persistent(false);
main_room:save(true); main_room:destroy(nil, 'All occupants left.');
main_room:destroy(main_room_jid, 'All occupants left.');
end end
end) end)
end end