Software / code / verse
Comparison
doc/example_jingle.lua @ 110:3fca7dd127df
doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Tue, 24 Aug 2010 11:16:46 +0100 |
| child | 144:46e933d81024 |
comparison
equal
deleted
inserted
replaced
| 109:60a03b2cabec | 110:3fca7dd127df |
|---|---|
| 1 -- Change these: | |
| 2 local jid, password = "user@example.com/receiver", "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"); | |
| 7 | |
| 8 require "verse" -- Verse main library | |
| 9 require "verse.client" -- XMPP client library | |
| 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 -- Handle incoming Jingle requests | |
| 42 c:hook("jingle", function (jingle) | |
| 43 if jingle.content.name == "file" then | |
| 44 print("File offer from "..jingle.peer.."!"); | |
| 45 print("Filename: "..jingle.content.file.name.." Size: "..jingle.content.file.size); | |
| 46 jingle:accept({ save_file = jingle.content.file.name..".received" }); | |
| 47 end | |
| 48 end); | |
| 49 | |
| 50 c:send(verse.presence() | |
| 51 :tag("status"):text("Send me a file!"):up() | |
| 52 :add_child(c:caps()) | |
| 53 ); | |
| 54 end); | |
| 55 | |
| 56 print("Starting loop...") | |
| 57 verse.loop() |