Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jibri session data and cjson #14601

Merged
merged 2 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions resources/prosody-plugins/mod_av_moderation_component.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local internal_room_jid_match_rewrite = util.internal_room_jid_match_rewrite;
local room_jid_match_rewrite = util.room_jid_match_rewrite;
local process_host_module = util.process_host_module;
local array = require "util.array";
local json = require 'util.json';
local json = require 'cjson.safe';
local st = require 'util.stanza';

local muc_component_host = module:get_option_string('muc_component');
Expand Down Expand Up @@ -49,7 +49,12 @@ function notify_occupants_enable(jid, enable, room, actorJid, mediaType)
body_json.room = internal_room_jid_match_rewrite(room.jid);
body_json.actor = actorJid;
body_json.mediaType = mediaType;
local body_json_str = json.encode(body_json);
local body_json_str, error = json.encode(body_json);

if not body_json_str then
module:log('error', 'error encoding json room:%s error:%s', room.jid, error);
return;
end

if jid then
send_json_message(jid, body_json_str)
Expand All @@ -75,12 +80,23 @@ function notify_whitelist_change(jid, moderators, room, mediaType, removed)
body_json.removed = true;
end
body_json.mediaType = mediaType;
local moderators_body_json_str = json.encode(body_json);
local moderators_body_json_str, error = json.encode(body_json);

if not moderators_body_json_str then
module:log('error', 'error encoding moderator json room:%s error:%s', room.jid, error);
return;
end

body_json.whitelists = nil;
if not removed then
body_json.approved = true; -- we want to send to participants only that they were approved to unmute
end
local participant_body_json_str = json.encode(body_json);
local participant_body_json_str, error = json.encode(body_json);

if not participant_body_json_str then
module:log('error', 'error encoding participant json room:%s error:%s', room.jid, error);
return;
end

for _, occupant in room:each_occupant() do
if moderators and occupant.role == 'moderator' then
Expand Down Expand Up @@ -110,7 +126,13 @@ function notify_jid_approved(jid, from, room, mediaType)
body_json.mediaType = mediaType;
body_json.from = from;

send_json_message(jid, json.encode(body_json));
local json_message, error = json.encode(body_json);
if not json_message then
module:log('error', 'skip sending json message to:%s error:%s', jid, error);
return;
end

send_json_message(jid, json_message);
end

-- receives messages from clients to the component sending A/V moderation enable/disable commands or adding
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- DEPRECATED and will be removed, giving time for mobile clients to update
local st = require "util.stanza";
local socket = require "socket";
local json = require "util.json";
local json = require 'cjson.safe';
local it = require "util.iterators";
local process_host_module = module:require "util".process_host_module;

Expand Down
69 changes: 69 additions & 0 deletions resources/prosody-plugins/mod_jibri_session.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
local json = require 'cjson';

local util = module:require 'util';
local room_jid_match_rewrite = util.room_jid_match_rewrite;
local get_room_from_jid = util.get_room_from_jid;

-- This needs to be attached to the main virtual host and the virtual host where jicofo is connected and authenticated.
-- The first pass is the iq coming from the client where we get the creator and attach it to the app_data.
-- The second pass is jicofo approving that and inviting jibri where we attach the session_id information to app_data
local function attachJibriSessionId(event)
local stanza = event.stanza;
if stanza.name == "iq" then
local jibri = stanza:get_child('jibri', 'http://jitsi.org/protocol/jibri');
if jibri then
if jibri.attr.action == 'start' then

local update_app_data = false;
local app_data = jibri.attr.app_data;
if app_data then
app_data = json.decode(app_data);
else
app_data = {};
end
if app_data.file_recording_metadata == nil then
app_data.file_recording_metadata = {};
end

if jibri.attr.room then
local jibri_room = jibri.attr.room;
jibri_room = room_jid_match_rewrite(jibri_room)
local room = get_room_from_jid(jibri_room);
if room then
local conference_details = {};
conference_details["session_id"] = room._data.meetingId;
app_data.file_recording_metadata.conference_details = conference_details;
update_app_data = true;
end
else
-- no room is because the iq received by the initiator in the room
local session = event.origin;
-- if a token is provided, add data to app_data
if session ~= nil then
local initiator = {};

if session.jitsi_meet_context_user ~= nil then
initiator.id = session.jitsi_meet_context_user.id;
end
if session.jitsi_meet_context_group ~= nil then
initiator.group = session.jitsi_meet_context_group;
end

app_data.file_recording_metadata.initiator = initiator
update_app_data = true;
end

end

if update_app_data then
app_data = json.encode(app_data);
jibri.attr.app_data = app_data;
jibri:up()
stanza:up()
end
end
end
end
end

