Custom module for logging joining and leaving

Hi to all!
I want to develop a custom module for jitsi for logging to an external database the joining and the leaving of my users.

This is the simple code that I have writed.
It not work :frowning: what is wrong in my code?

local is_healthcheck_room = module:require "util".is_healthcheck_room;

local muc_component_host = module:get_option_string("muc_component");
if muc_component_host == nil then
    log("error", "No muc_component specified. No muc to operate on!");
    return;
end

module:log("info", "Hello from MyModule prosody module!");

function occupant_joined(event)
    module:log("info", "occupant_joined");
end

function occupant_leaving(event)
    module:log("info", "occupant_leaving");
end

function process_host(host)
    if host == muc_component_host then -- the conference muc component
        module:log("info","Hook to muc events on %s", host);

        local muc_module = module:context(host);
        muc_module:hook("muc-occupant-joined", occupant_joined, -1);
        muc_module:hook("muc-occupant-pre-leave", occupant_leaving, -1);
    end
end

if prosody.hosts[muc_component_host] == nil then
    module:log("info","No muc component found, will listen for it: %s", muc_component_host);
    prosody.events.add_handler("host-activated", process_host);
else
    process_host(muc_component_host);
end

You can just do:

module:hook("muc-occupant-joined", occupant_joined, -1);
module:hook("muc-occupant-pre-leave", occupant_leaving, -1);

and make sure you load your module under the main muc component.

The waiting with process_host is when you load that module under the main virtualhost.

How I can be sure of this?

Now I am using the docker version.
I have added:

Component "mymodule.meet.jitsi" "mymodule_component"
    muc_component = "muc.meet.jitsi"

and under VirtualHost:

VirtualHost "meet.jitsi"
.
.
    modules_enabled = {
        "bosh";
        
        "websocket";
        "smacks"; -- XEP-0198: Stream Management
        
        "pubsub";
        "ping";
        "speakerstats";
        "conference_duration";
.
.
        **"mymodule";**
    }
.
.
    speakerstats_component = "speakerstats.meet.jitsi"
    **mymodule_component = "mymodule.meet.jitsi"**
.
.
    c2s_require_encryption = false

under ~/jitsi-meet-cfg/prosody/config/conf.d/jitsi-meet.cfg.lua

it’s enought?

This is wrong.

Not here.

Add it here:

And do it like:

function occupant_joined(event)
    module:log("info", "occupant_joined");
end

function occupant_leaving(event)
    module:log("info", "occupant_leaving");
end

module:hook("muc-occupant-joined", occupant_joined, -1);
module:hook("muc-occupant-pre-leave", occupant_leaving, -1);

With this configuration I don’t see at startup in the console of the prosody container:

Hello from MyModule prosody module!

And I don’t see also occupant_joined and occupant_leaving when an user join or leave.
It doesn’t seem to load at all :frowning:

EDIT 1: I checked in the files ~/jitsi-meet-cfg/prosody/config/conf.d/jitsi-meet.cfg.lua and I see correctly the name of my module under muc component.
EDIT 2: I don’t see errors in the console.

You may use an already existing event_sync module and send data to your API which will insert it into a database.

It seems a good idea!
I have developed the needed APIs and I tried this module.

I have followed the instructions in the readme file:

  • downloaded the module and placed it in the right folder
  • added the component in prosody config:
Component "event_sync.meet.jitsi" "event_sync_component"
    muc_component = "conference.meet.jitsi"
    breakout_component = "breakout.meet.mydomain.com"
    api_prefix = "https://myurlapy.app/api/v1/"
    api_headers = {
         ["Authorization"] = "Token mytoken";
    }
    api_timeout = 10
    api_retry_count = 2
    api_retry_delay = 1
    include_speaker_stats = true
  • restarted my container

Do I need to do other? It seems not to work :smiling_face_with_tear:

EDIT 1: fixed first issue, in docker jitsi the muc is: muc.meet.jitsi not conference.meet.jitsi
Now I see the events in prosody console:

prosody_1  | event_sync.meet.jitsi:event_sync_component                   info  Start tracking occupants for endlessrepeatsstartout@muc.meet.jitsi
prosody_1  | event_sync.meet.jitsi:event_sync_component                   info  New occupant - {"occupant_jid":"f2dd9zkrbbvnwlq_kty-j7ba@meet.jitsi/NO83jqXMg35a","joined_at":1669981819}
prosody_1  | event_sync.meet.jitsi:event_sync_component                   info  Room destroyed - endlessrepeatsstartout@muc.meet.jitsi

but I don’t see in my database the rows. the API is working, I am sure! I tested it with postman.

EDIT 2: found the final issue:

api_prefix = "https://myurlapy.app/api/v1"

api_prefix don’t need the final / now it works great!!