[mq]: xmpp-reconnect

This commit is contained in:
Dietrich Ayala 2008-06-04 17:00:02 -07:00
parent 49101addf2
commit 8ec3277ff2
5 changed files with 17 additions and 22 deletions

View File

@ -1,6 +1,8 @@
About the XMPP module
Here is sample code demonstrating how client code can use the XMPP module. It assumes that a Jabber server is running on localhost on port 5280.
Here is sample code demonstrating how client code can use the XMPP module.
It assumes that a Jabber server capable of HTTP-Polling is running on localhost
on port 5280.
Components.utils.import( "resource://weave/xmpp/xmppClient.js" );
@ -66,7 +68,6 @@ The ejabberd process is started simply by running:
ejabberd/bin/ejabberdctl start
Outstanding Issues -- bugs and things to do.
* The test above is failing with a timeout. How to debug this? Let's start
@ -122,4 +123,3 @@ Outstanding Issues -- bugs and things to do.
(Everything seems to be working OK with useKeys turned off, but that's less
secure.)

View File

@ -314,7 +314,7 @@ HTTPPollingTransport.prototype = {
},
setCallbackObject: function( callbackObject ) {
this._callbackObject = callbackObject;
this._callbackObject = callbackObject;
},
notify: function( timer ) {
@ -332,6 +332,9 @@ HTTPPollingTransport.prototype = {
},
connect: function() {
// In case this is a reconnect, make sure to re-initialize.
this._init(this._serverUrl, this._useKeys, this._interval);
/* Set up a timer to poll the server periodically. */
// TODO doPost isn't reentrant; don't try to doPost if there's

View File

@ -7,6 +7,9 @@ const EXPORTED_SYMBOLS = ['XmppClient', 'HTTPPollingTransport', 'PlainAuthentica
// http://developer.mozilla.org/en/docs/xpcshell
// http://developer.mozilla.org/en/docs/Writing_xpcshell-based_unit_tests
// IM level protocol stuff: presence announcements, conversations, etc.
// ftp://ftp.isi.edu/in-notes/rfc3921.txt
var Cc = Components.classes;
var Ci = Components.interfaces;
var Cu = Components.utils;
@ -419,15 +422,9 @@ XmppClient.prototype = {
},
waitForDisconnect: function() {
LOG("waitForDisconnect(): starting");
var thread = this._threadManager.currentThread;
while ( this._connectionStatus == this.CONNECTED ) {
thread.processNextEvent( true );
}
}
};
// IM level protocol stuff: presence announcements, conversations, etc.
// ftp://ftp.isi.edu/in-notes/rfc3921.txt

View File

@ -6,10 +6,8 @@ function LOG(aMsg) {
dump("TEST_XMPP: " + aMsg + "\n");
}
var serverUrl = "http://127.0.0.1:5280/http-poll";
var jabberDomain = Cc["@mozilla.org/network/dns-service;1"].
getService(Ci.nsIDNSService).myHostName;
LOG("DOMAIN: " + jabberDomain);
var serverUrl = "http://localhost:5280/http-poll";
var jabberDomain = "localhost";
var timer = Cc["@mozilla.org/timer;1"].createInstance( Ci.nsITimer );
var threadManager = Cc["@mozilla.org/thread-manager;1"].getService();
@ -19,12 +17,10 @@ function run_test() {
return;
/* First, just see if we can connect: */
var transport = new HTTPPollingTransport( serverUrl,
false,
4000 );
var transport = new HTTPPollingTransport(serverUrl, false, 4000);
var auth = new PlainAuthenticator();
var alice = new XmppClient("alice", jabberDomain, "iamalice",
transport, auth);
transport, auth);
// test connection
LOG("connecting");
@ -39,7 +35,6 @@ function run_test() {
do_check_eq( alice._connectionStatus, alice.NOT_CONNECTED);
LOG("disconnected");
/*
// test re-connection
LOG("reconnecting");
alice.connect( jabberDomain );
@ -48,6 +43,7 @@ function run_test() {
do_check_eq( alice._connectionStatus, alice.CONNECTED);
alice.disconnect();
/*
// test connection failure
alice.connect( "bad domain" );
alice.waitForConnection();

View File

@ -4,9 +4,8 @@ function LOG(aMsg) {
Components.utils.import( "resource://weave/xmpp/xmppClient.js" );
var serverUrl = "http://127.0.0.1:5280/http-poll";
var jabberDomain = Cc["@mozilla.org/network/dns-service;1"].
getService(Ci.nsIDNSService).myHostName;
var serverUrl = "http://localhost:5280/http-poll";
var jabberDomain = "localhost";
function run_test() {
// FIXME: this test hangs when you don't have a server, disabling for now