Willy Lazuardi
Willy Lazuardi

Reputation: 1816

Strophe.js : How to use strophe.roster.js plugin

I've found the plugin for maintaining roster in strophe.js.

I found The plugin here, but there's not enough documentation provided.

This is the snippet of the code initialization function:

    init: function(conn)
        {
            ...

            var newCallback = function(status)
            {
                if (status == Strophe.Status.ATTACHED || status == Strophe.Status.CONNECTED)
                {
                    try
                    {
                        // Presence subscription
                        conn.addHandler(roster._onReceivePresence.bind(roster), null, 'presence', null, null, null);
                        conn.addHandler(roster._onReceiveIQ.bind(roster), Strophe.NS.ROSTER, 'iq', "set", null, null);
                        console.log(items);
                    }
                    catch (e)
                    {
                        Strophe.error(e);
                    }
                }
            };
            ...
            Strophe.addNamespace('ROSTER_VER', 'urn:xmpp:features:rosterver');
        },

My problem is I didn't get my roster, so the presence couldn't be updated.

The roster request supposed to be send on init function, but I couldn't find it.

Is anybody use this plugin?

How to get the roster by this plugin since the code is much different from the XMPP Professional Programming book.

Thanks in advance :)

Upvotes: 1

Views: 3472

Answers (2)

Ernesto
Ernesto

Reputation: 1592

I have done it this way. But I agree, all the pluggins are a struggle because there is very little documentation.

See if this helps anyone as this is very old:

    /**
 * Called when connection is fully established
 */
function onConnected() {
    // SEE http://xmpp.org/rfcs/rfc6121.html#roster-login
    // the order of setting initial presence and requesting the roster is important.
    // Get the roster for the first time (we might need to keep a copy on session storage)
    connection.roster.get(onGetRoster, 0);
    // pres is an strophe helper to represent a presence status. after connecting, we tell the server we are online.
    connection.send($pres());

}

/**
 * When user just connected and gets the roster information
 */
function onGetRoster(items) {
    if (!items || items.length == 0)
        return;
    console.log(items);
}

Upvotes: 1

Mark S
Mark S

Reputation: 869

Use conn.roster.get(rostercb);. Don't forget to set your presence.

Upvotes: 0

Related Questions