Get the list of rooms


#1

Hello all!

I apologize in advance if such a question already exists, but I searched for a long time and did not find. that something similar was here https://community.jitsi.org/t/jitsi-dev-get-number-of-current-rooms-and-participants-from-prosody/13266, but I’m not quite sure what I understood as the right way to do it

Is it possible to get the whole list of rooms with their names through Api or some other way (and how exactly)? I’m building an application in iframe that is installed on our server with token authentication


#2

Hello,

the following code lines return real-time conferences and participants count. you can also extract room names from prosody.full_sessions object.

You have to add this mod_muc_size prosody module. If you wanna test it you have to send an http request to :

http://localhost:5280/nbConfPart

PS : I didn’t have enough time to optimize the code so it’s a bit messy.

function tablelength(T)
        local hash = {}
        local res = {}

        for _,v in ipairs(T) do
           if (not hash[v]) then
               res[#res+1] = v
               hash[v] = true
           end
        end

        local count = 0
        for _ in pairs(res) do count = count + 1 end
        return count
end

function getNbConfPart() 
    local tab={};

    --conferences count (without eliminating duplicates )
    for key, value in pairs(prosody.full_sessions) do
            if tostring(value["username"]:lower()) ~= "focus" then
                    table.insert(tab,tostring(value["jitsi_meet_room"]:lower()));
            end
    end

    local nbPart = 0
    if it.count(it.keys(prosody.full_sessions))-1 >= 0 --participants count
            then nbPart= it.count(it.keys(prosody.full_sessions))-1
    end

    local nbConf = tablelength(tab) --conferences count
    if nbPart == 0
            then nbConf=0
    end

     --create result as json
    local result_json=array();
    result_json:push({
                    part= nbPart,
                    conf=tablelength(tab) -- eliminates count number of rooms
            });

    -- create json response 
    return json.encode(result_json);
end

function module.load()
    module:depends("http");
	module:provides("http", {
		default_path = "/";
		route = {
			["GET room-size"] = function (event) return wrap_async_run(event,handle_get_room_size) end;
			["GET sessions"] = function () return tostring(it.count(it.keys(prosody.full_sessions))); end;
			["GET room"] = function (event) return wrap_async_run(event,handle_get_room) end;
            ["GET nbConfPart"] = function (event) return wrap_async_run(event,getNbConfPart) end;
		};
	});
end

#3

Thank you hkhait! I will check this and write about status! :slightly_smiling_face:


#4

Good morning!
First of all thanks for the help!

I added your code to mod_muc_size. Then i reset the prosody and try to get information by doing a request to the address https://my_domain.com:5280/nbConfPart. Don’t work…

Main error: Connection timed out

in other words, I do not have access to https://my_domain.com:5280/, I tried from the browser, and send request from various clients with different methods (POST, GET) => ERR_CONNECTION_TIMED_OUT

I made a request using the get method and the post method. Can I need to specify additional data in the query? Or maybe additionally need to set prosody? Additionally, in the web server configuration, I saw the lines:

location /http-bind {
    proxy_pass      http://localhost:5280/http-bind;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header Host $http_host;
proxy_buffering off;
    tcp_nodelay on;
}

Maybe there is something here


#5

did you add “muc_size” module to your prosody virtual host ?
For instance, in my case, I only use stats internally that’s why I send request to localhost.

This is what my prosody localhost virtual host look like (/etc/prosody/conf.d/localhost.cfg.lua) :

-- Section for localhost
plugin_paths = { "/usr/share/jitsi-meet/prosody-plugins/" }

-- This allows clients to connect to localhost. No harm in it.
VirtualHost "localhost"
        -- enabled = false -- Remove this line to enable this host
        app_id=""
        app_secret=""
        authentication = "anonymous"
        modules_enabled = {
            "muc_size";
        }

if you want to make it available to other clients you have to create a nginx location, something like this :

location /nbConfPart {
    proxy_pass      http://localhost:5280/nbConfPart;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header Host $http_host;
}

#6

Many thanks for pointing the right way! I’ll try now


#7

I tried many variants! Still can not make it work. (and variant with localhost also does not work)

i want to make it available to other clients, because I make the system connectable via an external api and secured jwt tokens. And I need to make a request for an application in iframe for someone who has the right to create rooms, and for those who do not have this right, should be able to connect to already created and open rooms. To do this, i must make a request to the our server on which prosody is installed and get a match of open rooms, right?

I added to our virtual host where the application is installed jitsi-meet:

modules_enabled = {
        "bosh";
        "pubsub";
        "ping"; -- Enable mod_ping
        "muc_size"; -- I understand this is the key point 
    }

Then nginx config:

    location /get-info {
        proxy_pass  http://localhost:5280/nbConfPart;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $remote_addr;
}

then nginx and prosody restart. and in all requests to https://my_domain.com/get-info I get 404 error

how does the mechanism of access to these functions in this plug-in occur?


#8

I looked in the logs:

modulemanager error Error initializing module ‘muc_size’ on ‘localhost’: /usr/lib/prosody/util/startup.lua:136: module ‘net.url’ not found:No LuaRocks module found for net.url
…sr/share/jitsi-meet/prosody-plugins/mod_muc_size.lua:13: in main chunk


#9

You need to install net-url module

sudo luarocks install net-url


#10

Yes! Thank you, there is a result! But I do not get the names of the rooms, but it’s good that now it works

I just got it =>

[{"part":1,"conf":1}]

#11

Hi!

I just tested it. The script shows the total number of all participants in all rooms, in the part parameter. While the parameter conf is always equal to 1 if exists open rooms :slightly_smiling_face:


Good! I’ll try to rewrite the code for my needs!


#12

Happened! If someone else will help here the working code:

(/usr/share/jitsi-meet/prosody-plugins/mod_muc_size.lua)

function has_value(tab, val)
   for _, value in ipairs(tab) do
       if value == val then
           return true
       end
   end
   return false
end

function get_info_rooms()
   local innerValues = {};
   local keyRoom = "jitsi_bosh_query_room";
   for _, value in pairs(prosody.full_sessions) do
       if tostring(value["username"]:lower()) ~= "focus" then
           for innerKey, innerValue in pairs(value) do
               if innerKey == keyRoom and not has_value(innerValues, innerValue) then
                   table.insert(innerValues, innerValue)
               end
           end
       end
   end
return json.encode(innerValues);
end

In function function module.load() last line I wrote

["GET get-info-rooms"] = function (event) return wrap_async_run(event,get_info_rooms) end;

config nginx:

location /get-info-rooms {
    add_header Access-Control-Allow-Origin *;
    proxy_pass  http://localhost:5280/get-info-rooms;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $remote_addr;
}

Of course, I did all the steps described at the beginning of this topic! And many thanks to hkhait for the help and the suggested solution!


#13

PS : please note that you have to save muc_size module content before updating jitsi-meet-tokens package. the update will replace mod_muc_size.lua with a new one, so any modification will be lost.
The safest way is to create a separate file and include it in “modules_enabled” in prosody virtual host