[Pkg-javascript-commits] [ltx] 04/469: examples/send_message.js & various fixes

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 4ff5ff5d064ab2aa3e653fb9b3141b56b52763c6
Author: Astro <astro at spaceboyz.net>
Date:   Wed May 26 04:19:18 2010 +0200

    examples/send_message.js & various fixes
---
 examples/send_message.js | 26 ++++++++++++++++++++++++++
 lib/xmpp.js              |  3 ++-
 lib/xmpp/connection.js   |  7 ++-----
 lib/xmpp/xml.js          |  2 +-
 4 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/examples/send_message.js b/examples/send_message.js
new file mode 100644
index 0000000..bf0c53d
--- /dev/null
+++ b/examples/send_message.js
@@ -0,0 +1,26 @@
+require.paths.push('../lib');
+var sys = require('sys');
+var xmpp = require('xmpp');
+var argv = process.argv;
+
+if (argv.length < 6) {
+    sys.puts('Usage: node send_message.js <my-jid> <my-password> <my-text> <jid1> [jid2] ... [jidN]');
+    process.exit(1);
+}
+
+var cl = new xmpp.Client({ jid: argv[2],
+			   password: argv[3],
+			   host: 'jabber.ccc.de',
+			   port: 5222 });
+cl.addListener('online',
+	       function() {
+		   argv.slice(5).forEach(
+		       function(to) {
+			   cl.send(new xmpp.XML.Element('message',
+							{ to: to,
+							  type: 'chat'}).
+				   c('body').
+				   t(argv[4]));
+		       });
+		   cl.end();
+	       });
diff --git a/lib/xmpp.js b/lib/xmpp.js
index 6eff5c4..318d301 100644
--- a/lib/xmpp.js
+++ b/lib/xmpp.js
@@ -1,6 +1,7 @@
 var Client = require('./xmpp/client').Client;
 var JID = require('./xmpp/jid').JID;
+var XML = require('./xmpp/xml');
 
 exports.Client = Client;
 exports.JID = JID;
-
+exports.XML = XML;
diff --git a/lib/xmpp/connection.js b/lib/xmpp/connection.js
index cc0371a..3849b3a 100644
--- a/lib/xmpp/connection.js
+++ b/lib/xmpp/connection.js
@@ -1,7 +1,6 @@
 var net = require('net');
 var sys = require('sys');
 var expat = require('expat');
-var puts = require('sys').puts;
 var xml = require('./xml');
 var sasl = require('./sasl');
 var JID = require('./jid').JID;
@@ -37,7 +36,6 @@ sys.inherits(Connection, net.Stream);
 exports.Connection = Connection;
 
 Connection.prototype.send = function(stanza) {
-    puts("SEND " + stanza);
     var self = this;
     if (stanza.root)
 	stanza.root().write(function(s) {
@@ -113,8 +111,6 @@ Connection.prototype.onData = function(data) {
  * before 'stanza' events are emitted to the user.
  */
 Connection.prototype.onStanza = function(stanza) {
-    puts('Stanza: ' + stanza.toString());
-
     if (this.state == STATE_ONLINE) {
 	this.emit('stanza', this.element);
     } else if (this.state == STATE_PREAUTH &&
@@ -194,7 +190,8 @@ Connection.prototype.onStanza = function(stanza) {
 	       stanza.name == 'iq' &&
 	       stanza.attrs.id == IQID_SESSION) {
 	if (stanza.attrs.type == 'result') {
-	    this.state = STATE_AUTHED;
+	    this.state = STATE_ONLINE;
+	    this.emit('online');
 	} else {
 	    this.emit('error', "Cannot establish session");
 	    this.end();
diff --git a/lib/xmpp/xml.js b/lib/xmpp/xml.js
index f19a0c2..335f513 100644
--- a/lib/xmpp/xml.js
+++ b/lib/xmpp/xml.js
@@ -143,4 +143,4 @@ function escapeXml(s) {
 };
 
 exports.Element = Element;
-exports.escapeXml = escapeXml;
\ No newline at end of file
+exports.escapeXml = escapeXml;

-- 
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