| 1 | -- Change these: |
| 2 | local jid, password = "user@example.com/sender", "secret"; |
| 3 | local receiver = "user@example.com/receiver"; |
| 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"); |
| 8 | |
| 9 | require "verse".init("client"); |
| 10 | |
| 11 | c = verse.new(verse.logger()) |
| 12 | c:add_plugin("version"); |
| 13 | c:add_plugin("disco"); |
| 14 | c:add_plugin("proxy65"); |
| 15 | c:add_plugin("jingle"); |
| 16 | c:add_plugin("jingle_ft"); |
| 17 | c:add_plugin("jingle_s5b"); |
| 18 | |
| 19 | -- Add some hooks for debugging |
| 20 | c:hook("opened", function () print("Stream opened!") end); |
| 21 | c:hook("closed", function () print("Stream closed!") end); |
| 22 | c:hook("stanza", function (stanza) print("Stanza:", stanza) end, 15); |
| 23 | |
| 24 | -- This one prints all received data |
| 25 | --c:hook("incoming-raw", function (...) print("<<", ...) end, 1000); |
| 26 | |
| 27 | -- Print a message after authentication |
| 28 | c:hook("authentication-success", function () print("Logged in!"); end); |
| 29 | c:hook("authentication-failure", function (err) print("Failed to log in! Error: "..tostring(err.condition)); end); |
| 30 | |
| 31 | -- Print a message and exit when disconnected |
| 32 | c:hook("disconnected", function () print("Disconnected!"); os.exit(); end); |
| 33 | |
| 34 | -- Now, actually start the connection: |
| 35 | c:connect_client(jid, password); |
| 36 | |
| 37 | -- Catch the "ready" event to know when the stream is ready to use |
| 38 | c:hook("ready", function () |
| 39 | print("Stream ready!"); |
| 40 | |
| 41 | c:send(verse.presence() |
| 42 | :tag("status"):text("Let me send you a file!"):up() |
| 43 | :add_child(c:caps()) |
| 44 | ); |
| 45 | |
| 46 | c:hook("proxy65/discovered-proxies", function () |
| 47 | print(c:send_file(receiver, "jingle.txt")); |
| 48 | end); |
| 49 | end); |
| 50 | |
| 51 | print("Starting loop...") |
| 52 | verse.loop() |