首页 > 解决方案 > ejabberd MUC-Sub 麻烦

问题描述

我正在运行具有以下 mod_muc 配置的 ejabberd (ver 18.3.0) 服务器:

  mod_muc:
    host: "conference.@HOST@"
    ...
    default_room_options:
      allow_subscription: true
      persistent: true
      mam: true

我正在尝试从各种客户端访问此服务器上的 muc 房间(带有 xmppframework 的 ios,带有 node-xmpp-client 的 js - 手动制作 xmpp 命令)。客户端能够接收消息 - 仅当我在连接后发送存在消息时。

但是,如果不发送出席信息,我不会在客户端收到任何消息(即使订阅成功)。我的理解是接收消息不需要存在消息(对于 mucsub)。

非常感谢任何帮助!


针对 Badlop 的回复的其他详细信息

我将客户端/服务器上的 xml 消息与您发布的消息进行了比较。继续您使用的 user1/user2 示例,我看到 user2 的订阅成功:

<iq xmlns="jabber:client" 
lang="en" 
to="rk3@localhost/abcd" 
from="tr21@conference.localhost" 
type="result" id="D7550060-E2AE-4369-878C-261A02BA48A2">
<subscribe xmlns="urn:xmpp:mucsub:0" nick="rk3n">
<event node="urn:xmpp:mucsub:nodes:messages"/>
<event node="urn:xmpp:mucsub:nodes:presence"/>
</subscribe>
</iq>

此外,来自 user2 的 muc 服务查询结果如下:

<iq xmlns="jabber:client" 
lang="en" 
to="rk3@localhost/abcd" 
from="conference.localhost" type="result" id="B28A237A-5D54-4AE2-821A-195272B05A88">
<subscriptions xmlns="urn:xmpp:mucsub:0">
<subscription jid="tr21@conference.localhost"/>
</subscriptions>
</iq>

但是,当我从 user1 发送群聊消息时:

<message 
from="rk1@localhost" to="tr21@conference.localhost"
type="groupchat">
<body> hi there777hi there778</body>
</message>

User2 仍未收到上述消息。

我在 ejabberd 服务器上打开了日志级别 5,可以看到服务器正在尝试将上述消息发送给 User2 (rk3)。但是,我在服务器上看到的这条消息的最后一条日志如下(我没有看到这条消息的任何“Send XML on stream”日志)。

2018-05-14 16:28:57.808 [debug] <0.646.0>@ejabberd_sm:do_route:656 processing message to bare JID:
#message{
 id = <<>>,type = normal,lang = <<>>,
 from =
  #jid{
   user = <<"tr21">>,server = <<"conference.localhost">>,resource = <<>>,
   luser = <<"tr21">>,lserver = <<"conference.localhost">>,lresource = <<>>},
 to =
  #jid{
   user = <<"rk3">>,server = <<"localhost">>,resource = <<>>,
   luser = <<"rk3">>,lserver = <<"localhost">>,lresource = <<>>},
 subject = [],body = [],thread = undefined,
 sub_els =
  [#ps_event{
    items =
     #ps_items{
      xmlns = <<>>,node = <<"urn:xmpp:mucsub:nodes:messages">>,
      items =
       [#ps_item{
         xmlns = <<>>,id = <<"15241958194312511749">>,
         sub_els =
          [#message{
            id = <<>>,type = groupchat,lang = <<"en">>,
            from =
             #jid{
              user = <<"tr21">>,server = <<"conference.localhost">>,
              resource = <<"rk1">>,luser = <<"tr21">>,
              lserver = <<"conference.localhost">>,lresource = <<"rk1">>},
            to =
             #jid{
              user = <<"rk3">>,server = <<"localhost">>,resource = <<>>,
              luser = <<"rk3">>,lserver = <<"localhost">>,lresource = <<>>},
            subject = [],
            body = [#text{lang = <<>>,data = <<"hi there777hi there778">>}],
            thread = undefined,
            sub_els =
             [#mam_archived{
               by =
                #jid{
                 user = <<"tr21">>,server = <<"conference.localhost">>,
                 resource = <<>>,luser = <<"tr21">>,
                 lserver = <<"conference.localhost">>,lresource = <<>>},
               id = <<"1526283878998040">>},
              #stanza_id{
               by =
                #jid{
                 user = <<"tr21">>,server = <<"conference.localhost">>,
                 resource = <<>>,luser = <<"tr21">>,
                 lserver = <<"conference.localhost">>,lresource = <<>>},
               id = <<"1526283878998040">>}],
            meta =
             #{ip => {172,17,0,1},
               mam_archived => true,stanza_id => 1526283878998040}}],
         node = <<>>,publisher = <<>>}],
      max_items = undefined,subid = <<>>,retract = undefined},
    purge = undefined,subscription = undefined,delete = undefined,
    create = undefined,configuration = undefined}],
 meta = #{stanza_id => 1526283879010097}}

