Annotate

doc/example_carbons.lua @ 260:7f6df45a3d1f

doc/example*.lua: Update to use new .init() method
author Matthew Wild <mwild1@gmail.com>
date Mon, 05 Dec 2011 15:44:17 +0000
parent 226:efd66bcc62c1
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()