Skip to content


Subversion checkout URL

You can clone with
Download ZIP


While reload page not get roster presence? #28

nishant opened this Issue · 6 comments

3 participants



While Login , i can get Presence of all rosters users. //login time

However i reload my page i can not get rosters presence, // that time connection resume

function handlePresence(aJSJaCPacket)

@sstrigler has become available
@cstar has become available......

Please help me how to get all roster users presence , Like available or offline or away etc...



I have the same issue. When connecting, the roster comes back with presence. When resuming, the roster comes back but without presence.

I'm thinking of storing the roster in local storage on each page unload and bringing it back up when a resume happens...


Sorry but this won't work as you expect. That's because you're not doing a new login upon reconnecting. Thus you have to store the state of the roster on your own and restore it after resuming. Local storage might indeed be an option to handle this.

@sstrigler sstrigler closed this

Unfortunately, there is one severe issue here, even when storing the roster in local storage for page transitions.

When adding a user to the roster after resuming, you will not receive the new user's presence information, even if they are online.


Here is the code, basically getting a subscription, gathering all groups the user is going to be in and already in, then sending off IQ msg:

function addUserToGroup(xid, nickname, subscription, groups) {
// subscribe to user
sendSubscribe(xid, 'subscribe');

// setup roster, send IQ msg to change groups for this contact
var iq = new JSJaCIQ();
var query = iq.setQuery('jabber:iq:roster');
var item = query.appendChild(iq.buildNode('item', { 'xmlns': 'jabber:iq:roster', 'jid': xid }));

if (subscription)
    item.setAttribute('subscription', subscription);

if (nickname)
    item.setAttribute('name', nickname);

// check if groups are in an array, if not, make it one
var g = new Array();
if (groups.constructor.toString().indexOf("Array") != -1) {
    g = groups;
} else {

// append all current groups this user is already in to the groups array
var existing = listGroupsForUser(xid);
for (i = 0; i < existing.length; i++) {
    if (jQuery.inArray(existing[i], g) == -1) {

// loop all groups and add them to IQ msg
if (g && g.length) {
    for (i in g) {
        item.appendChild(iq.buildNode('group', { 'xmlns': 'jabber:iq:roster' }, g[i]));



function sendSubscribe(to, type) {
sendPresence(to, type, '', status);

function sendPresence(to, type, show, status, checksum, limit_history, password, handle) {
if (this.con) {
var priority = '100';
if (show == 'available') show = '';
if (type == 'available') type = '';
if (!checksum || (checksum == 'none')) checksum = '';

    // New presence
    var presence = new JSJaCPresence();

    // Presence headers
    if (to) presence.setTo(to);
    if (type) presence.setType(type);
    if (show) presence.setShow(show);
    if (status) presence.setStatus(status);



function listGroupsForUser(xid) {
for (i = 0; i < roster.length; i++) {
if (roster[i].xid == xid) {
return roster[i].groups;

return new Array();


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.