Participant Count in Jitsi room


#1

Hello,

Is it possible to add participant count in Jitsi room? If possible, how can I add? Please help


How to get call duration after each call?
#2

I think, on the client side, you can find members count using the following line :

this.APP.conference.membersCount


#3

For server side infos you can look at this

By adding this module you can request to prosody the participant’s count for a room


#4

I added the following functions in mod_muc_size.lua to get real-time conferences and participants count on the server side.

PS : The code is not very optimised but it could be useful

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

you get the result by sending an http request to “http://localhost:PROSODY_PORT/nbConfPart”
note that you must enable mod_muc_size module in prosody localhost virtualhost configuration file.


#5

i’m still using prosody 0.9.X. This code also returns usernames, roles, jids, jitsi video muted, audio muted

function handle_get_room (event)
	local params = parse(event.request.url.query);
	local room_name = params["room"];
	local domain_name = params["domain"];
	local room_address = room_name .. "@" .. "conference." .. domain_name;
	local room = get_room_from_jid(room_address);
	local participant_count = 0;
	local occupants_json = array();

	log("debug", "Querying room %s", tostring(room_address));

	if room then
		local occupants = room._occupants;
		if occupants then
			participant_count = 0;
			for jid, occupant in pairs(occupants) do
				participant_count = participant_count + 1;
				-- filter focus as we keep it as hidden participant
				if string.sub(jid,-string.len("/focus"))~="/focus" then
					for jid2, pres in pairs(occupant.sessions) do
						local nick = pres:get_child_text("nick", "http://jabber.org/protocol/nick") or "";
						-- local email = pres:get_child_text("email") or "";
						local role = occupant.role or "";
						local videomuted = pres:get_child_text("videomuted", "http://jitsi.org/jitmeet/video") or "";
						local audiomuted = pres:get_child_text("audiomuted", "http://jitsi.org/jitmeet/audio") or "";
						
						occupants_json:push({
							jid = tostring(jid),
							-- email = tostring(email),
							displayname = tostring(nick),
							role = tostring(role),
							videomuted = tostring(videomuted),
							audiomuted = tostring(audiomuted)
						});
					end
				end
			end
			
		end
		log("debug", "there are %s occupants in room", tostring(participant_count));
	else
		log("debug", "no such room exists");
	end

	if participant_count > 1 then
		participant_count = participant_count - 1;
	end

	local GET_response = {
		headers = {
			content_type = "application/json";
		};
		body = json.encode(occupants_json);
	};
	return GET_response;
end

#6

Hello @Arthur_TOUMASSIAN

I don’t know if you could help but I have difficulties in finding the prosody module that manages events such as room and participants creation, etc. For example when a user joins a room, I want to store his JID, room name and more other information in an external database. do you have any tips for that ?


#7

Hi @hkhait

I have the same needs.
This module may inspire you. Its hooks events you need. You just have to adapt handlers to do http requests to your stats api or directly write to DB. But as it needs prosody >= 0.10 i didn’t go further.
Please keep me informed if you manage to get something

https://hg.prosody.im/prosody-modules/file/c3a039972b74/mod_statsd/mod_statsd.lua


#8

Hello @Arthur_TOUMASSIAN,

Thanks for the link.
I tried to adapt handlers to get the needed information from events object but only resource-bind and resource-unbind handlers work. the other ones, such as muc-occupant-joined and muc-occupant-left (that are the most important events in this case) don’t do anything. Do you have any idea why ?

I found the following documentation about Prosody Events https://prosody.im/doc/developers/events, it seems that the only supported events by default are resource-bind and resource-unbind.


#9

Which version of prosody do you have? And mod_muc ? I was in the same case that you, i concluded that with my version of Prosody those events are not implemented.


#10

I have the same version of prosody as https://meet.jit.si which is Prosody trunk nightly build 747 (2017-02-19, 428d4abee723) and the mod_muc that comes with (attached below)

mod_muc.lua.txt (11.1 KB)


#11

I’m looking at the code of prosody trunk here https://hg.prosody.im/trunk/file/tip/plugins/muc/muc.lib.lua
I can find lines where events are fired
muc-occupant-joined
muc-occupant-left
… so theorically should be fired

Maybe its the way it listens the event : global events, module events …
I didn’t try yet, my last resort will be to patch muc.lib.lua to inject my code directly in it. I know… a very poor solution :stuck_out_tongue:


#12

This was the first thing that came to my mind too. Anyway, I’ll do my best and let you know :wink:


#13

Which version of prosody are you using? For sure those are available in prosody-trunk as we use that version, but I’m not sure about 0.10…


#14

I use Prosody trunk nightly build 747 (2017-02-19, 428d4abee723)
isn’t it outdated ?


#15

Yep, we use the same. Hum, I’m sure those were available, I will double check when I get to the PC.


#16

Ok, Thank you for your assistance.

EDIT :
I found the two events muc-occupant-left and muc-occupant-joined in /usr/lib/prosody/modules/muc/muc.lib.lua

I’m not Lua/Prosody expert but I tried to add the module below and it didn’t work :

-- jitsi-meet stats test
--
-- Author : Hamza KHAIT

local json = require "util.json";
local http = require "net.http";
local muc_size_url="http://localhost:5280/room";

-- Track users as they bind
module:hook("resource-bind", function(event)
	log("info", "TEST resource-bind");
end)

-- Track users as they unbind
module:hook("resource-unbind", function(event)
	log("info", "TEST resource-unbind");
end)

-- Track MUC occupants as they join/leave
module:hook("muc-occupant-joined", function(event)
	log("info", "muc-occupant-joined");
end)

module:hook("muc-occupant-left", function(event)
	log("info", "muc-occupant-left");
end)

when I join a room prosody log only displays “TEST resource-bind” and “TEST resource-unbind”
Something is missing ?


#17

Yep, those events are there in trunk. So there must be something with your module … Are you loading the module globally or under the muc component.

Component "conference.yourdomain" "muc"
.....
....
modules_enabled = { "jitsi-meet-stats-test" }

#18

IT WORKS !! :smiley:

I was loading the module globally, that’s why muc events didn’t work.

Thank you very much @damencho