strophe.js를 사용하여 승인 요청 (명단에 추가)
-
14-11-2019 - |
문제
나는 브라우저에서 XMPP 메시지를 보내고받을 수있는 Strophe.js 라이브러리를 사용합니다.그것은 잘 작동하지만, 나는 이미 나의 연락처 목록에 이미 가지고있는 사용자만이 있습니다.
누군가 (내가 알고있는 주소)를 내 명단에 추가해야합니다.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