[Pkg-javascript-commits] [ltx] 57/469: examples/echo_bot.js
Jonas Smedegaard
dr at jones.dk
Wed Aug 31 13:01:00 UTC 2016
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository ltx.
commit 8be2efefdd7945871cf084ade5453bcf37fadbf6
Author: Astro <astro at spaceboyz.net>
Date: Sat Aug 14 01:01:24 2010 +0200
examples/echo_bot.js
---
examples/echo_bot.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+)
diff --git a/examples/echo_bot.js b/examples/echo_bot.js
new file mode 100644
index 0000000..1952e39
--- /dev/null
+++ b/examples/echo_bot.js
@@ -0,0 +1,50 @@
+/**
+ * Echo Bot - the XMPP Hello World
+ **/
+require.paths.push('../lib');
+var sys = require('sys');
+var xmpp = require('xmpp');
+var argv = process.argv;
+
+if (argv.length != 4) {
+ sys.puts('Usage: node echo_bot.js <my-jid> <my-password>');
+ process.exit(1);
+}
+
+var cl = new xmpp.Client({ jid: argv[2],
+ password: argv[3] });
+cl.on('online',
+ function() {
+ cl.send(new xmpp.Element('presence',
+ { type: 'chat'}).
+ c('show').t('chat').up().
+ c('status').t('Happily echoing your <message/> stanzas')
+ );
+ });
+cl.on('stanza',
+ function(stanza) {
+ if (stanza.is('message') &&
+ // Important: never reply to errors!
+ stanza.attrs.type !== 'error') {
+
+ // Swap addresses...
+ stanza.attrs.to = stanza.attrs.from;
+ delete stanza.attrs.from;
+ // and send back.
+ cl.send(stanza);
+ }
+ });
+cl.on('authFail',
+ function() {
+ sys.puts("Authentication failure");
+ process.exit(1);
+ });
+cl.on('error',
+ function(e) {
+ sys.puts(e);
+ process.exit(1);
+ });
+cl.on('end',
+ function() {
+ /* node.js will exit by itself */
+ });
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/ltx.git
More information about the Pkg-javascript-commits
mailing list