我通过扩展 AbstractComponent 类构建了一个基于 Whack 库的外部 openfire 组件。我希望客户订阅我的组件并在组件上线和下线时接收到状态通知。所以我的问题是我们如何处理基于 AbstractComponent 的外部组件的存在和存在订阅?
目前我可以通过使用 handlePresence() 方法来响应出席请求,但是我应该如何将客户端添加到组件名册(外部组件是否首先允许名册)?
@Override
protected void handlePresence(Presence presence){
if (presence.getType() == Presence.Type.subscribe){
System.out.println("The component has received Subscribtion request.");
Presence original = presence;
Presence response = new Presence();
//Swap the sender/recipient fields
response.setTo(original.getFrom());
response.setFrom(original.getTo());
//Convert the text to upper case
response.setType(Presence.Type.subscribed);
send(response);
}
}