Annotate

doc/example_bosh.lua @ 243:20842f98f9ff

doc/example_pep.lua: get_child_text()
author Kim Alvefur <zash@zash.se>
date Thu, 24 Nov 2011 07:02:27 +0100
parent 91:59d7141827be
child 260:7f6df45a3d1f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
88
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 -- Change these:
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 local jid, password = "user@example.com", "secret";
91
59d7141827be doc/example_bosh.lua: Put url into variable
Matthew Wild <mwild1@gmail.com>
parents: 88
diff changeset
3 local url = "http://example.com:80/http-bind";
88
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 -- This line squishes verse each time you run,
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 -- handy if you're hacking on Verse itself
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 --os.execute("squish --minify-level=none verse");
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 require "verse" -- Verse main library
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 require "verse.bosh" -- Verse BOSH support
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 require "verse.client" -- XMPP client library
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12
91
59d7141827be doc/example_bosh.lua: Put url into variable
Matthew Wild <mwild1@gmail.com>
parents: 88
diff changeset
13 c = verse.new_bosh(nil, url);
88
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 c:add_plugin("version");
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 -- Add some hooks for debugging
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 c:hook("opened", function () print("Stream opened!") end);
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 c:hook("closed", function () print("Stream closed!") end);
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 c:hook("stanza", function (stanza) print("Stanza:", stanza) end);
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 -- This one prints all received data
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 c:hook("incoming-raw", print, 1000);
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 -- Print a message after authentication
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 c:hook("authentication-success", function () print("Logged in!"); end);
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 c:hook("authentication-failure", function (err) print("Failed to log in! Error: "..tostring(err.condition)); end);
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 -- Print a message and exit when disconnected
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 c:hook("disconnected", function () print("Disconnected!"); os.exit(); end);
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 -- Now, actually start the connection:
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 c:connect_client(jid, password);
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 -- Catch the "ready" event to know when the stream is ready to use
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 c:hook("ready", function ()
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 print("Stream ready!");
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 c.version:set{ name = "Verse example BOSH client" };
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 c:query_version(c.jid, function (v) print("I am using "..(v.name or "<unknown>")); end);
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 end);
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 print("Starting loop...")
e204ef45bdd6 Add doc/example_bosh.lua
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42 verse.loop()