XMPP_Protocol
查询服务器信息
用户通过查询服务器信息来查看服务器对特定某些功能的支持,比如:用户需要查询是否支持在多个终端同时发送消息,点击下面的查询语句,服务器返回<feature var=’urn:xmpp:carbons:2’> 节点则表明是支持此功能的。
<iq xmlns='jabber:client'
|
服务器返回:
|
订阅房间
在多用户聊天(MUC)中,通过将房间作为PubSub公开,用户通过订阅房间的节点事件来建立和房间的关联,即使这个用户不在房间里面。也就是说用户无需向房间发送状态即可接收消息。
注意:
- 如果按照标准的XMPP,用户需要发送presence状态来表明自己出席了某个房间,用户加入了房间之后才能收发消息 。但是有了订阅的概念用户只需要订阅房间即可。
- 用户订阅房间可支持的节点事件如下:
- urn:xmpp:mucsub:nodes:presence
- urn:xmpp:mucsub:nodes:messages
- urn:xmpp:mucsub:nodes:affiliations
- urn:xmpp:mucsub:nodes:subscribers
- urn:xmpp:mucsub:nodes:config
- urn:xmpp:mucsub:nodes:subject
- urn:xmpp:mucsub:nodes:system
<iq from='hag66@shakespeare.example' to='coven@muc.shakespeare.example' 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 from='coven@muc.shakespeare.example'
to='hag66@shakespeare.example' type='result' id='E6E10350-76CF-40C6-B91B-1EA08C332FC7'> <subscribe 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> |
查询房间信息
IQ查询:
|
服务器返回:
|
邀请订阅房间
服务器现已支持除主持人之外,普通订阅者也可以邀请别人订阅房间。
IQ查询:
注意:在<subscribe>节点属性意义如下:
- Xmlns:”urn:xmpp:mucsub:0” 固定的命名空间表明订阅房间
- Jid:被邀请订阅的用户的jid
- Nick:被邀请订阅的用户在房间的昵称;iOS目前填的是用户的jid前面部分
比如用户的jid是:13602439462@taobao.com ,则nick为:13602439462
<iq from='king@shakespeare.example' to='coven@muc.shakespeare.example' type='set' id='E6E10350-76CF-40C6-B91B-1EA08C332FC7'> <subscribe xmlns='urn:xmpp:mucsub:0' jid='hag66@shakespeare.example' 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查询:
<iq from='hag66@shakespeare.example' to='coven@muc.shakespeare.example' type='set' id='E6E10350-76CF-40C6-B91B-1EA08C332FC7'> <unsubscribe xmlns='urn:xmpp:mucsub:0' /> </iq> |
服务器返回:
<iq from='coven@muc.shakespeare.example' to='hag66@shakespeare.example' type='result' id='E6E10350-76CF-40C6-B91B-1EA08C332FC7' /> |
注意:如果是群主退群,需先通过上面的查询取消订阅,另外还要调用distory解散群。
以iOS为例:
<iq from='hag66@shakespeare.example' to='coven@muc.shakespeare.example' type='set' id='E6E10350-76CF-40C6-B91B-1EA08C332FC7'> <destory/> </iq> |
- 群主为其他成员取消订阅(踢人)
<iq from='king@shakespeare.example' to='coven@muc.shakespeare.example' type='set' id='E6E10350-76CF-40C6-B91B-1EA08C332FC7'> <unsubscribe xmlns='urn:xmpp:mucsub:0' jid='hag66@shakespeare.example'/> </iq>
|
获取订阅房间列表
用户查询自己订阅的房间列表
IQ查询:
注意:to 属性指定的格式为:
subdomain.domain比如:
Subdomain:conference
Domain:taobao.com
则to为:conference.com
<iq from='hag66@shakespeare.example' to='muc.shakespeare.example' type='get' id='E6E10350-76CF-40C6-B91B-1EA08C332FC7'> <subscriptions xmlns='urn:xmpp:mucsub:0' /> </iq> |
服务器返回:
<iq from='muc.shakespeare.example' to='hag66@shakespeare.example' type='result' id='E6E10350-76CF-40C6-B91B-1EA08C332FC7'> <subscriptions xmlns='urn:xmpp:mucsub:0'> <subscription jid='coven@muc.shakespeare.example'> <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'/> </subscription> <subscription jid='chat@muc.shakespeare.example'> <event node='urn:xmpp:mucsub:nodes:messages'/> </subscription> </subscriptions> </iq> |
获取订阅者列表
获取订阅者列表即获取房间成员。
IQ查询:
注意:直接将to属性指定为房间jid即可以查询房间成员列表。
<iq from='hag66@shakespeare.example' to='coven@muc.shakespeare.example' type='get' id='E6E10350-76CF-40C6-B91B-1EA08C332FC7'> <subscriptions xmlns='urn:xmpp:mucsub:0' /> </iq> |
服务器返回:
<iq from='coven@muc.shakespeare.example' to='hag66@shakespeare.example' type='result' id='E6E10350-76CF-40C6-B91B-1EA08C332FC7'> <subscriptions xmlns='urn:xmpp:mucsub:0'> <subscription jid='juliet@shakespeare.example'> <event node='urn:xmpp:mucsub:nodes:messages'/> <event node='urn:xmpp:mucsub:nodes:affiliations'/> </subscription> <subscription jid='romeo@shakespeare.example'> <event node='urn:xmpp:mucsub:nodes:messages'/> </subscription> </subscriptions> </iq> |
2.6.3.8 查询离线消息数量
IQ查询:
|
服务器返回:
|
离线消息收取
只需要发送一个prioryity 大于1的presence即可。
IQ查询:
|
启用carbons(消息副本)
在现实中,存在一个账号登录多个终端的情况,Carbons协议用于确保一个账号的所有设备都能获得所有对话的内容,以避免用户混淆。作为副本,在实现该协议的所有用户的客户端之间共享关于对话的当前状态的信息,确保信息在各种终端连续不间断。
客户端启用carbons协议只需要发送一个带<enable>节的协议即可。
IQ查询:
|
服务器返回:
|