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

 
创建room的stanza:
<presence
    from = '[email protected]/desktop'
    to = '[email protected]/firstwitch' >
  <x xmlns = 'http://jabber.org/protocol/muc' />
</presence>
 
房间创建成功之后,client收到的stanza:
<presence
    from = '[email protected]/firstwitch'
    to = '[email protected]/desktop' >
  <x xmlns = 'http://jabber.org/protocol/muc#user' >
    <item affiliation = 'owner'
          role = 'moderator' />
    <status code = '110' />
    <status code = '201' />
  </x>
</presence>
 
创建成功之后对房间进行配置的stanza(根据自己需求提交响应的参数,下面的例子是配置room名称和members only):
一个set类型的iq,query里面的x元素的type为submit,然后里面的field为相关的配置项
<iq from = '[email protected]/desktop'
    id = 'create2'
    to = '[email protected]'
    type = 'set' >
  <query xmlns = 'http://jabber.org/protocol/muc#owner' >
    <x xmlns = 'jabber:x:data' type = 'submit' >
      <field var = 'FORM_TYPE' >
        <value> http://jabber.org/protocol/muc#roomconfig </value>
      </field>
      <field var = 'muc#roomconfig_roomname' >
        <value> A Dark Cave </value>
      </field>
      <field var = '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即可
<iq from = '[email protected]/desktop'
    id = 'member4'
    to = '[email protected]'
    type = 'set' >
  <query xmlns = 'http://jabber.org/protocol/muc#admin' >
    <item affiliation = 'none'
          jid = '[email protected]' />
    <item affiliation = 'member'
          jid = '[email protected]' />
  </query>
</iq>
 
如果想要禁言有个用户,可以通过下面的stanza( The <reason/> element is OPTIONAL ):
<iq from = '[email protected]/desktop'
    id = 'voice2'
    to = '[email protected]'
    type = 'set' >
  <query xmlns = 'http://jabber.org/protocol/muc#admin' >
    <item nick = 'thirdwitch'
          role = 'visitor' >
      <reason> Not so worthy after all! </reason>
    </item>
  </query>
</iq>
离开房间:
<presence
    from='[email protected]/pda'
    to='[email protected]/thirdwitch'
    type='unavailable'/>

猜你喜欢

转载自dreamoftch.iteye.com/blog/2307914