Annotate

doc/example_carbons.lua @ 233:b5fd3292bdbd

squishy: Rewrite in an attempt to curb the unbounded growth of the plugin list
author Matthew Wild <mwild1@gmail.com>
date Sun, 27 Nov 2011 21:40:42 +0000
parent 226:efd66bcc62c1
child 260:7f6df45a3d1f
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
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 require "verse" -- Verse main library
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 require "verse.client" -- XMPP client library
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 c = verse.new();--verse.logger());
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 c:add_plugin "carbons"
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 c:hook("disconnected", verse.quit);
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 local jid, password = unpack(arg);
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 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
17 c:connect_client(jid, password);
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 -- Print a message after authentication
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 c:hook("authentication-success", function () c:debug("Logged in!"); end);
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 c:hook("authentication-failure", function (err)
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 c:error("Failed to log in! Error: "..tostring(err.condition));
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 c:close();
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 end);
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 c:hook("carbon", function(carbon)
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 local dir, ts, st = carbon.dir, carbon.timestamp, carbon.stanza;
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 print("", ts, dir:upper());
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 print(st);
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 end);
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 -- 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
33 c:hook("ready", function ()
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 c:debug("Connected");
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 c.carbons:enable(function(ok)
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 if ok then
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 c:debug("Carbons enabled")
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 else
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39 c:error("Could not enable carbons, aborting");
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40 c:close();
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 end);
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
44
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
45 verse.loop()