欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

XMPP MUC多人聊天相关的一些stanza

程序员文章站 2022-06-26 18:12:47
...

 

 

 

 
创建room的stanza:
<presence
    from='crone1@shakespeare.lit/desktop'
    to='coven@chat.shakespeare.lit/firstwitch'>
  <xxmlns='http://jabber.org/protocol/muc'/>
</presence>
 
房间创建成功之后,client收到的stanza:
<presence
    from='coven@chat.shakespeare.lit/firstwitch'
    to='crone1@shakespeare.lit/desktop'>
  <xxmlns='http://jabber.org/protocol/muc#user'>
    <itemaffiliation='owner'
          role='moderator'/>
    <statuscode='110'/>
    <statuscode='201'/>
  </x>
</presence>
 
创建成功之后对房间进行配置的stanza(根据自己需求提交响应的参数,下面的例子是配置room名称和members only):
一个set类型的iq,query里面的x元素的type为submit,然后里面的field为相关的配置项
<iqfrom='crone1@shakespeare.lit/desktop'
    id='create2'
    to='coven@chat.shakespeare.lit'
    type='set'>
  <queryxmlns='http://jabber.org/protocol/muc#owner'>
    <xxmlns='jabber:x:data'type='submit'>
      <fieldvar='FORM_TYPE'>
        <value>http://jabber.org/protocol/muc#roomconfig</value>
      </field>
      <fieldvar='muc#roomconfig_roomname'>
        <value>A Dark Cave</value>
      </field>
      <fieldvar='muc#roomconfig_membersonly'>
        <value>1</value>
      </field>
    </x>
  </query>
</iq>
 
如果配置了room是members only,然后想要往该房间添加允许进入的member,使用下面的stanza:
一个set类型的iq,query里面的item元素表示要添加的member,可以添加多个item,即多个member,指定query的affiliation属性member即可
<iqfrom='crone1@shakespeare.lit/desktop'
    id='member4'
    to='coven@chat.shakespeare.lit'
    type='set'>
  <queryxmlns='http://jabber.org/protocol/muc#admin'>
    <itemaffiliation='none'
          jid='hag66@shakespeare.lit'/>
    <itemaffiliation='member'
          jid='hecate@shakespeare.lit'/>
  </query>
</iq>
 
如果想要禁言有个用户,可以通过下面的stanza(The <reason/> element is OPTIONAL):
<iqfrom='crone1@shakespeare.lit/desktop'
    id='voice2'
    to='coven@chat.shakespeare.lit'
    type='set'>
  <queryxmlns='http://jabber.org/protocol/muc#admin'>
    <itemnick='thirdwitch'
          role='visitor'>
      <reason>Not so worthy after all!</reason>
    </item>
  </query>
</iq>
离开房间:
<presence
    from='hag66@shakespeare.lit/pda'
    to='coven@chat.shakespeare.lit/thirdwitch'
    type='unavailable'/>
相关标签: xmpp muc stanza