p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Professional XMPP Programming with JavaScript and jQuery (http://p2p.wrox.com/forumdisplay.php?f=542)
-   -   problem getting the online presence list after attaching (http://p2p.wrox.com/showthread.php?t=80902)

anamaria September 13th, 2010 07:13 AM

problem getting the online presence list after attaching
 
Hello Jack,
I have been reading your book and used it in order to build a chat application similar to the one on facebook. First of all, I would like to thank you for having written this helpful and well documented book!
After having read the 12th chapter, I decided to also use "attach" in order to prevent the user from reentering his credentials when refreshing or visiting another page where the chat application is available. I saved the JID, SID and RID in cookies when the unload event occurred and then reread them when necessary and attaching to the old connection.
Everything worked just fine, but I experience a problem regarding the online presence list. When unloading, I do not send any presence stanza having the type "unavailable" because I do not want the other users to see that I go offline and come back online every time I do a page refresh. However, after attaching and requesting the roster again I can only see a list with all the contacts appearing offline (although some of them are for sure online). The problem is that although I send the initial presence information, when attaching the other contacts do not send their presence stanzas because in their view I am still online, as before attaching.
My question is if I can somehow request the other users to send their presence stanza, without actually announcing them that I go offline and then send again initial presence information that normally triggers them into sending me their presence stanza.
I tried to pause and resume the connection but the situation stays the same. I attach the code that I used when unloading the page and loading it again.
I would be really grateful for your answer, because this problem is bugging me for some while and I would really need to know if what I want is possible or not and unfortunately I was not able to find an answer anywhere else..



$(window).unload(function() {
connection.pause();
if( connection != null ){
set_cookie();
}else{

createCookie("cookieJid","",-1);
createCookie("cookieSid","",-1);
createCookie("cookieRid","",-1);

}
});




$(document).ready(function() {
var con = new Strophe.Connection("http://bosh.metajack.im:5280/xmpp-httpbind" );
var cookieJid = readCookie( "cookieJid" );
var cookieSid = readCookie( "cookieSid" );
var cookieRid = readCookie( "cookieRid" );


if( ( cookieSid != null ) && ( cookieSid != '') ){
con.attach( cookieJid, cookieSid, cookieRid , null );
}
else{
con=null;
}
if (con!=null){

connection = con;
triggerConnected();

}
});




triggerConnected: function(){

$("#login_dialog").html('');
$("#login_dialog").append("<ul style=\"overflow:auto\"></ul>");

var iq = $iq({type: 'get'}).c('query', {xmlns: 'jabber:iq:roster'});

connection.resume();
connection.sendIQ(iq, on_roster);


connection.addHandleron_message, null, "message", "chat");
}





on_roster : function (iq){


$(iq).find('item').each(function () {

//etc

});


connection.addHandler( on_presence, null, "presence");
connection.send(null);
connection.send($pres());

}

Thak you very much for your time!

anamaria September 22nd, 2010 03:47 PM

Hello,
Sorry for insisting but I am really interested in the response to this question. And until now I didn't find any answer so I have no idea how to continue..
I would be more than happy if you could help me..please! :)

metajack December 5th, 2010 01:24 PM

Quote:

Originally Posted by anamaria (Post 263191)
Everything worked just fine, but I experience a problem regarding the online presence list. When unloading, I do not send any presence stanza having the type "unavailable" because I do not want the other users to see that I go offline and come back online every time I do a page refresh. However, after attaching and requesting the roster again I can only see a list with all the contacts appearing offline (although some of them are for sure online).

Your application must preserve some amount of state about the connection. One of these bits of state is the JID, SID, and RID. Another is the presence status of contacts.

Quote:

My question is if I can somehow request the other users to send their presence stanza, without actually announcing them that I go offline and then send again initial presence information that normally triggers them into sending me their presence stanza.
You can send presence probes manually to everyone on your roster, but that is not really advisable. People may be changing pages a lot, and sending lots of duplicate probes is probably not going to scale well.

Use local storage to store critical application state on the client side or find some way to store this server side (AJAX, XMPP's private xml storage, etc).


All times are GMT -4. The time now is 05:50 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.