[Pkg-javascript-commits] [ltx] 75/469: real echo_server example

Jonas Smedegaard dr at jones.dk
Wed Aug 31 13:01:04 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 7e70b2db23e11acd2342fb0da0003c8d659b5af7
Author: Astro <astro at spaceboyz.net>
Date:   Sun Sep 5 20:15:09 2010 +0200

    real echo_server example
---
 examples/echo_server.js | 14 +++++++++-----
 lib/xmpp/router.js      | 10 +++++++++-
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/examples/echo_server.js b/examples/echo_server.js
index a632a66..1a24b49 100644
--- a/examples/echo_server.js
+++ b/examples/echo_server.js
@@ -1,8 +1,12 @@
 var xmpp = require('../lib/xmpp');
 
 var r = new xmpp.Router();
-r.send(new xmpp.Element('message', { from: 'test at codetu.be',
-				     to: 'astro at spaceboyz.net',
-				     type: 'chat' }).
-       c('body').t('Hello, World')
-      );
+r.register('codetu.be', function(stanza) {
+    console.log("<< "+stanza.toString());
+    if (stanza.attrs.type !== 'error') {
+	var me = stanza.attrs.to;
+	stanza.attrs.to = stanza.attrs.from;
+	stanza.attrs.from = me;
+	r.send(stanza);
+    }
+});
diff --git a/lib/xmpp/router.js b/lib/xmpp/router.js
index 366415f..89099d0 100644
--- a/lib/xmpp/router.js
+++ b/lib/xmpp/router.js
@@ -277,11 +277,19 @@ Router.prototype.acceptConnection = function(inStream) {
     });
 };
 
+/**
+ * Create domain context & register a stanza listener callback
+ */
+Router.prototype.register = function(domain, listener) {
+    this.getContext(domain).stanzaListener = listener;
+};
+
+// TODO: unregister w/ connections teardown
+
 Router.prototype.send = function(stanza) {
     if (stanza.root)
 	stanza = stanza.root();
 
-    console.log({send:stanza});
     if (stanza.attrs && stanza.attrs.from) {
 	var domain = (new JID.JID(stanza.attrs.from)).domain;
 	this.getContext(domain).send(stanza);

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