Software / code / verse
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 |
| rev | line source |
|---|---|
| 226 | 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 | |
|
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 | 9 |
| 10 c = verse.new();--verse.logger()); | |
| 11 c:add_plugin "carbons" | |
| 12 | |
| 13 c:hook("disconnected", verse.quit); | |
| 14 local jid, password = unpack(arg); | |
| 15 assert(jid and password, "You need to supply JID and password as arguments"); | |
| 16 c:connect_client(jid, password); | |
| 17 | |
| 18 -- Print a message after authentication | |
| 19 c:hook("authentication-success", function () c:debug("Logged in!"); end); | |
| 20 c:hook("authentication-failure", function (err) | |
| 21 c:error("Failed to log in! Error: "..tostring(err.condition)); | |
| 22 c:close(); | |
| 23 end); | |
| 24 | |
| 25 c:hook("carbon", function(carbon) | |
| 26 local dir, ts, st = carbon.dir, carbon.timestamp, carbon.stanza; | |
| 27 print("", ts, dir:upper()); | |
| 28 print(st); | |
| 29 end); | |
| 30 | |
| 31 -- Catch the "ready" event to know when the stream is ready to use | |
| 32 c:hook("ready", function () | |
| 33 c:debug("Connected"); | |
| 34 c.carbons:enable(function(ok) | |
| 35 if ok then | |
| 36 c:debug("Carbons enabled") | |
| 37 else | |
| 38 c:error("Could not enable carbons, aborting"); | |
| 39 c:close(); | |
| 40 end | |
| 41 end); | |
| 42 end); | |
| 43 | |
| 44 verse.loop() |