سؤال

يمكنني استخدام Strophe.js مكتبة لإرسال واستقبال رسائل XMPP في المتصفح.إنه يعمل بشكل جيد، ولكن فقط للمستخدمين لدي بالفعل في قائمة جهات الاتصال الخاصة بي - قائمة.

أحتاج إلى إضافة شخص (الذي أعرف عنوانه) إلى قائمتي.كيف يمكنني تحقيق هذا باستخدام stroph.js؟هذا مهم بالنسبة لي منذ أن رفض Gmail إرسال رسائل إلى أشخاص ليس لديهم في قائمة My Propter.أود الحصول على الاشتراك: كلاهما، لتكون قادرة على تلقي وإرسال الرسائل.

هل كانت مفيدة؟

المحلول

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");
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top