Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

feat(time-restricted): Add an option to unblock room names after a period

damenchoa37a5965df31
diff --git a/resources/prosody-plugins/mod_time_restricted.lua b/resources/prosody-plugins/mod_time_restricted.lua
index 6023350213..614a6a70fa 100644
--- a/resources/prosody-plugins/mod_time_restricted.lua
+++ b/resources/prosody-plugins/mod_time_restricted.lua
@@ -12,14 +12,49 @@ local TIMEOUT = MIN * 60
local GRACE = module:get_option_number("conference_grace_seconds", 0)
local DESTROY_AT = TIMEOUT + GRACE
+-- Hours after which a room that reached the limit can be created again. 0 (the
+-- default) keeps the room name blocked until prosody restarts.
+local BLOCKED_CLEANUP_HOURS = module:get_option_number("conference_blocked_cleanup_hours", 0)
+local BLOCKED_CLEANUP_SECONDS = BLOCKED_CLEANUP_HOURS * 3600
+
+-- How often expired room names are dropped from the blocked list.
+local BLOCKED_SWEEP_INTERVAL = 300
+
local is_healthcheck_room = module:require "util".is_healthcheck_room
local st = require "util.stanza"
local json = require "cjson.safe"
local array = require "util.array";
module:log('info', "loaded")
+-- Room JID -> the time the room was destroyed for reaching the limit.
local restricted_rooms = array{};
+local function is_blocked(room_jid)
+ local blocked_at = restricted_rooms[room_jid];
+
+ if not blocked_at then
+ return false;
+ end
+
+ if BLOCKED_CLEANUP_SECONDS > 0 and os.time() - blocked_at >= BLOCKED_CLEANUP_SECONDS then
+ restricted_rooms[room_jid] = nil;
+ module:log('info', "the conference id unblocked %s", room_jid);
+ return false;
+ end
+
+ return true;
+end
+
+if BLOCKED_CLEANUP_SECONDS > 0 then
+ module:add_timer(BLOCKED_SWEEP_INTERVAL, function()
+ for room_jid in pairs(restricted_rooms) do
+ is_blocked(room_jid);
+ end
+
+ return BLOCKED_SWEEP_INTERVAL;
+ end)
+end
+
-- The `type` the time-timer feature in jitsi-meet matches on. Sent as a
-- json-message from the room JID so lib-jitsi-meet surfaces it as a
-- NON_PARTICIPANT_MESSAGE_RECEIVED (a server-originated, non-participant
@@ -63,7 +98,7 @@ module:hook("muc-room-created", function (event)
if is_healthcheck_room(room.jid) then
return
end
- restricted_rooms[room.jid] = true;
+ restricted_rooms[room.jid] = os.time();
-- %g (not %d) so a fractional conference_max_minutes does not crash the
-- timer; for the usual whole-minute configs it renders identically.
room:destroy(nil, string.format('This meeting reached its %g-minute time limit and has ended.', MIN));
@@ -100,7 +135,7 @@ module:hook("muc-room-pre-create", function(event)
return
end
- if restricted_rooms[room.jid] then
+ if is_blocked(room.jid) then
module:log('info', "the conference id blocked %s", room.jid);
origin.send(st.error_reply(stanza, "cancel", "resource-constraint", nil, module.host));
return true;
diff --git a/tests/prosody/docker/cfg/conference.cfg.lua b/tests/prosody/docker/cfg/conference.cfg.lua
index 660bb6fc9f..cc241c0b74 100644
--- a/tests/prosody/docker/cfg/conference.cfg.lua
+++ b/tests/prosody/docker/cfg/conference.cfg.lua
@@ -65,9 +65,11 @@ Component "conference.localhost" "muc"
-- mod_time_restricted (loaded on demand by mod_time_restricted_spec, not in
-- modules_enabled, so it does not destroy other tests' rooms): a fractional
-- limit keeps the test fast — 0.125 min = 7.5 s to the limit, plus a 3 s
- -- wrap-up grace before the room is actually destroyed.
+ -- wrap-up grace before the room is actually destroyed. The room name is
+ -- unblocked 0.002 h = 7.2 s after the destroy.
conference_max_minutes = 0.125
conference_grace_seconds = 3
+ conference_blocked_cleanup_hours = 0.002
-- mod_muc_limit_messages: cap per room and honour auth tokens.
muc_limit_messages_count = 3
diff --git a/tests/prosody/mod_time_restricted_spec.js b/tests/prosody/mod_time_restricted_spec.js
index 3b4afebe0a..6641eae664 100644
--- a/tests/prosody/mod_time_restricted_spec.js
+++ b/tests/prosody/mod_time_restricted_spec.js
@@ -11,8 +11,10 @@ const JITMEET_NS = 'http://jitsi.org/jitmeet';
// Mirrors docker/prosody.cfg.lua:
// conference_max_minutes = 0.125 -> TIMEOUT = 7.5 s (the meeting's limit)
// conference_grace_seconds = 3 -> room destroyed at 10.5 s
+// conference_blocked_cleanup_hours = 0.002 -> name unblocked 7.2 s after the destroy
const DURATION_SECONDS = 7.5;
const GRACE_SECONDS = 3;
+const BLOCKED_CLEANUP_SECONDS = 7.2;
// A moment safely inside the grace window: past the limit, well before the
// destroy. Used to prove the room outlives its limit by the granted time.
@@ -188,6 +190,36 @@ describe('mod_time_restricted', () => {
assert.equal(await getRoomState(r), null, 'the room must not be re-created');
});
+ it('allows re-creation once conference_blocked_cleanup_hours elapses', async () => {
+ const r = room();
+
+ await ctx.connectFocus(r);
+
+ const c = await ctx.connect();
+
+ await c.joinRoom(r);
+ await c.waitForPresence(p => p.attrs.type === 'unavailable', DESTROY_WAIT_MS);
+ const destroyedAt = Date.now();
+
+ // Slack over the cleanup period.
+ const unblockedAt = destroyedAt + ((BLOCKED_CLEANUP_SECONDS + 2) * 1000);
+
+ await new Promise(resolve => setTimeout(resolve, Math.max(0, unblockedAt - Date.now())));
+
+ const probe = await createXmppClient({ domain: 'auth.localhost',
+ username: 'focus',
+ password: 'focussecret' });
+
+ try {
+ const rejoin = await probe.joinRoom(r, 'focus', { timeout: 5000 });
+
+ assert.notEqual(rejoin.attrs.type, 'error', 're-creating the room must be allowed after the cleanup');
+ assert.ok(await getRoomState(r), 'the room must be re-created');
+ } finally {
+ await probe.disconnect();
+ }
+ });
+
// The client only trusts a `time_restricted` message because it arrives from
// the bare room JID: lib-jitsi-meet derives the endpoint id from the stanza's
// resource, and jitsi-meet's time-timer middleware ignores the message unless