| 1 | -- Change these: |
| 2 | local jid, password = "user@example.com", "secret"; |
| 3 | local url = "http://example.com:80/http-bind"; |
| 4 | |
| 5 | -- This line squishes verse each time you run, |
| 6 | -- handy if you're hacking on Verse itself |
| 7 | --os.execute("squish --minify-level=none verse"); |
| 8 | |
| 9 | require "verse".init("client", "bosh"); |
| 10 | |
| 11 | c = verse.new_bosh(nil, url); |
| 12 | c:add_plugin("version"); |
| 13 | |
| 14 | -- Add some hooks for debugging |
| 15 | c:hook("opened", function () print("Stream opened!") end); |
| 16 | c:hook("closed", function () print("Stream closed!") end); |
| 17 | c:hook("stanza", function (stanza) print("Stanza:", stanza) end); |
| 18 | |
| 19 | -- This one prints all received data |
| 20 | c:hook("incoming-raw", print, 1000); |
| 21 | |
| 22 | -- Print a message after authentication |
| 23 | c:hook("authentication-success", function () print("Logged in!"); end); |
| 24 | c:hook("authentication-failure", function (err) print("Failed to log in! Error: "..tostring(err.condition)); end); |
| 25 | |
| 26 | -- Print a message and exit when disconnected |
| 27 | c:hook("disconnected", function () print("Disconnected!"); os.exit(); end); |
| 28 | |
| 29 | -- Now, actually start the connection: |
| 30 | c:connect_client(jid, password); |
| 31 | |
| 32 | -- Catch the "ready" event to know when the stream is ready to use |
| 33 | c:hook("ready", function () |
| 34 | print("Stream ready!"); |
| 35 | c.version:set{ name = "Verse example BOSH client" }; |
| 36 | c:query_version(c.jid, function (v) print("I am using "..(v.name or "<unknown>")); end); |
| 37 | end); |
| 38 | |
| 39 | print("Starting loop...") |
| 40 | verse.loop() |