Annotate

doc/example_pep.lua @ 400:0db9cb909cf1

client, component: Fix logging of invalid XML
author Matthew Wild <mwild1@gmail.com>
date Tue, 09 Feb 2016 23:39:31 +0000
parent 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("pep");
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 -- 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
15 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
16 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
17 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
18
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 -- 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
20 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
21
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 -- 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
23 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
24 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
25
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 -- 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
27 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
28
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 -- 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
30 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
31
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 -- 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
33 c:hook("ready", function ()
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 print("Stream ready!");
269
a15ede6b9ca1 doc/example_pep.lua: Reorder a bit to avoid re-sending presence multiple times when caps change.
Kim Alvefur <zash@zash.se>
parents: 260
diff changeset
35 c.version:set{ name = "verse example client" };
a15ede6b9ca1 doc/example_pep.lua: Reorder a bit to avoid re-sending presence multiple times when caps change.
Kim Alvefur <zash@zash.se>
parents: 260
diff changeset
36 c:hook_pep("http://jabber.org/protocol/mood", function (event)
a15ede6b9ca1 doc/example_pep.lua: Reorder a bit to avoid re-sending presence multiple times when caps change.
Kim Alvefur <zash@zash.se>
parents: 260
diff changeset
37 print(event.from.." is "..event.item.tags[1].name);
a15ede6b9ca1 doc/example_pep.lua: Reorder a bit to avoid re-sending presence multiple times when caps change.
Kim Alvefur <zash@zash.se>
parents: 260
diff changeset
38 end);
a15ede6b9ca1 doc/example_pep.lua: Reorder a bit to avoid re-sending presence multiple times when caps change.
Kim Alvefur <zash@zash.se>
parents: 260
diff changeset
39
a15ede6b9ca1 doc/example_pep.lua: Reorder a bit to avoid re-sending presence multiple times when caps change.
Kim Alvefur <zash@zash.se>
parents: 260
diff changeset
40 c:hook_pep("http://jabber.org/protocol/tune", function (event)
a15ede6b9ca1 doc/example_pep.lua: Reorder a bit to avoid re-sending presence multiple times when caps change.
Kim Alvefur <zash@zash.se>
parents: 260
diff changeset
41 print(event.from.." is listening to "..event.item:get_child_text("title"));
a15ede6b9ca1 doc/example_pep.lua: Reorder a bit to avoid re-sending presence multiple times when caps change.
Kim Alvefur <zash@zash.se>
parents: 260
diff changeset
42 end);
a15ede6b9ca1 doc/example_pep.lua: Reorder a bit to avoid re-sending presence multiple times when caps change.
Kim Alvefur <zash@zash.se>
parents: 260
diff changeset
43
168
7285e04a4797 plugins.pep: Update for new disco/caps code
Matthew Wild <mwild1@gmail.com>
parents: 128
diff changeset
44 c:send(verse.presence());
269
a15ede6b9ca1 doc/example_pep.lua: Reorder a bit to avoid re-sending presence multiple times when caps change.
Kim Alvefur <zash@zash.se>
parents: 260
diff changeset
45
128
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 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
47 :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
48 :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
49 :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
50 :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
51 );
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53 end);
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
54
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55 print("Starting loop...")
720b9ccd7ea4 doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
56 verse.loop()