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!
Last edited by anamaria; September 13th, 2010 at 07:30 AM..
|