Strophe.jsを使用して承認要求(名簿に追加)
-
14-11-2019 - |
質問
strophe.js ライブラリを使用して、ブラウザでXMPPメッセージを送受信します。それはうまく機能しますが、私がすでに私の連絡先リストで持っているユーザーだけです - 名簿。
私は自分の名簿に誰かを追加する必要があります。Strophe.jsを使ってこれを達成するにはどうすればよいですか?Gmailが私の名簿に持っていない人々へのメッセージの送信を拒否して以来、これは私にとって重要です。購読を取得したいのですが、メッセージを送受信できるようにしたいのですが。
解決
Send <presence to="friend@example.com" type="subscribe"/>
:
conn.send($pres({ to: "friend@example.com", type: "subscribe" }));
When your friend accepts, they should send a subscribe to you also, which you can handle by setting a Strophe handler for incoming presence with type "subscribe":
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");
所属していません StackOverflow