Browse Source

prosody modules: jibri queue events for leave, room destroyed

master
Aaron van Meerten 5 years ago
parent
commit
099820b6ac
1 changed files with 62 additions and 25 deletions
  1. 62
    25
      resources/prosody-plugins/mod_jibri_queue_component.lua

+ 62
- 25
resources/prosody-plugins/mod_jibri_queue_component.lua View File

13
 local get_room_from_jid = module:require "util".get_room_from_jid;
13
 local get_room_from_jid = module:require "util".get_room_from_jid;
14
 local room_jid_match_rewrite = module:require "util".room_jid_match_rewrite;
14
 local room_jid_match_rewrite = module:require "util".room_jid_match_rewrite;
15
 local is_healthcheck_room = module:require "util".is_healthcheck_room;
15
 local is_healthcheck_room = module:require "util".is_healthcheck_room;
16
-
16
+local room_jid_split_subdomain = module:require "util".room_jid_split_subdomain;
17
+local internal_room_jid_match_rewrite = module:require "util".internal_room_jid_match_rewrite;
17
 local async_handler_wrapper = module:require "util".async_handler_wrapper;
18
 local async_handler_wrapper = module:require "util".async_handler_wrapper;
18
 
19
 
19
 -- this basically strips the domain from the conference.domain address
20
 -- this basically strips the domain from the conference.domain address
158
     end
159
     end
159
 end
160
 end
160
 
161
 
161
-local function sendEvent(type,room_address,participant,edetails)
162
+local function sendEvent(type,room_address,participant)
162
     local event_ts = round(socket.gettime()*1000);
163
     local event_ts = round(socket.gettime()*1000);
164
+    local node, host, resource, target_subdomain = room_jid_split_subdomain(room_address);
165
+    local room_param = '';
166
+    if target_subdomain then
167
+        room_param = target_subdomain..'/'..node;
168
+    else
169
+        room_param = node;
170
+    end
171
+
163
     local out_event = {
172
     local out_event = {
164
         ["conference"] = room_address,
173
         ["conference"] = room_address,
165
-        ["event_type"] = "Event"..type,
174
+        ["room_param"] = room_param,
175
+        ["event_type"] = type,
166
         ["participant"] = participant,
176
         ["participant"] = participant,
167
-        ["event_details"] = edetails,
168
-        ["event_ts"] = event_ts
169
     }
177
     }
170
     module:log("debug","Sending event %s",inspect(out_event));
178
     module:log("debug","Sending event %s",inspect(out_event));
171
 
179
 
191
             log("info", "Jibri Queue Messsage Event found: %s ",inspect(event.stanza));
199
             log("info", "Jibri Queue Messsage Event found: %s ",inspect(event.stanza));
192
 
200
 
193
             local jibriQueue
201
             local jibriQueue
194
-                = event.stanza:get_child('jibriqueue', 'http://jitsi.org/protocol/jibri-queue');
202
+                = event.stanza:get_child('jibri-queue', 'http://jitsi.org/protocol/jibri-queue');
195
             if jibriQueue then
203
             if jibriQueue then
196
-                log("info", "Jibri Queue: %s ",inspect(jibriQueue));
204
+                module:log("info", "Jibri Queue Join Request: %s ",inspect(jibriQueue));
197
                 local roomAddress = jibriQueue.attr.room;
205
                 local roomAddress = jibriQueue.attr.room;
198
                 local room = get_room_from_jid(room_jid_match_rewrite(roomAddress));
206
                 local room = get_room_from_jid(room_jid_match_rewrite(roomAddress));
199
 
207
 
200
                 if not room then
208
                 if not room then
201
-                    log("warn", "No room found %s", roomAddress);
209
+                    module:log("warn", "No room found %s", roomAddress);
202
                     return false;
210
                     return false;
203
                 end
211
                 end
204
 
212
 
206
 
214
 
207
                 local occupant = room:get_occupant_by_real_jid(from);
215
                 local occupant = room:get_occupant_by_real_jid(from);
208
                 if not occupant then
