Permalink
Browse files

examples/echo.js: Add example echo component

  • Loading branch information...
1 parent 3be584e commit 9f141c18f8f3609227cc0173c8f7aad41552756f @mwild1 mwild1 committed Feb 10, 2010
Showing with 22 additions and 0 deletions.
  1. +22 −0 examples/echo.js
View
22 examples/echo.js
@@ -0,0 +1,22 @@
+var jid = "echo.localhost", password = "hellohello";
+var xmpp = require("../xmpp");
+var conn = new xmpp.Connection();
+var sys = require("sys");
+
+conn.log = function (_, m) { sys.puts(m); };
+
+conn.connect(jid, password, function (status, condition) {
+ if(status == xmpp.Status.CONNECTED)
+ conn.addHandler(onMessage, null, 'message', null, null, null);
+ else
+ conn.log(xmpp.LogLevel.DEBUG, "New connection status: " + status + (condition?(" ("+condition+")"):""));
+});
+
+function onMessage(message) {
+ conn.send(xmpp.message({
+ to:message.getAttribute("from"),
+ from:message.getAttribute("to"),
+ type: "chat"})
+ .c("body").t(message.getChild("body").getText()));
+}
+

0 comments on commit 9f141c1

Please sign in to comment.