Skip to content

Commit

Permalink
examples/echo.js: Add example echo component
Browse files Browse the repository at this point in the history
  • Loading branch information
mwild1 committed Feb 10, 2010
1 parent 3be584e commit 9f141c1
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions 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.