Is x4m a little bit slow to load ? Method .isDown() for example...

Asked by R. Rigaud

Hello, I'm coding a basic Jabber client for x4m, so I read a lot of Hyperstruct wiki pages, and I test...

I found something weird, here is my code to connect and change Presence :

function setPresence()
{
 // Récupération du Statut (<show>)
 var Status = $("status").selectedItem.value;
 // Récupération du Mood (<status>)
 var Mood = $("mood").value;

 // Comme on ne sait pas si c'est le Status qui a changé, dans le doute, on affiche la nouvelle icône
 showStatusIcon(Status);

 // On MAJ la Présence sur Internet
 if (Status == 'available' && XMPP.isDown(account))
 {
  XMPP.up(account, function() { XMPP.send(account, <presence><status>{Mood}</status></presence>); });
        }
 else if (Status == 'unavailable' && XMPP.isUp(account))
  XMPP.down(account);
 else if (Status == "available")
  XMPP.send(account, <presence><status>{Mood}</status></presence>);
 else
  XMPP.send(account, <presence><show>{Status}</show><status>{Mood}</status></presence>);
}

This Code is launched on a Menulist Select Event.

Problem, the value of : XMPP.isDown(account)

I've got a button that displays this value... When my app starts, I click on it and it returns : false ! It should be true because I'm offline....
I click again : false, again... idem.

Until 5/6 seconds... and then when I click, it returns : True !

So, if I try to connect my account with my menulist before 5/6 seconds... There is no connection... probably because I don't enter in the good "if"...

And I'm also wondering : I thought that XMPP.up() was an obligation but When I test with my menulist to put : Away, DND, Away, DND... with XMPP.send(presence), I also connect because I appear in Gajim ! Is it normal ?

What do you think about it ? is these comportments normal ? If yes, how to proceed to wait for XMPP.isDown to get the right value ?
Is my algorithm good and in adequation with x4m or should I modify it ? After the connection problem, my code seems to work very well...

Thanks.

Question information

Language:
English Edit question
Status:
Solved
For:
SamePlace Edit question
Assignee:
No assignee Edit question
Solved by:
R. Rigaud
Solved:
Last query:
Last reply:
Revision history for this message
Massimiliano Mirra (bard-hyperstruct) said :
#1

Are you sure your account isn't configured to automatically connect on startup?

Revision history for this message
R. Rigaud (raph-rigaud) said :
#2

Hum... What do you mean ? What configuration ? Is there a server config, independant from the client-app ?

I mean, no I don't connect at start up in my app... My connection is just managed by the code I wrote, with a Menulist.
On load, I juste load xmpp in my JS file like this :

var loader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"].getService(Components.interfaces.mozIJSSubScriptLoader);
loader.loadSubScript("chrome://xmpp4moz/content/xmpp.js");

Nothing else at start up.

Revision history for this message
Massimiliano Mirra (bard-hyperstruct) said :
#3

In that case I don't know why you are getting that result. :-( When I first start Firefox and no XMPP account is connected, isDown(account) returns true as expected.

Revision history for this message
R. Rigaud (raph-rigaud) said :
#4

It's wired... I clearly must wait 6/7 seconds to get isDown(account) to return true...

Actually, if I'm fast to click on my test button, I've got "true", but the next second, I've got "false"... until 6/7 seconds later... And no code is running.

Well, it's not a big problem, I'll just make an Interface Initialization, to wait for the good value. After that, everything works well.