Software /
code /
verse
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 |
rev | line source |
---|---|
88 | 1 -- Change these: |
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 | 4 |
5 -- This line squishes verse each time you run, | |
6 -- handy if you're hacking on Verse itself | |
7 --os.execute("squish --minify-level=none verse"); | |
8 | |
9 require "verse" -- Verse main library | |
10 require "verse.bosh" -- Verse BOSH support | |
11 require "verse.client" -- XMPP client library | |
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 | 14 c:add_plugin("version"); |
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 BOSH client" }; | |
38 c:query_version(c.jid, function (v) print("I am using "..(v.name or "<unknown>")); end); | |
39 end); | |
40 | |
41 print("Starting loop...") | |
42 verse.loop() |