Prosody module hook "muc-room-pre-create" not working

Hello guys,
I created my own custom prosody module to lock rooms ahead of users joining.
If I use the “muc-room-created” hook the module works.

module:hook("muc-room-created", function (event)
    local room = event.room;
    module:log("debug", "hooked room create for %s", tostring(room));
    local pass = "pass";
    local res = room:set_password(pass);
    module:log("info", "Set password '%s' for %s.", pass, tostring(room));
    return nil;
end, 0);

But if I use the “muc-room-pre-create” hook it does not seem to work.

module:hook("muc-room-pre-create", function (event)
    local room = event.room;
    module:log("debug", "hooked room create for %s", tostring(room));
    local pass = "pass";
    local res = room:set_password(pass);
    module:log("info", "Set password '%s' for %s.", pass, tostring(room));
    return nil;
end, 0);

No error is thrown in the logs and the logs say that the room was successfully locked.
Any ideas on how to enable this module hook?

Perhaps it is down to hook priority? I have not validated this, but my suspicion is there is another hook on muc-room-pre-create that might be overriding the passwords (e.g. this).

Assuming that other hook runs with default priority 0, try changing yours to -1 so it runs after that initialisation.

Hi Shawn thanks for the reply, how do I change the priority?

It’s the third argument to module:hook(...) i.e. change the 0 there to -1.

It sadly did not solve the problem.

So you’ve solved this?

My bad, I use the “muc-room-created” hook and it works. Will first try to figure out how to dynamically set passwords then move on to correctly implement “muc-room-pre-create” hook.

Any reason not to use “muc-room-created” if it works?

No not really, I thought “muc-room-pre-create” would be better practice as it sets the password before the room creation.

I agree, it does make more sense to do it there. Odd that it doesn’t work.

I’ve experimented with this a little. Here are my observations:

  1. Using “muc-room-pre-create” with priority > 0, the set_password call succeeds but doesn’t take effect because it presumably then gets overridden by this.
  2. Using “muc-room-pre-create” with priority <= 0, it successfully sets the password on room but the conference does not start when users click “Join”. Looking at a Jicofo logs, we see that the focus user fails to join the room to start the conference because the room is now password protected.

So my understanding here is that while “muc-room-pre-create” conceptually sounds like a better place to do this, it might be too early as it stops the focus user (always the first to join a room) from entering.

So unless we can make modifications to exclude “focus” user from the room passwords, perhaps “muc-room-created” might be the better optionl?

1 Like

Good news. It looks like there is such a solution :smiley:

You can use mod_muc_password_whitlist.lua that’s included in with jitsi.

Component "conference.YOURDOMAIN" "muc"
   modules_enabled = {
      -- ...
      "muc_password_whitelist";
   }

   muc_password_whitelist = { "focus@auth.YOURDOMAIN" }

By adding this to my config, focus user was excluded from password checks and it all works as expected.

For the record, this is what I had in the custom module:

local is_healthcheck_room = module:require "util".is_healthcheck_room;

module:hook("muc-room-pre-create", function (event)
    local room = event.room;

    if is_healthcheck_room(room.jid) then
        return;
    end

    local pass = "password";
    room:set_password(pass);
end, -1);
2 Likes

So after your response my jitsi-meet.cfg.lua looks like this:

Component "muc.meet.jitsi" "muc"
    storage = "memory"
    modules_enabled = {
        "muc_password";
        "muc_password_whitelist";
        "muc_meeting_id";

        "polls";
        "muc_domain_mapper";

    }
    muc_password_whitelist = { "focus@auth.muc.meet.jitsi" }
    muc_room_cache_size = 1000
    muc_room_locking = false
    muc_room_default_public_jids = true

and my mod_muc_password.lua looks like this:

local is_healthcheck_room = module:require "util".is_healthcheck_room;

module:hook("muc-room-pre-create", function (event)
    local room = event.room;

    if is_healthcheck_room(room.jid) then
        return;
    end

    local pass = "password";
    room:set_password(pass);
    module:log("info", "Set password '%s' for %s.", pass, tostring(room));
end, -1);

The log at the second to last line in the mod_muc_password.lua module goes through. But the room is still not locked.

That should probably say “focus@auth.meet.jitsi” (without the “muc”).

Did you restart prosody after the changes?

set_password() returns a boolean true if it was successful. What do you get with:

local success = room:set_password(pass);

if success then
    module:log("info", "Password set for %s", tostring(room));
else
   module:log("error", "Failed to set password for %s", tostring(room));
end
1 Like

Nice, it actually works now. Thanks a lot :smiley:

Now just to find a way to dynamically pass the password and my first student job project will be complete.