我使用strophe.js库在浏览器中发送和接收XMPP消息。它工作正常,但仅适用于我的联系人列表中已经存在的用户-名册。
我需要将某个人(我知道其地址)添加到我的名册中。如何使用strophe.js做到这一点?这对我来说很重要,因为gmail拒绝将邮件发送给我名册上没有的人。我想要订阅:两者都可以接收和发送消息。
最佳答案
发送<presence to="friend@example.com" type="subscribe"/>
:
conn.send($pres({ to: "friend@example.com", type: "subscribe" }));
当您的 friend 接受时,他们也应该向您发送订阅,您可以通过将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");
关于xmpp - 使用strophe.js的授权请求(添加到名册中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9505949/