要启用出席信息服务,需要创建一个“配置文件”对象。配置文件对象是通过 IRTCClientProvisioning::CreateProfile 方法创建的。要创建配置文件对象,客户端应用程序需要创建一个符合装置架构的 XML 字符串。XML 架构的属性包括:
装置设置 - 配置文件的唯一标识符。
用户设置 - 用户的 URI、领域和登录帐户信息
客户端设置 - 有关与通信链路无关的客户端应用程序信息。此信息是可选的。
提供商设置 - 有关 Internet 电话服务提供商 (ITSP) 的信息。
SIP 服务器设置 - 指定可用的 SIP 服务器、SIP 服务器角色和服务器支持的会话类型。
要在 SIP 服务器上注册用户,客户端需要创建一个 XML 配置文件字符串,指示 RTC 客户端 API 如何与 SIP 服务器进行通信。创建 XML 字符串后,即可调用 IRTCClientProvisioning::CreateProfile() 方法创建一个配置文件对象。下一步是调用 IRTCClientProvisioning::EnableProfile() 方法在 RTC 服务器上注册用户,并指定配置文件应该在该服务器上注册的会话类型。注册类型可以是:允许传入计算机到计算机的会话 (RTCRF_REGISTER_INVITE_SESSIONS)、允许传入即时消息会话 (RTCRF_REGISTER_MESSAGE_SESSIONS)、允许传入观察程序 (RTCRF_REGISTER_PRESENCE) 或允许所有的注册类型 (RTCRF_REGISTER_ALL)。设置 RTCRF_REGISTER_PRESENCE 或 RTCRF_REGISTER_ALL 将通知注册服务器:客户端接受 SIP SUBSCRIBE 方法。这将允许用户通知其他用户他们的出席状态更改、获取其联系人出席状态更改的通知以及将出席信息添加到观察程序列表的其他人。
观察程序对象在好友列表中提供了用户状态。观察程序可以查询 Presentity 的状态,并得到好友列表中的用户状态更改的通知。观察程序还使用户能够通过 Presentity 的状态中断或允许其他人加入。
示例代码说明了注册用户以及启用出席信息和好友列表的步骤。
HRESULT CAVDConfDlg::DoSIPLogin(BSTR bXMLObj) ... . // 获取 RTC 客户端装置接口 hr = m_pClient->QueryInterface( if (FAILED(hr)) // 从 XML 装置文档创建 RTC SAFE_FREE_STRING(bXMLObj); if (FAILED(hr)) // 启用 RTC 配置文件对象 SAFE_RELEASE(pProv); if (FAILED(hr)) // 启用出席信息 if (FAILED(hr)) return S_OK; |
启用配置文件后,还应启用出席信息以防传入的观察程序事件丢失。EnablePresence() 方法还演示了创建好友列表的方法。
HRESULT CAVDConfDlg::EnablePresence(BOOL bEnable) // 清理好友列表 // 获取 RTC 客户端出席信息接口 if (FAILED(hr)) // 获取出席信息存储区的位置 // 如果禁用出席信息,则将最新的 if (FAILED(hr)) // 启用出席信息 if (FAILED(hr)) // 设置启用标志 // 如果禁用出席信息,则清理 if (FAILED(hr)) while (pEnumBuddy->Next(1, &pBuddy, NULL) == S_OK) SAFE_RELEASE(pBuddy); SAFE_RELEASE(pEnumBuddy); // 清理观察程序 hr = pPresence->EnumerateWatchers(&pEnumWatcher); while (pEnumWatcher->Next(1, &pWatcher, NULL) == S_OK) SAFE_RELEASE(pWatcher); SAFE_RELEASE(pEnumWatcher); SAFE_RELEASE(pPresence); return S_OK; |
请注意 pPresence->EnablePresence() 函数的第二个参数,它需要一个 Variant 型的存储区来保留好友列表以及允许和禁止的观察程序列表。Variant 存储区可采用文件名 (BSTR)、DOMDocument 对象,或者支持 Istream、IsequentialStream 或 IpersistStream 的任意对象的形式。
在 RTC 服务器中注册后,应用程序接收 RTCE_REGISTRATION_STATE_CHANGE 事件,指示注册是完成还是失败。
出席信息服务可以在服务器注册您的配置文件之前启用。下图显示了注册前启用出席信息服务的方法。
这可以使用户在注册到服务器之前设置他们的状态。现在,用户可以注册到 SIP 服务器,而对观察程序可以显示为“离线”,并查看联系人状态。当用户要在不受干扰的情况下监视组的出席状态时,此功能非常有用。

