examples/echo.js

Wed, 24 Feb 2010 22:26:09 -0800

author
zuwiki <zuwiki@gmail.com>
date
Wed, 24 Feb 2010 22:26:09 -0800
changeset 16
74a24eb1fb44
parent 13
917f370a7631
permissions
-rw-r--r--

Making node-xml into a submodule. Gosh I hope I know what I'm doing.

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()));
}

mercurial