examples/echo.js

Fri, 16 Apr 2010 23:05:06 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Fri, 16 Apr 2010 23:05:06 +0100
changeset 19
998b0659c5f7
parent 13
917f370a7631
permissions
-rw-r--r--

xmpp.js: Set connection timeout to 0 to disable it (thanks pkrumins)

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