examples/echo.js

Sun, 21 Feb 2010 15:25:11 -0800

author
zuwiki <zuwiki@gmail.com>
date
Sun, 21 Feb 2010 15:25:11 -0800
changeset 14
aaad945d10ba
parent 13
917f370a7631
permissions
-rw-r--r--

Adding node-xml.js by Rob Righter. Fixing up xmpp.js to work for me. Can't say exactly what all was wrong, other than apparent changes in the node.js TCP API.

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