Best way of listening of listening to someone's presence on any room


#1

Hello,

What’s the preferred way of listening to all presence on all rooms? We want to basically create a hook to where we can act on someone’s presence.

-Mark


#2

The best place for this is custom lua module in prosody, something like: https://github.com/jitsi/jitsi-meet/blob/master/resources/prosody-plugins/mod_muc_call.lua#L56


#3

Awesome, thanks @damencho!


#4

So I tried it, and I can’t seem to find a way to know if the user left the room. Is this possible?


#5

If you are using prosody trunk you have events like:


#6

Hum, it doesn’t kept my line number, so here it is:

muc_module:hook("muc-room-created", room_created, -1);
muc_module:hook("muc-occupant-joined", occupant_joined, -1);
muc_module:hook("muc-occupant-pre-leave", occupant_leaving, -1);
muc_module:hook("muc-room-destroyed", room_destroyed, -1);

There is also muc-occupant-leave


#7

Thank you this works. The version of prosody that I have installed doesn’t have muc-occupant-leave, but the muc-occupant-pre-leave should be good enough.

The only thing is that when the user leaves, it doesn’t have the nick name or email in the stanza. This is fine, we’ll just have to do some lookup on the other side of the code.

Thanks!


#8

You can get the occupant object and its latest presence, maybe will have it. In the PR above I’m extracting the display name on leave.


#9

Thank you again, I was able to use the occupant.sessions table and look for name == "email" to get a unique id that we need.