Software /
code /
verse
Comparison
doc/example_carbons.lua @ 226:efd66bcc62c1
doc: Add Carbons example
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 02 Nov 2011 01:18:53 +0100 |
child | 260:7f6df45a3d1f |
comparison
equal
deleted
inserted
replaced
225:04bfa5c3a776 | 226:efd66bcc62c1 |
---|---|
1 local xmlns_carbons = "urn:xmpp:carbons:1"; | |
2 local xmlns_forward = "urn:xmpp:forward:0"; | |
3 | |
4 -- This line squishes verse each time you run, | |
5 -- handy if you're hacking on Verse itself | |
6 --os.execute("squish --minify-level=none verse"); | |
7 | |
8 require "verse" -- Verse main library | |
9 require "verse.client" -- XMPP client library | |
10 | |
11 c = verse.new();--verse.logger()); | |
12 c:add_plugin "carbons" | |
13 | |
14 c:hook("disconnected", verse.quit); | |
15 local jid, password = unpack(arg); | |
16 assert(jid and password, "You need to supply JID and password as arguments"); | |
17 c:connect_client(jid, password); | |
18 | |
19 -- Print a message after authentication | |
20 c:hook("authentication-success", function () c:debug("Logged in!"); end); | |
21 c:hook("authentication-failure", function (err) | |
22 c:error("Failed to log in! Error: "..tostring(err.condition)); | |
23 c:close(); | |
24 end); | |
25 | |
26 c:hook("carbon", function(carbon) | |
27 local dir, ts, st = carbon.dir, carbon.timestamp, carbon.stanza; | |
28 print("", ts, dir:upper()); | |
29 print(st); | |
30 end); | |
31 | |
32 -- Catch the "ready" event to know when the stream is ready to use | |
33 c:hook("ready", function () | |
34 c:debug("Connected"); | |
35 c.carbons:enable(function(ok) | |
36 if ok then | |
37 c:debug("Carbons enabled") | |
38 else | |
39 c:error("Could not enable carbons, aborting"); | |
40 c:close(); | |
41 end | |
42 end); | |
43 end); | |
44 | |
45 verse.loop() |