| 1 | -- Change these: |
| 2 | local jid, password = "user@example.com", "secret"; |
| 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 | local verse = require "verse".init("client"); |
| 9 | |
| 10 | c = verse.new(); |
| 11 | c:add_plugin("version"); |
| 12 | |
| 13 | -- Add some hooks for debugging |
| 14 | c:hook("opened", function () print("Stream opened!") end); |
| 15 | c:hook("closed", function () print("Stream closed!") end); |
| 16 | c:hook("stanza", function (stanza) print("Stanza:", stanza) end); |
| 17 | |
| 18 | -- This one prints all received data |
| 19 | c:hook("incoming-raw", print, 1000); |
| 20 | |
| 21 | -- Print a message after authentication |
| 22 | c:hook("authentication-success", function () print("Logged in!"); end); |
| 23 | c:hook("authentication-failure", function (err) print("Failed to log in! Error: "..tostring(err.condition)); end); |
| 24 | |
| 25 | -- Print a message and exit when disconnected |
| 26 | c:hook("disconnected", function () print("Disconnected!"); os.exit(); end); |
| 27 | |
| 28 | -- Now, actually start the connection: |
| 29 | c:connect_client(jid, password); |
| 30 | |
| 31 | -- Catch the "ready" event to know when the stream is ready to use |
| 32 | c:hook("ready", function () |
| 33 | print("Stream ready!"); |
| 34 | c.version:set{ name = "verse example client" }; |
| 35 | c:query_version(c.jid, function (v) print("I am using "..(v.name or "<unknown>")); end); |
| 36 | end); |
| 37 | |
| 38 | print("Starting loop...") |
| 39 | verse.loop() |