forked from mwild1/xmppjs
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
examples/echo.js: Add example echo component
- Loading branch information
Showing
1 changed file
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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())); | ||
} | ||
|