图 3:注册前启用出席信息的步骤。
请注意,可以在设置出席状态后调用 CreateProfile() 方法。
下面是 XML 架构。
| < xml version="1.0" > <Schema name="ProvisioningSchema.xml" xmlns="urn:schemas-microsoft-com:xml-data" xmlns:dt="urn:schemas-microsoft-com:datatypes"> <comments>Schema Version MajorRevisionNumber = 1 MinorRevisionNumber = 0 </comments> <ElementType name="provision" model="closed"> <AttributeType name="key" required="yes" /> <attribute type="key" /> <AttributeType name="name" required="yes" /> <attribute type="name" /> <AttributeType name="expires" dt:type="dateTime.tz" /> <attribute type="expires" /> <element type="user" minOccurs="1" maxOccurs="1" /> <element type="sipsrv" minOccurs="1" maxOccurs="*" /> <element type="client" minOccurs="0" maxOccurs="1" /> <element type="provider" minOccurs="0" maxOccurs="1" /> </ElementType> <ElementType name="user" model="closed"> <AttributeType name="uri" required="yes" /> <attribute type="uri" /> <AttributeType name="account" required="no" /> <attribute type="account" /> <AttributeType name="name" required="no" /> <attribute type="name" /> <AttributeType name="password" required="no" /> <attribute type="password" /> <AttributeType name="realm" required="no" /> <attribute type="realm" /> </ElementType> <ElementType name="client" model="closed"> <AttributeType name="name" required="yes" /> <attribute type="name" /> <AttributeType name="banner" dt:type="bool" required="no" /> <attribute type="banner" /> <AttributeType name="updates" dt:type="bool" required="no" /> <attribute type="updates" /> <AttributeType name="minver" dt:type="fixed.14.4" required="no"/> <attribute type="minver" /> <AttributeType name="curver" dt:type="fixed.14.4" required="no"/> <attribute type="curver" /> <AttributeType name="updateuri" dt:type="uri" required="no" /> <attribute type="updateuri" /> <element type="data" minOccurs="0" maxOccurs="1" /> </ElementType> <ElementType name="data" model="open" /> <ElementType name="provider" model="closed" content="mixed"> <AttributeType name="name" /> <attribute type="name" /> <AttributeType name="homepage" dt:type="uri" required="no" /> <attribute type="homepage" /> <AttributeType name="helpdesk" dt:type="uri" required="no" /> <attribute type="helpdesk" /> <AttributeType name="personal" dt:type="uri" required="no" /> <attribute type="personal" /> <AttributeType name="calldisplay" dt:type="uri" required="no" /> <attribute type="calldisplay" /> <AttributeType name="idledisplay" dt:type="uri" required="no" /> <attribute type="idledisplay" /> <element type="data" /> </ElementType> <ElementType name="sipsrv" model="closed" content="mixed"> <AttributeType name="addr" required="yes" /> <attribute type="addr" /> <AttributeType name="protocol" dt:type="enumeration" dt:values="TCP UDP TLS" required="yes" /> <attribute type="protocol" /> <AttributeType name="auth" dt:type="enumeration" dt:values="basic digest" required="no" /> <attribute type="auth" /> <AttributeType name="role" dt:type="enumeration" dt:values="proxy registrar" required="yes" /> <attribute type="role" /> <element type="session" minOccurs="0" maxOccurs="*" /> </ElementType> <ElementType name="session" model="closed"> <AttributeType name="party" dt:type="enumeration" dt:values="first third" /> <attribute type="party" /> <AttributeType name="type" dt:type="enumeration" dt:values="pc2pc pc2ph ph2ph im" /> <attribute type="type" /> </ElementType> </Schema> |