You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用ejabberd API添加MUC成员后,成员数显示为0的问题咨询

Why get_room_occupants_number Returns 0 After Subscribing Users via subscribe_room

Hey there! Let's clear up the confusion here—this behavior is actually expected, and it comes down to a key distinction between MUC-Sub subscriptions and room occupants in ejabberd.

1. The Core Difference: Subscriptions vs. Occupants

When you use the subscribe_room API, you're setting up a MUC-Sub subscription for the user. This lets them receive updates from the room (like new messages, affiliation changes, or subject updates) without needing to be actively connected or joined to the room.

However, an "occupant" is defined as a user who is currently online and has explicitly joined the room via an XMPP MUC join request. Subscribing doesn't automatically make a user an occupant—these are two separate concepts entirely.

2. What You're Missing: Actual Room Joining

To have users count towards the occupants number returned by get_room_occupants_number, you need to ensure the user actively joins the room. Here's how to do this:

  • Via XMPP Client: Have the user's client send a MUC join stanza to the room (e.g., a presence stanza directed to roomdub@conference.dub/vish).
  • Via ejabberd API: If you need to trigger this server-side, you can use the send_stanza API to simulate a join request. For example:
    {
      "from": "vishesh@dub/dummy",
      "to": "roomdub@conference.dub/vish",
      "stanza": "<presence/>"
    }
    

3. Verify Subscriptions (Instead of Occupants)

If you want to confirm that your subscribe_room calls worked correctly, use the get_room_subscribers API instead. This will return the list of users who have subscribed to the room's updates:

  • Request:
    { "room": "roomdub@conference.dub" }
    
  • Expected Response:
    You should see vishesh@dub/dummy listed here, confirming the subscription was successful.

4. Quick Room Configuration Check

Double-check your room's configuration to rule out any edge cases:

  • Ensure the room is marked as persistent (you already did this, which is good!).
  • If the room is set to members_only, users need to have an affiliation (like member) before they can join. You can set affiliations using the set_room_affiliation API if needed.

Summary

The get_room_occupants_number metric only counts users who are actively joined and online in the room. Your subscriptions are working (as confirmed by the subscribe_room response), but those users aren't counted as occupants until they join the room.

内容的提问来源于stack exchange,提问作者Vishesh Madhusudhana

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 07:48:13