module:hook('pre-iq/full', attachJibriSessionId);
15 changes: 12 additions & 3 deletions resources/prosody-plugins/mod_muc_breakout_rooms.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ end
local jid_node = require 'util.jid'.node;
local jid_host = require 'util.jid'.host;
local jid_split = require 'util.jid'.split;
local json = require 'util.json';
local json = require 'cjson.safe';
local st = require 'util.stanza';
local uuid_gen = require 'util.uuid'.generate;

Expand Down Expand Up @@ -166,13 +166,18 @@ function broadcast_breakout_rooms(room_jid)
end
end

local json_msg = json.encode({
local json_msg, error = json.encode({
type = BREAKOUT_ROOMS_IDENTITY_TYPE,
event = JSON_TYPE_UPDATE_BREAKOUT_ROOMS,
roomCounter = main_room._data.breakout_rooms_counter,
rooms = rooms
});

if not json_msg then
module:log('error', 'not broadcasting breakout room information room:%s error:%s', main_room_jid, error);
return;
end

for _, occupant in main_room:each_occupant() do
if jid_node(occupant.jid) ~= 'focus' then
send_json_msg(occupant.jid, json_msg)
Expand Down Expand Up @@ -329,12 +334,16 @@ function on_message(event)
local participant_jid = message.attr.participantJid;
local target_room_jid = message.attr.roomJid;

local json_msg = json.encode({
local json_msg, error = json.encode({
type = BREAKOUT_ROOMS_IDENTITY_TYPE,
event = JSON_TYPE_MOVE_TO_ROOM_REQUEST,
roomJid = target_room_jid
});

if not json_msg then
module:log('error', 'skip sending request room:%s error:%s', room.jid, error);
end

send_json_msg(participant_jid, json_msg)
return true;
end
Expand Down
2 changes: 1 addition & 1 deletion resources/prosody-plugins/mod_muc_census.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
-- network filters

local jid = require "util.jid";
local json = require "util.json";
local json = require 'cjson.safe';
local iterators = require "util.iterators";
local util = module:require "util";
local is_healthcheck_room = util.is_healthcheck_room;
Expand Down
9 changes: 7 additions & 2 deletions resources/prosody-plugins/mod_muc_jigasi_invite.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local jid_split = require "util.jid".split;
local hashes = require "util.hashes";
local random = require "util.random";
local st = require("util.stanza");
local json = require "util.json";
local json = require 'cjson.safe';
local util = module:require "util";
local async_handler_wrapper = util.async_handler_wrapper;
local process_host_module = util.process_host_module;
Expand Down Expand Up @@ -133,7 +133,12 @@ local function handle_jigasi_invite(event)
module:log("warn", "Wrong content type: %s or missing payload", request.headers.content_type);
return { status_code = 400; }
end
local payload = json.decode(request.body);
local payload, error = json.decode(request.body);

if not payload then
module:log('error', 'Cannot decode json error:%s', error);
return { status_code = 400; }
end

local conference = payload["conference"];
local phone_no = payload["phoneNo"];
Expand Down
6 changes: 3 additions & 3 deletions resources/prosody-plugins/mod_muc_kick_jigasi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ local starts_with = util.starts_with;
local formdecode = require "util.http".formdecode;
local urlencode = require "util.http".urlencode;
local jid = require "util.jid";
local json = require "util.json";
local json = require 'cjson.safe';

local muc_domain_prefix = module:get_option_string("muc_mapper_domain_prefix", "conference");

Expand Down Expand Up @@ -107,9 +107,9 @@ function handle_kick_participant (event)
return { status_code = 400; }
end

local params = json.decode(request.body);
local params, error = json.decode(request.body);
if not params then
module:log("warn", "Missing params");
module:log("warn", "Missing params error:%s", error);
return { status_code = 400; }
end

Expand Down
11 changes: 9 additions & 2 deletions resources/prosody-plugins/mod_muc_lobby_rooms.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ local jid_bare = require 'util.jid'.bare;
local jid_prep = require "util.jid".prep;
local jid_resource = require "util.jid".resource;
local resourceprep = require "util.encodings".stringprep.resourceprep;
local json = require 'util.json';
local json = require 'cjson.safe';
local filters = require 'util.filters';
local st = require 'util.stanza';
local muc_util = module:require "muc/util";
Expand Down Expand Up @@ -80,10 +80,17 @@ function broadcast_json_msg(room, from, json_msg)

local occupant = room:get_occupant_by_real_jid(from);
if occupant then
local json_msg_str, error = json.encode(json_msg);

if not json_msg_str then
module:log('error', 'Error broadcasting message room:%s', room.jid, error);
return;
end

room:broadcast_message(
st.message({ type = 'groupchat', from = occupant.nick })
:tag('json-message', {xmlns='http://jitsi.org/jitmeet'})
:text(json.encode(json_msg)):up());
:text(json_msg_str):up());
end
end

Expand Down
22 changes: 17 additions & 5 deletions resources/prosody-plugins/mod_muc_password_check.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local inspect = require "inspect";
local formdecode = require "util.http".formdecode;
local urlencode = require "util.http".urlencode;
local jid = require "util.jid";
local json = require "util.json";
local json = require 'cjson.safe';
local util = module:require "util";
local async_handler_wrapper = util.async_handler_wrapper;
local starts_with = util.starts_with;
Expand Down Expand Up @@ -106,9 +106,9 @@ function handle_validate_room_password (event)
return { status_code = 400; }
end

local params = json.decode(request.body);
local params, error = json.decode(request.body);
if not params then
module:log("warn", "Missing params");
module:log("warn", "Missing params error:%s", error);
return { status_code = 400; }
end

Expand All @@ -125,9 +125,15 @@ function handle_validate_room_password (event)
return { status_code = error_code; }
end

local json_msg_str, error_encode = json.encode({ valid = (room:get_password() == passcode) });
if not json_msg_str then
module:log('error', 'Cannot encode json room:%s error:%s', room.jid, error_encode);
return { status_code = 400; };
end

local PUT_response = {
headers = { content_type = "application/json"; };
body = json.encode({ valid = (room:get_password() == passcode) })
body = json_msg_str;
};

-- module:log("debug","Sending response for room password validate: %s", inspect(PUT_response));
Expand All @@ -150,11 +156,17 @@ function handle_get_room_password (event)
room_details["passcodeProtected"] = room:get_password() ~= nil;
room_details["lobbyEnabled"] = room._data ~= nil and room._data.lobbyroom ~= nil;

local json_msg_str, error = json.encode(room_details);
if not json_msg_str then
module:log('error', 'Cannot encode json room:%s error:%s', room.jid, error);
return { status_code = 400; };
end

local GET_response = {
headers = {
content_type = "application/json";
};
body = json.encode(room_details);
body = json_msg_str;
};
-- module:log("debug","Sending response for room password: %s", inspect(GET_response));

Expand Down
2 changes: 1 addition & 1 deletion resources/prosody-plugins/mod_muc_size.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

local jid = require "util.jid";
local it = require "util.iterators";
local json = require "util.json";
local json = require 'cjson.safe';
local iterators = require "util.iterators";
local array = require"util.array";

Expand Down
14 changes: 11 additions & 3 deletions resources/prosody-plugins/mod_polls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-- by keeping track of the state of polls in each room, and sending
-- that state to new participants when they join.

local json = require("util.json");
local json = require 'cjson.safe';
local st = require("util.stanza");
local jid = require "util.jid";
local util = module:require("util");
Expand All @@ -22,8 +22,11 @@ local function get_poll_message(stanza)
if json_data == nil then
return nil;
end
local data = json.decode(json_data);
local data, error = json.decode(json_data);
if not data or (data.type ~= "new-poll" and data.type ~= "answer-poll") then
if error then
module:log('error', 'Error decoding data error:%s', error);
end
return nil;
end
return data;
Expand Down Expand Up @@ -192,12 +195,17 @@ module:hook("muc-occupant-joined", function(event)
};
end

local json_msg_str, error = json.encode(data);
if not json_msg_str then
module:log('error', 'Error encoding data room:%s error:%s', room.jid, error);
end

local stanza = st.message({
from = room.jid,
to = event.occupant.jid
})
:tag("json-message", { xmlns = "http://jitsi.org/jitmeet" })
:text(json.encode(data))
:text(json_msg_str)
:up();
room:route_stanza(stanza);
end);
6 changes: 3 additions & 3 deletions resources/prosody-plugins/mod_reservations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@

local jid = require 'util.jid';
local http = require "net.http";
local json = require "util.json";
local json = require 'cjson.safe';
local st = require "util.stanza";
local timer = require 'util.timer';
local datetime = require 'util.datetime';
Expand Down Expand Up @@ -396,10 +396,10 @@ end
-- Ref: https://github.com/jitsi/jicofo/blob/master/doc/reservation.md
-- @return nil if invalid, or table with payload parsed from JSON response
function RoomReservation:parse_conference_response(response_body)
local data = json.decode(response_body);
local data, error = json.decode(response_body);

if data == nil then -- invalid JSON payload
module:log("error", "Invalid JSON response from API - %s", response_body);
module:log("error", "Invalid JSON response from API - %s error:%s", response_body, error);
return;
end

Expand Down
Loading
Loading