Search code examples
ejabberdejabberd-moduleejabberd-api

how to add occupants/users to a MUC room?


I have created a persistent MUC room using the ejabberd API "create_room_with_opts". I am now adding a user to the room by subscribing the user to the room using "subscribe_room" API with folowwing req and response.

Req:

{
  "user": "vishesh@dub/dummy",
  "nick": "vish",
  "room": "[email protected]",
  "nodes": "urn:xmpp:mucsub:nodes:messages,urn:xmpp:mucsub:nodes:affiliations,urn:xmpp:mucsub:nodes:subject,urn:xmpp:mucsub:nodes:presence"
}

Res:

[
    "urn:xmpp:mucsub:nodes:messages",
    "urn:xmpp:mucsub:nodes:affiliations",
    "urn:xmpp:mucsub:nodes:subject",
    "urn:xmpp:mucsub:nodes:presence"
]

But when I list the number of occupants it lists as 0. I used "get_room_occupants_number" API which had following req and res.

Request:

{
    "name": "roomdub",
    "service": "conference.dub"
}

Response:

{
    "occupants": 0
}

I am unable to understand why I don't see the user I added? Did I miss any step?


Solution

  • An account can be a room "subscriber", and receive notifications, and can also sends messages to the room. As described in https://docs.ejabberd.im/developer/xmpp-clients-bots/proposed-extensions/muc-sub/

    Alternatively (or simultaneously), the account can be a room "occupant", and can see other room occupants' presence, how they join and leave, receives messages, private messages and can also send them. As described in https://xmpp.org/extensions/xep-0045.html

    So, this sentence is wrong:

    I am now adding a user to the room by subscribing the user to the room

    You are not "adding" the user to the room, because after all that concept is not define in any of the protocols I mentioned. You are "subscribing" it to some room events. And doesn't make him an "occupant".