|
@@ -0,0 +1,69 @@
|
|
1
|
+local json = require 'cjson';
|
|
2
|
+
|
|
3
|
+local util = module:require 'util';
|
|
4
|
+local room_jid_match_rewrite = util.room_jid_match_rewrite;
|
|
5
|
+local get_room_from_jid = util.get_room_from_jid;
|
|
6
|
+
|
|
7
|
+-- This needs to be attached to the main virtual host and the virtual host where jicofo is connected and authenticated.
|
|
8
|
+-- The first pass is the iq coming from the client where we get the creator and attach it to the app_data.
|
|
9
|
+-- The second pass is jicofo approving that and inviting jibri where we attach the session_id information to app_data
|
|
10
|
+local function attachJibriSessionId(event)
|
|
11
|
+local stanza = event.stanza;
|
|
12
|
+ if stanza.name == "iq" then
|
|
13
|
+ local jibri = stanza:get_child('jibri', 'http://jitsi.org/protocol/jibri');
|
|
14
|
+ if jibri then
|
|
15
|
+ if jibri.attr.action == 'start' then
|
|
16
|
+
|
|
17
|
+ local update_app_data = false;
|
|
18
|
+ local app_data = jibri.attr.app_data;
|
|
19
|
+ if app_data then
|
|
20
|
+ app_data = json.decode(app_data);
|
|
21
|
+ else
|
|
22
|
+ app_data = {};
|
|
23
|
+ end
|
|
24
|
+ if app_data.file_recording_metadata == nil then
|
|
25
|
+ app_data.file_recording_metadata = {};
|
|
26
|
+ end
|
|
27
|
+
|
|
28
|
+ if jibri.attr.room then
|
|
29
|
+ local jibri_room = jibri.attr.room;
|
|
30
|
+ jibri_room = room_jid_match_rewrite(jibri_room)
|
|
31
|
+ local room = get_room_from_jid(jibri_room);
|
|
32
|
+ if room then
|
|
33
|
+ local conference_details = {};
|
|
34
|
+ conference_details["session_id"] = room._data.meetingId;
|
|
35
|
+ app_data.file_recording_metadata.conference_details = conference_details;
|
|
36
|
+ update_app_data = true;
|
|
37
|
+ end
|
|
38
|
+ else
|
|
39
|
+ -- no room is because the iq received by the initiator in the room
|
|
40
|
+ local session = event.origin;
|
|
41
|
+ -- if a token is provided, add data to app_data
|
|
42
|
+ if session ~= nil then
|
|
43
|
+ local initiator = {};
|
|
44
|
+
|
|
45
|
+ if session.jitsi_meet_context_user ~= nil then
|
|
46
|
+ initiator.id = session.jitsi_meet_context_user.id;
|
|
47
|
+ end
|
|
48
|
+ if session.jitsi_meet_context_group ~= nil then
|
|
49
|
+ initiator.group = session.jitsi_meet_context_group;
|
|
50
|
+ end
|
|
51
|
+
|
|
52
|
+ app_data.file_recording_metadata.initiator = initiator
|
|
53
|
+ update_app_data = true;
|
|
54
|
+ end
|
|
55
|
+
|
|
56
|
+ end
|
|
57
|
+
|
|
58
|
+ if update_app_data then
|
|
59
|
+ app_data = json.encode(app_data);
|
|
60
|
+ jibri.attr.app_data = app_data;
|
|
61
|
+ jibri:up()
|
|
62
|
+ stanza:up()
|
|
63
|
+ end
|
|
64
|
+ end
|
|
65
|
+ end
|
|
66
|
+ end
|
|
67
|
+end
|
|
68
|
+
|
|
69
|
+module:hook('pre-iq/full', attachJibriSessionId);
|