Annotate

doc/example_pep.lua @ 260:7f6df45a3d1f

doc/example*.lua: Update to use new .init() method
author Matthew Wild <mwild1@gmail.com>
date Mon, 05 Dec 2011 15:44:17 +0000
parent 243:20842f98f9ff
child 269:a15ede6b9ca1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
128
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 -- Change these:
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 local jid, password = "user@example.com", "secret";
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 -- This line squishes verse each time you run,
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 -- handy if you're hacking on Verse itself
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 --os.execute("squish --minify-level=none");
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
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: 243
diff changeset
8 require "verse".init("client");
128
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 c = verse.new();
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 c:add_plugin("version");
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 c:add_plugin("disco");
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 c:add_plugin("pep");
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 -- Add some hooks for debugging
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 c:hook("opened", function () print("Stream opened!") end);
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 c:hook("closed", function () print("Stream closed!") end);
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 c:hook("stanza", function (stanza) print("Stanza:", stanza) end);
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 -- This one prints all received data
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 c:hook("incoming-raw", print, 1000);
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 -- Print a message after authentication
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 c:hook("authentication-success", function () print("Logged in!"); end);
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 c:hook("authentication-failure", function (err) print("Failed to log in! Error: "..tostring(err.condition)); end);
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 -- Print a message and exit when disconnected
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 c:hook("disconnected", function () print("Disconnected!"); os.exit(); end);
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 -- Now, actually start the connection:
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 c:connect_client(jid, password);
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 -- Catch the "ready" event to know when the stream is ready to use
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 c:hook("ready", function ()
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 print("Stream ready!");
168
7285e04a4797 plugins.pep: Update for new disco/caps code
Matthew Wild <mwild1@gmail.com>
parents: 128
diff changeset
36 c:send(verse.presence());
128
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 c.version:set{ name = "verse example client" };
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 c:publish_pep(verse.stanza("tune", { xmlns = "http://jabber.org/protocol/tune" })
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 :tag("title"):text("Beautiful Cedars"):up()
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 :tag("artist"):text("The Spinners"):up()
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 :tag("source"):text("Not Quite Folk"):up()
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42 :tag("track"):text("4"):up()
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 );
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 c:hook_pep("http://jabber.org/protocol/mood", function (event)
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 print(event.from.." is "..event.item.tags[1].name);
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47 end);
168
7285e04a4797 plugins.pep: Update for new disco/caps code
Matthew Wild <mwild1@gmail.com>
parents: 128
diff changeset
48
7285e04a4797 plugins.pep: Update for new disco/caps code
Matthew Wild <mwild1@gmail.com>
parents: 128
diff changeset
49 c:hook_pep("http://jabber.org/protocol/tune", function (event)
243
20842f98f9ff doc/example_pep.lua: get_child_text()
Kim Alvefur <zash@zash.se>
parents: 168
diff changeset
50 print(event.from.." is listening to "..event.item:get_child_text("title"));
168
7285e04a4797 plugins.pep: Update for new disco/caps code
Matthew Wild <mwild1@gmail.com>
parents: 128
diff changeset
51 end);
128
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52 end);
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
54 print("Starting loop...")
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55 verse.loop()