doc/example_pep.lua

changeset 269
a15ede6b9ca1
parent 260
7f6df45a3d1f
equal deleted inserted replaced
268:06e6c6de6438 269:a15ede6b9ca1
7 7
8 require "verse".init("client"); 8 require "verse".init("client");
9 9
10 c = verse.new(); 10 c = verse.new();
11 c:add_plugin("version"); 11 c:add_plugin("version");
12 c:add_plugin("disco");
13 c:add_plugin("pep"); 12 c:add_plugin("pep");
14 13
15 -- Add some hooks for debugging 14 -- Add some hooks for debugging
16 c:hook("opened", function () print("Stream opened!") end); 15 c:hook("opened", function () print("Stream opened!") end);
17 c:hook("closed", function () print("Stream closed!") end); 16 c:hook("closed", function () print("Stream closed!") end);
31 c:connect_client(jid, password); 30 c:connect_client(jid, password);
32 31
33 -- Catch the "ready" event to know when the stream is ready to use 32 -- Catch the "ready" event to know when the stream is ready to use
34 c:hook("ready", function () 33 c:hook("ready", function ()
35 print("Stream ready!"); 34 print("Stream ready!");
35 c.version:set{ name = "verse example client" };
36 c:hook_pep("http://jabber.org/protocol/mood", function (event)
37 print(event.from.." is "..event.item.tags[1].name);
38 end);
39
40 c:hook_pep("http://jabber.org/protocol/tune", function (event)
41 print(event.from.." is listening to "..event.item:get_child_text("title"));
42 end);
43
36 c:send(verse.presence()); 44 c:send(verse.presence());
37 c.version:set{ name = "verse example client" }; 45
38 c:publish_pep(verse.stanza("tune", { xmlns = "http://jabber.org/protocol/tune" }) 46 c:publish_pep(verse.stanza("tune", { xmlns = "http://jabber.org/protocol/tune" })
39 :tag("title"):text("Beautiful Cedars"):up() 47 :tag("title"):text("Beautiful Cedars"):up()
40 :tag("artist"):text("The Spinners"):up() 48 :tag("artist"):text("The Spinners"):up()
41 :tag("source"):text("Not Quite Folk"):up() 49 :tag("source"):text("Not Quite Folk"):up()
42 :tag("track"):text("4"):up() 50 :tag("track"):text("4"):up()
43 ); 51 );
44 52
45 c:hook_pep("http://jabber.org/protocol/mood", function (event)
46 print(event.from.." is "..event.item.tags[1].name);
47 end);
48
49 c:hook_pep("http://jabber.org/protocol/tune", function (event)
50 print(event.from.." is listening to "..event.item:get_child_text("title"));
51 end);
52 end); 53 end);
53 54
54 print("Starting loop...") 55 print("Starting loop...")
55 verse.loop() 56 verse.loop()

mercurial