Annotate

doc/example_jingle.lua @ 340:0ce227f6034c

plugins.adhoc: Add missing return in error case
author Matthew Wild <mwild1@gmail.com>
date Tue, 28 May 2013 15:14:50 +0100
parent 260:7f6df45a3d1f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
110
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 -- Change these:
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 local jid, password = "user@example.com/receiver", "secret";
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 -- This line squishes verse each time you run,
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 -- handy if you're hacking on Verse itself
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 --os.execute("squish --minify-level=none");
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7
260
7f6df45a3d1f doc/example*.lua: Update to use new .init() method
Matthew Wild <mwild1@gmail.com>
parents: 144
diff changeset
8 require "verse".init("client");
110
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 c = verse.new(verse.logger())
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 c:add_plugin("version");
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 c:add_plugin("disco");
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 c:add_plugin("proxy65");
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 c:add_plugin("jingle");
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 c:add_plugin("jingle_ft");
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 c:add_plugin("jingle_s5b");
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 -- Add some hooks for debugging
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 c:hook("opened", function () print("Stream opened!") end);
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 c:hook("closed", function () print("Stream closed!") end);
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 c:hook("stanza", function (stanza) print("Stanza:", stanza) end, 15);
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 -- This one prints all received data
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 --c:hook("incoming-raw", function (...) print("<<", ...) end, 1000);
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 -- Print a message after authentication
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 c:hook("authentication-success", function () print("Logged in!"); end);
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 c:hook("authentication-failure", function (err) print("Failed to log in! Error: "..tostring(err.condition)); end);
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 -- Print a message and exit when disconnected
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 c:hook("disconnected", function () print("Disconnected!"); os.exit(); end);
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 -- Now, actually start the connection:
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 c:connect_client(jid, password);
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 -- Catch the "ready" event to know when the stream is ready to use
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 c:hook("ready", function ()
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 print("Stream ready!");
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 -- Handle incoming Jingle requests
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 c:hook("jingle", function (jingle)
144
46e933d81024 docs/example_jingle.lua: Update to use content.type instead of content.name for checking the kind of content we're receiving
Matthew Wild <mwild1@gmail.com>
parents: 110
diff changeset
42 if jingle.content.type == "file" then
110
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 print("File offer from "..jingle.peer.."!");
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 print("Filename: "..jingle.content.file.name.." Size: "..jingle.content.file.size);
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 jingle:accept({ save_file = jingle.content.file.name..".received" });
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 end
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47 end);
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49 c:send(verse.presence()
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 :tag("status"):text("Send me a file!"):up()
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51 :add_child(c:caps())
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52 );
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53 end);
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
54
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55 print("Starting loop...")
3fca7dd127df doc/example_jingle.lua, doc/example_jingle_send.lua: Example scripts to receive and send files using Jingle
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
56 verse.loop()