|
@@ -13,7 +13,8 @@ local parse = neturl.parseQuery;
|
13
|
13
|
local get_room_from_jid = module:require "util".get_room_from_jid;
|
14
|
14
|
local room_jid_match_rewrite = module:require "util".room_jid_match_rewrite;
|
15
|
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
|
18
|
local async_handler_wrapper = module:require "util".async_handler_wrapper;
|
18
|
19
|
|
19
|
20
|
-- this basically strips the domain from the conference.domain address
|
|
@@ -158,14 +159,21 @@ local function cb(content_, code_, response_, request_)
|
158
|
159
|
end
|
159
|
160
|
end
|
160
|
161
|
|
161
|
|
-local function sendEvent(type,room_address,participant,edetails)
|
|
162
|
+local function sendEvent(type,room_address,participant)
|
162
|
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
|
172
|
local out_event = {
|
164
|
173
|
["conference"] = room_address,
|
165
|
|
- ["event_type"] = "Event"..type,
|
|
174
|
+ ["room_param"] = room_param,
|
|
175
|
+ ["event_type"] = type,
|
166
|
176
|
["participant"] = participant,
|
167
|
|
- ["event_details"] = edetails,
|
168
|
|
- ["event_ts"] = event_ts
|
169
|
177
|
}
|
170
|
178
|
module:log("debug","Sending event %s",inspect(out_event));
|
171
|
179
|
|
|
@@ -191,14 +199,14 @@ function on_iq(event)
|
191
|
199
|
log("info", "Jibri Queue Messsage Event found: %s ",inspect(event.stanza));
|
192
|
200
|
|
193
|
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
|
203
|
if jibriQueue then
|
196
|
|
- log("info", "Jibri Queue: %s ",inspect(jibriQueue));
|
|
204
|
+ module:log("info", "Jibri Queue Join Request: %s ",inspect(jibriQueue));
|
197
|
205
|
local roomAddress = jibriQueue.attr.room;
|
198
|
206
|
local room = get_room_from_jid(room_jid_match_rewrite(roomAddress));
|
199
|
207
|
|
200
|
208
|
if not room then
|
201
|
|
- log("warn", "No room found %s", roomAddress);
|
|
209
|
+ module:log("warn", "No room found %s", roomAddress);
|
202
|
210
|
return false;
|
203
|
211
|
end
|
204
|
212
|
|
|
@@ -206,35 +214,64 @@ function on_iq(event)
|
206
|
214
|
|
207
|
215
|
local occupant = room:get_occupant_by_real_jid(from);
|
208
|
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
|
218
|
return false;
|
211
|
219
|
end
|
|
220
|
+
|
212
|
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
|
228
|
end
|
218
|
229
|
end
|
219
|
230
|
end
|
220
|
231
|
return true
|
221
|
232
|
end
|
222
|
233
|
|
223
|
|
-function occupant_joined(event)
|
|
234
|
+-- create recorder queue cache for the room
|
|
235
|
+function room_created(event)
|
224
|
236
|
local room = event.room;
|
225
|
|
- local occupant = event.occupant;
|
226
|
237
|
|
227
|
238
|
if is_healthcheck_room(room.jid) then
|
228
|
239
|
return;
|
229
|
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
|
275
|
end
|
239
|
276
|
|
240
|
277
|
module:hook("iq/host", on_iq);
|
|
@@ -245,10 +282,10 @@ function process_host(host)
|
245
|
282
|
module:log("info","Hook to muc events on %s", host);
|
246
|
283
|
|
247
|
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
|
289
|
end
|
253
|
290
|
end
|
254
|
291
|
|