You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mod_muc_wait_for_host.lua 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. -- This module is activated under the main muc component
  2. -- This will prevent anyone joining the call till jicofo and one moderator join the room
  3. -- for the rest of the participants lobby will be turned on and they will be waiting there till
  4. -- the main participant joins and lobby will be turned off at that time and rest of the participants will
  5. -- join the room. It expects main virtual host to be set to require jwt tokens and guests to use
  6. -- the guest domain which is anonymous.
  7. -- The module has the option to set participants to moderators when connected via token/when they are authenticated
  8. -- This module depends on mod_persistent_lobby.
  9. local um_is_admin = require 'core.usermanager'.is_admin;
  10. local jid = require 'util.jid';
  11. local util = module:require "util";
  12. local is_healthcheck_room = util.is_healthcheck_room;
  13. local is_moderated = util.is_moderated;
  14. local process_host_module = util.process_host_module;
  15. local disable_auto_owners = module:get_option_boolean('wait_for_host_disable_auto_owners', false);
  16. local muc_domain_base = module:get_option_string('muc_mapper_domain_base');
  17. if not muc_domain_base then
  18. module:log('warn', "No 'muc_mapper_domain_base' option set, disabling muc_mapper plugin inactive");
  19. return
  20. end
  21. -- to activate this you need the following config in general config file in log = { }
  22. -- { to = 'file', filename = '/var/log/prosody/prosody.audit.log', levels = { 'audit' } }
  23. local logger = require 'util.logger';
  24. local audit_logger = logger.make_logger('mod_'..module.name, 'audit');
  25. local lobby_muc_component_config = 'lobby.' .. muc_domain_base;
  26. local lobby_host;
  27. if not disable_auto_owners then
  28. module:hook('muc-occupant-joined', function (event)
  29. local room, occupant, session = event.room, event.occupant, event.origin;
  30. local is_moderated_room = is_moderated(room.jid);
  31. -- for jwt authenticated and username and password authenticated
  32. -- only if it is not a moderated room
  33. if not is_moderated_room and
  34. (session.auth_token or (session.username and jid.host(occupant.bare_jid) == muc_domain_base)) then
  35. room:set_affiliation(true, occupant.bare_jid, 'owner');
  36. end
  37. end, 2);
  38. end
  39. local function is_admin(jid)
  40. return um_is_admin(jid, module.host);
  41. end
  42. -- if not authenticated user is trying to join the room we enable lobby in it
  43. -- and wait for the moderator to join
  44. module:hook('muc-occupant-pre-join', function (event)
  45. local room, occupant, session = event.room, event.occupant, event.origin;
  46. -- we ignore jicofo as we want it to join the room or if the room has already seen its
  47. -- authenticated host
  48. if is_admin(occupant.bare_jid) or is_healthcheck_room(room.jid) or room.has_host then
  49. return;
  50. end
  51. local has_host = false;
  52. for _, o in room:each_occupant() do
  53. if jid.host(o.bare_jid) == muc_domain_base then
  54. room.has_host = true;
  55. end
  56. end
  57. if not room.has_host then
  58. if session.auth_token or (session.username and jid.host(occupant.bare_jid) == muc_domain_base) then
  59. -- the host is here, let's drop the lobby
  60. room:set_members_only(false);
  61. -- let's set the default role of 'participant' for the newly created occupant as it was nil when created
  62. -- when the room was still members_only, later if not disabled this participant will become a moderator
  63. occupant.role = room:get_default_role(room:get_affiliation(occupant.bare_jid)) or 'participant';
  64. module:log('info', 'Host %s arrived in %s.', occupant.bare_jid, room.jid);
  65. audit_logger('room_jid:%s created_by:%s', room.jid,
  66. session.jitsi_meet_context_user and session.jitsi_meet_context_user.id or 'nil');
  67. module:fire_event('room_host_arrived', room.jid, session);
  68. lobby_host:fire_event('destroy-lobby-room', {
  69. room = room,
  70. newjid = room.jid,
  71. message = 'Host arrived.',
  72. });
  73. elseif not room:get_members_only() then
  74. -- let's enable lobby
  75. module:log('info', 'Will wait for host in %s.', room.jid);
  76. prosody.events.fire_event('create-persistent-lobby-room', {
  77. room = room;
  78. reason = 'waiting-for-host',
  79. skip_display_name_check = true;
  80. });
  81. end
  82. end
  83. end);
  84. process_host_module(lobby_muc_component_config, function(host_module, host)
  85. -- lobby muc component created
  86. module:log('info', 'Lobby component loaded %s', host);
  87. lobby_host = module:context(host_module);
  88. end);