Annotate

doc/example_carbons.lua @ 271:c9d8628a61cc

plugins.roster: Change variable name to what's used in XMPP-IM
author Kim Alvefur <zash@zash.se>
date Sun, 01 Jan 2012 22:17:39 +0100
parent 260:7f6df45a3d1f
child 287:762511350532
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
226
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 local xmlns_carbons = "urn:xmpp:carbons:1";
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 local xmlns_forward = "urn:xmpp:forward:0";
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 -- This line squishes verse each time you run,
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 -- handy if you're hacking on Verse itself
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 --os.execute("squish --minify-level=none verse");
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7
260
7f6df45a3d1f doc/example*.lua: Update to use new .init() method
Matthew Wild <mwild1@gmail.com>
parents: 226
diff changeset
8 require "verse".init("client");
226
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 c = verse.new();--verse.logger());
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 c:add_plugin "carbons"
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 c:hook("disconnected", verse.quit);
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 local jid, password = unpack(arg);
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 assert(jid and password, "You need to supply JID and password as arguments");
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 c:connect_client(jid, password);
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 -- Print a message after authentication
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 c:hook("authentication-success", function () c:debug("Logged in!"); end);
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 c:hook("authentication-failure", function (err)
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 c:error("Failed to log in! Error: "..tostring(err.condition));
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 c:close();
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 end);
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 c:hook("carbon", function(carbon)
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 local dir, ts, st = carbon.dir, carbon.timestamp, carbon.stanza;
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 print("", ts, dir:upper());
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 print(st);
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 end);
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 -- Catch the "ready" event to know when the stream is ready to use
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 c:hook("ready", function ()
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 c:debug("Connected");
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 c.carbons:enable(function(ok)
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 if ok then
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 c:debug("Carbons enabled")
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 else
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 c:error("Could not enable carbons, aborting");
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39 c:close();
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40 end
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
41 end);
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
42 end);
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
43
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
44 verse.loop()