Getting request params in prosody

Hi,

is it possible to get request params in prosody, just like you get jwt token param in some plugins?

Kind regards,
Rok

Yes, if those are added to the bosh connection and passed through the webserver’s proxy. You cannot get parameters from the page as that does not reaches prosody.

How can I accomplish this? Where can I add params to the bosh connection?

Maybe here https://github.com/jitsi/jitsi-meet/blob/0598e7369b2dfac9c11637c3c356cf634466430f/connection.js#L90

1 Like

Thank you, I have made a build and it runs successfully.

How would I catch then this param in prosody?

I would like to catch it before user enters room, because based on this parameter I would give user moderator status or not.

Will answer to myself… it can be done with

function init_session(event)
	local session, request = event.session, event.request;
	local query = request.url.query;

	if query ~= nil then
        local params = formdecode(query);
        session.lala = query and params.lala or nil;
    end
end
module:hook_global("bosh-session", init_session);

But now I have another issue… how do I set all users as members at first place (so everyone who connects should be by default as a member, also the first one)?

I tried with _set_affiliation(room, true, jid, “member”, reason) but it does not work.

Replying to myself :slight_smile: … it can be done with

  1. changing connection.js in jitsi-meet in function
    let serviceUrl = connectionConfig.websocket || connectionConfig.bosh;
    let search = window.location.search;
    let params = new URLSearchParams(search);
    let token = params.get('token');
    if (token) {
        serviceUrl += `?room=${roomName}&token=${token}`;
    } else {
        serviceUrl += `?room=${roomName}`;
    }
  1. creating prosody plugin with something like
local formdecode = require "util.http".formdecode;
local log = module._log;

local function verify_user(session, stanza, room)
    local user_jid = stanza.attr.from;
    if session.token == "lala" then
        room:set_affiliation(true, user_jid, "owner");
    else
        room:set_affiliation(true, user_jid, nil);
    end
end


module:hook("muc-room-pre-create", function(event)
    local origin, room, stanza = event.origin, event.room, event.stanza;
    log("info", "pre create: %s %s", tostring(origin), tostring(stanza));
    return verify_user(origin, stanza, room);
end);

module:hook("muc-occupant-pre-join", function(event)
    local origin, room, stanza = event.origin, event.room, event.stanza;
    log("info", "pre join: %s %s", tostring(room), tostring(stanza));
    return verify_user(origin, stanza, room);
end);


-- Extract 'token' param from URL when session is created
function init_session(event)
    log("info", "init session");
    local session, request = event.session, event.request;
    local query = request.url.query;

    if query ~= nil then
        local params = formdecode(query);
        session.token = query and params.token or nil;
        -- previd is used together with https://modules.prosody.im/mod_smacks.html
        -- the param is used to find resumed session and re-use anonymous(random) user id
        -- (see get_username_from_token)
        session.previd = query and params.previd or nil;

        -- The room name and optional prefix from the bosh query
        session.jitsi_bosh_query_room = params.room;
        session.jitsi_bosh_query_prefix = params.prefix or "";
    end
end
module:hook_global("bosh-session", init_session);

You don’t need to set them by default to member, none (which is the default) is fine. The member affiliation make sense when you are using members only room, which you are not.

But won’t then the first one become the moderator?

To be moderator it should be owner. There is a logic in jicofo which sets the first to join as moderator, you can turn that off. Set org.jitsi.jicofo.DISABLE_AUTO_OWNER=true

Thx.