Get the list of rooms

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!

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

Hello,

I don’t get this to work.

Let me tell you what I did and maybe you find an error.

1 - Create the module

nano /usr/lib/prosody/modules/mod_muc_size.lua

Add the code:

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;
            ["GET get-info-rooms"] = function (event) return wrap_async_run(event,get_info_rooms) end;
        };
    });
end

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

2 - Configure nGinx

nano/etc/nginx/sites-enabled/vc1.mydomain.conf

Add:

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

3 - Enable the module in Prosody

nano /etc/prosody/conf.d/vc1.mydomain.cfg.lua

In modules-enabled add

"muc_size";

4 - Install necessary packets

apt install luarocks

luarocks install net-url

Did I miss something???

Does the fact that I get redirected to https affects this?

what did you get in prosody log file ? /var/log/prosody/prosody.log

If I go to https://vc1.mydomain/get-info-rooms I get a 502 Bad Gateway error and /var/log/prosody/prosody.log shows nothing

Hum it’s Nginx error, did you restart nginx and prosody after the modification ?

Yes, I restarted the whole server. Several times

what do you get when you type http://vc1.mydomain:5280/get-info-rooms in your browser ?

This site can’t be reached

vc1.mydomain refused to connect.

Try:

ERR_CONNECTION_REFUSED

the server is listening on port 5280 and the port is forwarded

I think you have to enable the module for localhost in /etc/prosody/conf.d/localhost.cfg.lua
and replace the line (in nginx)

with
proxy_pass http://localhost:5280/get-info-rooms;

that didn’t work :frowning: and I think proxy_pass is a web server parameter. Isn’t it?

Yes it is.

What is the content of your file /etc/prosody/conf.d/localhost.cfg.lua ?

Only this in that file

-- Section for localhost

-- This allows clients to connect to localhost. No harm in it.
VirtualHost "localhost"

it should be like this

-- Section for localhost
-- 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";
        }

Still doesn’t work

in my nginx file I have:

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;
}

And in /etc/prosody/conf.d/localhost.cfg.lua I have now:

-- Section for localhost
-- 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";
        }

This doesn’t work anymore. First, with simple jitsi installation plugin folder is not installed.
Second, when I cloned jitsi and unpacked plugin folder to /usr/lib/prosody/modules/
and then followed the tutorial, prosody wasn’t able to register plugin correctly throwing various errors that this or that library was missing. I was patiently installing them, untill I hit basexx which required luajwtjitsi, which required luacrypto, which required to be built on a server wich failed. This is so sad such a powerfull system requires so much effort for simple task to get all active rooms & participants.

I have same problem. Did you find a solution?

No, I haven’t. Didn’t try hard though, has another projects to wok on. If you find it, please share!

I am almost done with a solution. I don’t know how to solve this error. “no field package.preload[‘util.async’]”.