216
                 if not occupant then
209
-                    log("warn", "No occupant %s found for %s", from, roomAddress);
217
+                    module:log("warn", "No occupant %s found for %s", from, roomAddress);
210
                     return false;
218
                     return false;
211
                 end
219
                 end
220
+
212
                 -- now handle new jibri queue message
221
                 -- now handle new jibri queue message
213
-                local edetails = {
214
-                    ["foo"] = "bar"
215
-                }
216
-                sendEvent('JoinQueue',room.jid,occupant.jid,edetails)
222
+                room.jibriQueue[occupant.jid] = true;
223
+
224
+                module:log("Sending JoinQueue event for jid %s occupant %s",roomAddress,occupant.jid)
225
+                sendEvent('JoinQueue',roomAddress,occupant.jid)
226
+            else
227
+                module:log("Jibri Queue Stanza missing child %s",inspect(event.stanza))
217
             end
228
             end
218
         end
229
         end
219
     end
230
     end
220
     return true
231
     return true
221
 end
232
 end
222
 
233
 
223
-function occupant_joined(event)
234
+-- create recorder queue cache for the room
235
+function room_created(event)
224
     local room = event.room;
236
     local room = event.room;
225
-    local occupant = event.occupant;
226
 
237
 
227
     if is_healthcheck_room(room.jid) then
238
     if is_healthcheck_room(room.jid) then
228
         return;
239
         return;
229
     end
240
     end
230
 
241
 
231
-    local participant_count = it.count(room:each_occupant());
242
+    room.jibriQueue = {};
243
+end
232
 
244
 
233
-    -- now handle new jibri queue message
234
-    local edetails = {
235
-        ["participant_count"] = participant_count
236
-    }
237
-    sendEvent('Join',room.jid,occupant.jid,edetails)
245
+-- Conference ended, clear all queue cache jids
246
+function room_destroyed(event)
247
+    local room = event.room;
248
+
249
+    if is_healthcheck_room(room.jid) then
250
+        return;
251
+    end
252
+    for jid, x in pairs(room.jibriQueue) do
253
+        if x then
254
+            sendEvent('LeaveQueue',internal_room_jid_match_rewrite(room.jid),jid);
255
+        end
256
+    end
257
+end
258
+
259
+-- Occupant left remove it from the queue if it joined the queue
260
+function occupant_leaving(event)
261
+    local room = event.room;
262
+
263
+    if is_healthcheck_room(room.jid) then
264
+        return;
265
+    end
266
+
267
+    local occupant = event.occupant;
268
+
269
+    -- check if user has cached queue request
270
+    if room.jibriQueue[occupant.jid] then
271
+        -- remove occupant from queue cache, signal backend
272
+        room.jibriQueue[occupant.jid] = nil;
273
+        sendEvent('LeaveQueue',internal_room_jid_match_rewrite(room.jid),occupant.jid);
274
+    end
238
 end
275
 end
239
 
276
 
240
 module:hook("iq/host", on_iq);
277
 module:hook("iq/host", on_iq);
245
         module:log("info","Hook to muc events on %s", host);
282
         module:log("info","Hook to muc events on %s", host);
246
 
283
 
247
         local muc_module = module:context(host);
284
         local muc_module = module:context(host);
248
-        -- muc_module:hook("muc-room-created", room_created, -1);
249
-        muc_module:hook("muc-occupant-joined", occupant_joined, -1);
250
-        -- muc_module:hook("muc-occupant-pre-leave", occupant_leaving, -1);
251
-        -- muc_module:hook("muc-room-destroyed", room_destroyed, -1);
285
+        muc_module:hook("muc-room-created", room_created, -1);
286
+        -- muc_module:hook("muc-occupant-joined", occupant_joined, -1);
287
+        muc_module:hook("muc-occupant-pre-leave", occupant_leaving, -1);
288
+        muc_module:hook("muc-room-destroyed", room_destroyed, -1);
252
     end
289
     end
253
 end
290
 end
254
 
291
 

Loading…
Cancel
Save