Comparison

doc/example_pep.lua @ 128:720b9ccd7ea4

doc/example_pep.lua: Example script to use the PEP plugin
author Matthew Wild <mwild1@gmail.com>
date Mon, 13 Sep 2010 14:12:09 +0100
child 168:7285e04a4797
comparison
equal deleted inserted replaced
127:8f831f259cea 128:720b9ccd7ea4
1 -- Change these:
2 local jid, password = "user@example.com", "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();
12 c:add_plugin("version");
13 c:add_plugin("disco");
14 c:add_plugin("pep");
15
16 -- Add some hooks for debugging
17 c:hook("opened", function () print("Stream opened!") end);
18 c:hook("closed", function () print("Stream closed!") end);
19 c:hook("stanza", function (stanza) print("Stanza:", stanza) end);
20
21 -- This one prints all received data
22 c:hook("incoming-raw", print, 1000);
23
24 -- Print a message after authentication
25 c:hook("authentication-success", function () print("Logged in!"); end);
26 c:hook("authentication-failure", function (err) print("Failed to log in! Error: "..tostring(err.condition)); end);
27
28 -- Print a message and exit when disconnected
29 c:hook("disconnected", function () print("Disconnected!"); os.exit(); end);
30
31 -- Now, actually start the connection:
32 c:connect_client(jid, password);
33
34 -- Catch the "ready" event to know when the stream is ready to use
35 c:hook("ready", function ()
36 print("Stream ready!");
37 c.version:set{ name = "verse example client" };
38 c:publish_pep(verse.stanza("tune", { xmlns = "http://jabber.org/protocol/tune" })
39 :tag("title"):text("Beautiful Cedars"):up()
40 :tag("artist"):text("The Spinners"):up()
41 :tag("source"):text("Not Quite Folk"):up()
42 :tag("track"):text("4"):up()
43 );
44
45 c:hook_pep("http://jabber.org/protocol/mood", function (event)
46 print(event.from.." is "..event.item.tags[1].name);
47 end);
48 c:send(verse.presence():add_child(c:caps()));
49 end);
50
51 print("Starting loop...")
52 verse.loop()