doc/example_jingle.lua

Fri, 17 Sep 2010 16:42:50 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Fri, 17 Sep 2010 16:42:50 +0100
changeset 144
46e933d81024
parent 110
3fca7dd127df
child 260
7f6df45a3d1f
permissions
-rw-r--r--

docs/example_jingle.lua: Update to use content.type instead of content.name for checking the kind of content we're receiving

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
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
8 require "verse" -- Verse main library
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 require "verse.client" -- XMPP client library
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
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 = 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
12 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
13 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
14 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
15 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
16 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
17 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
18
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 -- 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
20 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
21 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
22 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
23
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 -- 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
25 --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
26
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 -- 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
28 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
29 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
30
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 -- 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
32 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
33
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 -- 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
35 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
36
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 -- 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
38 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
39 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
40
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 -- 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
42 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
43 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
44 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
45 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
46 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
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 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
49
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 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
51 :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
52 :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
53 );
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 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
55
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 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
57 verse.loop()

mercurial