Fri, 06 Aug 2010 17:09:13 +0100
squishy: Add --with-bosh option to squish with verse.bosh and necessarylibraries
88 | 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 verse"); | |
7 | ||
8 | require "verse" -- Verse main library | |
9 | require "verse.bosh" -- Verse BOSH support | |
10 | require "verse.client" -- XMPP client library | |
11 | ||
12 | c = verse.new_bosh(nil, "http://example.com:5280/http-bind"); | |
13 | c:add_plugin("version"); | |
14 | ||
15 | -- Add some hooks for debugging | |
16 | c:hook("opened", function () print("Stream opened!") end); | |
17 | c:hook("closed", function () print("Stream closed!") end); | |
18 | c:hook("stanza", function (stanza) print("Stanza:", stanza) end); | |
19 | ||
20 | -- This one prints all received data | |
21 | c:hook("incoming-raw", print, 1000); | |
22 | ||
23 | -- Print a message after authentication | |
24 | c:hook("authentication-success", function () print("Logged in!"); end); | |
25 | c:hook("authentication-failure", function (err) print("Failed to log in! Error: "..tostring(err.condition)); end); | |
26 | ||
27 | -- Print a message and exit when disconnected | |
28 | c:hook("disconnected", function () print("Disconnected!"); os.exit(); end); | |
29 | ||
30 | -- Now, actually start the connection: | |
31 | c:connect_client(jid, password); | |
32 | ||
33 | -- Catch the "ready" event to know when the stream is ready to use | |
34 | c:hook("ready", function () | |
35 | print("Stream ready!"); | |
36 | c.version:set{ name = "Verse example BOSH client" }; | |
37 | c:query_version(c.jid, function (v) print("I am using "..(v.name or "<unknown>")); end); | |
38 | end); | |
39 | ||
40 | print("Starting loop...") | |
41 | verse.loop() |