| 1 | local xmlns_carbons = "urn:xmpp:carbons:1"; |
| 2 | local xmlns_forward = "urn:xmpp:forward:0"; |
| 3 | |
| 4 | local function datetime(t) return os_date("!%Y-%m-%dT%H:%M:%SZ", t); end |
| 5 | |
| 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 | |
| 10 | require "verse".init("client"); |
| 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; |
| 29 | print("", datetime(ts), dir:upper()); |
| 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() |