一 Presence对象介绍
与IQ一样,Presence也是继承自XMPP的基类Packet信息包,Presence主要有两个用途:1)告诉服务器所有客户端当前所处的状态,2)发出添加/删除好友请求;每个Presence信息包都有一个类型属性Presence.Type,如下:
- available: 表示处于在线状态
- unavailable: 表示处于离线状态
- subscribe: 表示发出添加好友的申请
- unsubscribe: 表示发出删除好友的申请
- unsubscribed: 表示拒绝添加对方为好友
- error: 表示presence信息报中包含了一个错误消息。
除了类型信息外,Presence还包含其他一些可选的属性:
- Status: 用于表示用户状态的自定义文本,例如:外出吃饭
- Priority: 一个表示发送者资源优先级的非负数(我尚未搞明白什么是发送者资源)
- Mode: 表示五种状态之一:在线(默认)、聊天、离开、xa (extended away)、请勿打扰
Represents XMPP presence packets. Every presence packet has a type, which is one of the following values:
available
-- (Default) indicates the user is available to receive messages.unavailable
-- the user is unavailable to receive messages.subscribe
-- request subscription to recipient's presence.subscribed
-- grant subscription to sender's presence.unsubscribe
-- request removal of subscription to sender's presence.unsubscribed
-- grant removal of subscription to sender's presence.error
-- the presence packet contains an error message.
A number of attributes are optional:
- Status -- free-form text describing a user's presence (i.e., gone to lunch).
- Priority -- non-negative numerical priority of a sender's resource. The highest resource priority is the default recipient of packets not addressed to a particular resource.
- Mode -- one of five presence modes:
available
(the default),chat
,away
,xa
(extended away), anddnd
(do not disturb).