[Pkg-javascript-commits] [ltx] 05/469: DNS SRV support

Jonas Smedegaard dr at jones.dk
Wed Aug 31 13:00:50 UTC 2016


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository ltx.

commit 2f98ff282293f8220fb33870cc25f6ac42f790bc
Author: Astro <astro at spaceboyz.net>
Date:   Wed May 26 04:43:58 2010 +0200

    DNS SRV support
---
 README.markdown          |  1 -
 examples/send_message.js |  4 +---
 lib/xmpp/client.js       | 27 +++++++++++++++++++++++++--
 3 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/README.markdown b/README.markdown
index b6d77f9..dff8d39 100644
--- a/README.markdown
+++ b/README.markdown
@@ -53,4 +53,3 @@ Desires about the API? Propose them ASAP!
 * Clean up `Connection.prototype.onStanza()`
 * Support `SASL DIGEST-MD5` authentication
 * Component support (that's trivial)
-* DNS SRV support
diff --git a/examples/send_message.js b/examples/send_message.js
index bf0c53d..fb21e17 100644
--- a/examples/send_message.js
+++ b/examples/send_message.js
@@ -9,9 +9,7 @@ if (argv.length < 6) {
 }
 
 var cl = new xmpp.Client({ jid: argv[2],
-			   password: argv[3],
-			   host: 'jabber.ccc.de',
-			   port: 5222 });
+			   password: argv[3] });
 cl.addListener('online',
 	       function() {
 		   argv.slice(5).forEach(
diff --git a/lib/xmpp/client.js b/lib/xmpp/client.js
index 569a3fd..63f88a5 100644
--- a/lib/xmpp/client.js
+++ b/lib/xmpp/client.js
@@ -1,7 +1,7 @@
 var Connection = require('./connection').Connection;
 var JID = require('./jid').JID;
 var sys = require('sys');
-var puts = require('sys').puts;
+var dns = require('dns');
 
 /**
  * params:
@@ -19,7 +19,30 @@ function Client(params) {
     this.xmppVersion = "1.0";
     this.streamTo = this.jid.domain;
 
-    this.connect(params.port, params.host);
+    if (params.host) {
+	this.connect(params.port || 5222, params.host);
+    } else {
+	var self = this;
+	dns.resolveSrv('_xmpp-client._tcp.' + this.jid.domain,
+		       function(err, addrs) {
+			   if (err) {
+			       /* no SRV record, try domain as A */
+			       self.connect(params.port || 5222, self.jid.domain);
+			   } else {
+			       addrs = addrs.sort(
+					   function(a, b) {
+					       if (a.priority < b.priority)
+						   return -1;
+					       else if (a.priority > b.priority)
+						   return 1;
+					       else
+						   return 0;
+					   });
+			       /* Design fail: */
+			       self.connect(addrs[0].port, addrs[0].name);
+			   }
+		       });
+    }
 }
 
 sys.inherits(Client, Connection);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/ltx.git



More information about the Pkg-javascript-commits mailing list