"Fossies" - the Fresh Open Source Software Archive 
Member "jitsi-meet-7564/resources/prosody-plugins/mod_muc_meeting_id.lua" (3 Oct 2023, 4522 Bytes) of package /linux/misc/jitsi-meet-7564.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Lua source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
See also the last
Fossies "Diffs" side-by-side code changes report for "mod_muc_meeting_id.lua":
7531_vs_7542.
1 local queue = require "util.queue";
2 local uuid_gen = require "util.uuid".generate;
3 local main_util = module:require "util";
4 local ends_with = main_util.ends_with;
5 local is_healthcheck_room = main_util.is_healthcheck_room;
6 local internal_room_jid_match_rewrite = main_util.internal_room_jid_match_rewrite;
7 local presence_check_status = main_util.presence_check_status;
8
9 local um_is_admin = require 'core.usermanager'.is_admin;
10 local function is_admin(jid)
11 return um_is_admin(jid, module.host);
12 end
13
14 local QUEUE_MAX_SIZE = 100;
15
16 -- Module that generates a unique meetingId, attaches it to the room
17 -- and adds it to all disco info form data (when room is queried or in the
18 -- initial room owner config)
19
20 -- Hook to assign meetingId for new rooms
21 module:hook("muc-room-created", function(event)
22 local room = event.room;
23
24 if is_healthcheck_room(room.jid) then
25 return;
26 end
27
28 room._data.meetingId = uuid_gen();
29
30 module:log("debug", "Created meetingId:%s for %s",
31 room._data.meetingId, room.jid);
32 end);
33
34 -- Returns the meeting config Id form data.
35 function getMeetingIdConfig(room)
36 return {
37 name = "muc#roominfo_meetingId";
38 type = "text-single";
39 label = "The meeting unique id.";
40 value = room._data.meetingId or "";
41 };
42 end
43
44 -- add meeting Id to the disco info requests to the room
45 module:hook("muc-disco#info", function(event)
46 table.insert(event.form, getMeetingIdConfig(event.room));
47 end);
48
49 -- add the meeting Id in the default config we return to jicofo
50 module:hook("muc-config-form", function(event)
51 table.insert(event.form, getMeetingIdConfig(event.room));
52 end, 90-3);
53
54 -- disabled few options for room config, to not mess with visitor logic
55 module:hook("muc-config-submitted/muc#roomconfig_moderatedroom", function()
56 return true;
57 end, 99);
58 module:hook("muc-config-submitted/muc#roomconfig_presencebroadcast", function()
59 return true;
60 end, 99);
61 module:hook("muc-config-submitted/muc#roominfo_meetingId", function(event)
62 -- we allow jicofo to overwrite the meetingId
63 if is_admin(event.actor) then
64 event.room._data.meetingId = event.value;
65 return;
66 end
67
68 return true;
69 end, 99);
70 module:hook('muc-broadcast-presence', function (event)
71 local actor, occupant, room, x = event.actor, event.occupant, event.room, event.x;
72 if presence_check_status(x, '307') then
73 -- make sure we update and affiliation for kicked users
74 room:set_affiliation(actor, occupant.bare_jid, 'none');
75 end
76 end);
77
78 --- Avoids any participant joining the room in the interval between creating the room
79 --- and jicofo entering the room
80 module:hook('muc-occupant-pre-join', function (event)
81 local room, stanza = event.room, event.stanza;
82
83 -- we skip processing only if jicofo_lock is set to false
84 if room._data.jicofo_lock == false or is_healthcheck_room(room.jid) then
85 return;
86 end
87
88 local occupant = event.occupant;
89 if ends_with(occupant.nick, '/focus') then
90 module:fire_event('jicofo-unlock-room', { room = room; });
91 else
92 room._data.jicofo_lock = true;
93 if not room.pre_join_queue then
94 room.pre_join_queue = queue.new(QUEUE_MAX_SIZE);
95 end
96
97 if not room.pre_join_queue:push(event) then
98 module:log('error', 'Error enqueuing occupant event for: %s', occupant.nick);
99 return true;
100 end
101 module:log('debug', 'Occupant pushed to prejoin queue %s', occupant.nick);
102
103 -- stop processing
104 return true;
105 end
106 end, 8); -- just after the rate limit
107
108 function handle_jicofo_unlock(event)
109 local room = event.room;
110
111 room._data.jicofo_lock = false;
112 if not room.pre_join_queue then
113 return;
114 end
115
116 -- and now let's handle all pre_join_queue events
117 for _, ev in room.pre_join_queue:items() do
118 -- if the connection was closed while waiting in the queue, ignore
119 if ev.origin.conn then
120 module:log('debug', 'Occupant processed from queue %s', ev.occupant.nick);
121 room:handle_normal_presence(ev.origin, ev.stanza);
122 end
123 end
124 room.pre_join_queue = nil;
125 end
126
127 module:hook('jicofo-unlock-room', handle_jicofo_unlock);
128
129 -- make sure we remove nick if someone is sending it with a message to protect
130 -- forgery of display name
131 module:hook("muc-occupant-groupchat", function(event)
132 event.stanza:remove_children('nick', 'http://jabber.org/protocol/nick');
133 end, 45); -- prosody check is prio 50, we want to run after it