我可能错过了一些非常基本的东西(wrt user / nick / muc room 等),但不知道是什么。

你能给我你用来创建user1/user2的步骤吗,在服务器上注册他们的昵称等(使用ejabberdctl)?

标签: ejabberdmultiuserchat

解决方案


我的理解是接收消息不需要存在消息(对于 mucsub)。

你是对的。有什么奇怪的。所以,我自己尝试过,并为您提供发送和接收的确切节,以便您进行比较,也许您会看到相关的内容。

您还可以尝试使用桌面 Jabber 客户端(如 Gajim、Psi 或 Tkabber)的 XML 控制台手动发送这些节,因此您不必为此测试编写代码。

我像你一样配置模块。然后 user1 加入 room2 (因此它被创建)。user2 订阅了房间:

<iq to='room2@conference.localhost'
    type='set'
    id='E6E10350-76CF-40C6-B91B-1EA08C332FC7'>
  <subscribe xmlns='urn:xmpp:mucsub:0'
             nick='mynick'
             password='roompassword'>
    <event node='urn:xmpp:mucsub:nodes:messages' />
    <event node='urn:xmpp:mucsub:nodes:affiliations' />
    <event node='urn:xmpp:mucsub:nodes:subject' />
    <event node='urn:xmpp:mucsub:nodes:config' />
  </subscribe>
</iq>

<iq xml:lang='es'
    to='user2@localhost/tka1'
    from='room2@conference.localhost'
    type='result'
    id='E6E10350-76CF-40C6-B91B-1EA08C332FC7'>
  <subscribe nick='mynick'
    xmlns='urn:xmpp:mucsub:0'>
    <event node='urn:xmpp:mucsub:nodes:messages'/>
    <event node='urn:xmpp:mucsub:nodes:affiliations'/>
    <event node='urn:xmpp:mucsub:nodes:subject'/>
    <event node='urn:xmpp:mucsub:nodes:config'/>
  </subscribe>
</iq>

紧接着,用户 1 向房间发送一条消息,用户 2 接收它,而没有发送任何出席信息节。

<message to='user2@localhost/tka1'
    from='room2@conference.localhost'>
  <event xmlns='http://jabber.org/protocol/pubsub#event'>
    <items node='urn:xmpp:mucsub:nodes:messages'>
      <item id='1625407893684208871'>
        <message xml:lang='es'
    to='user2@localhost'
    from='room2@conference.localhost/user1'
    type='groupchat'
    id='53:939858'
    xmlns='jabber:client'>
          <archived by='room2@conference.localhost'
    id='1526291787755131'
    xmlns='urn:xmpp:mam:tmp'/>
          <stanza-id by='room2@conference.localhost'
    id='1526291787755131'
    xmlns='urn:xmpp:sid:0'/>
          <body>hi allll</body>
        </message>
      </item>
    </items>
  </event>
</message>

可以肯定的是,user2 向 MUC 服务查询了他的订阅列表,MUC 返回了 room2,另一个他也订阅了:

<iq 
    to='conference.localhost'
    type='get'
    id='E6E10350-76CF-40C6-B91B-1EA08C332FC7'>
  <subscriptions xmlns='urn:xmpp:mucsub:0' />
</iq>

<iq xml:lang='es'
    to='user2@localhost/tka1'
    from='conference.localhost'
    type='result'
    id='E6E10350-76CF-40C6-B91B-1EA08C332FC7'>
  <subscriptions xmlns='urn:xmpp:mucsub:0'>
    <subscription jid='room2@conference.localhost'/>
    <subscription jid='room3@conference.localhost'/>
  </subscriptions>
</iq>

推荐阅读