我使用strophe.js库在浏览器中发送和接收XMPP消息,它能够正常工作,但仅适用于我已经在通讯录中的用户。
我需要将某个人(我已知其地址)添加到我的通讯录中,我该如何使用strophe.js实现呢?这对我很重要,因为Gmail拒绝向我未在通讯录中的人发送消息。我想获得订阅:双方均可接收和发送消息。
我需要将某个人(我已知其地址)添加到我的通讯录中,我该如何使用strophe.js实现呢?这对我很重要,因为Gmail拒绝向我未在通讯录中的人发送消息。我想获得订阅:双方均可接收和发送消息。
发送 <presence to="friend@example.com" type="subscribe"/>
:
conn.send($pres({ to: "friend@example.com", type: "subscribe" }));
当你的朋友接受请求时,他们也应该向你发送一个订阅,你可以通过设置一个类型为“subscribe”的Strophe处理程序来处理它们发送的出席信息:
function on_subscription_request(stanza)
{
if(stanza.getAttribute("type") == "subscribe" && is_friend(stanza.getAttribute("from")))
{
// Send a 'subscribed' notification back to accept the incoming
// subscription request
conn.send($pres({ to: "friend@example.com", type: "subscribed" }));
}
return true;
}
conn.addHandler(on_subscription_request, null, "presence", "subscribe");