Software /
code /
verse
Annotate
doc/example_carbons.lua @ 348:34b878d58948
plugins.pubsub: Implement fetching of items
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 06 Jul 2013 08:40:18 +0200 |
parent | 287:762511350532 |
rev | line source |
---|---|
226 | 1 local xmlns_carbons = "urn:xmpp:carbons:1"; |
2 local xmlns_forward = "urn:xmpp:forward:0"; | |
3 | |
287
762511350532
doc/example_carbons.lua: Update to reflect timestamp change in carbons plugin.
Kim Alvefur <zash@zash.se>
parents:
260
diff
changeset
|
4 local function datetime(t) return os_date("!%Y-%m-%dT%H:%M:%SZ", t); end |
762511350532
doc/example_carbons.lua: Update to reflect timestamp change in carbons plugin.
Kim Alvefur <zash@zash.se>
parents:
260
diff
changeset
|
5 |
226 | 6 -- This line squishes verse each time you run, |
7 -- handy if you're hacking on Verse itself | |
8 --os.execute("squish --minify-level=none verse"); | |
9 | |
260
7f6df45a3d1f
doc/example*.lua: Update to use new .init() method
Matthew Wild <mwild1@gmail.com>
parents:
226
diff
changeset
|
10 require "verse".init("client"); |
226 | 11 |
12 c = verse.new();--verse.logger()); | |
13 c:add_plugin "carbons" | |
14 | |
15 c:hook("disconnected", verse.quit); | |
16 local jid, password = unpack(arg); | |
17 assert(jid and password, "You need to supply JID and password as arguments"); | |
18 c:connect_client(jid, password); | |
19 | |
20 -- Print a message after authentication | |
21 c:hook("authentication-success", function () c:debug("Logged in!"); end); | |
22 c:hook("authentication-failure", function (err) | |
23 c:error("Failed to log in! Error: "..tostring(err.condition)); | |
24 c:close(); | |
25 end); | |
26 | |
27 c:hook("carbon", function(carbon) | |
28 local dir, ts, st = carbon.dir, carbon.timestamp, carbon.stanza; | |
287
762511350532
doc/example_carbons.lua: Update to reflect timestamp change in carbons plugin.
Kim Alvefur <zash@zash.se>
parents:
260
diff
changeset
|
29 print("", datetime(ts), dir:upper()); |
226 | 30 print(st); |
31 end); | |
32 | |
33 -- Catch the "ready" event to know when the stream is ready to use | |
34 c:hook("ready", function () | |
35 c:debug("Connected"); | |
36 c.carbons:enable(function(ok) | |
37 if ok then | |
38 c:debug("Carbons enabled") | |
39 else | |
40 c:error("Could not enable carbons, aborting"); | |
41 c:close(); | |
42 end | |
43 end); | |
44 end); | |
45 | |
46 verse.loop() |