Software /
code /
verse
Annotate
doc/example_bosh.lua @ 474:fca0c7672148
disco: Remove stray print()
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 17 Mar 2023 11:12:12 +0000 |
parent | 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 | |
260
7f6df45a3d1f
doc/example*.lua: Update to use new .init() method
Matthew Wild <mwild1@gmail.com>
parents:
91
diff
changeset
|
9 require "verse".init("client", "bosh"); |
88 | 10 |
91
59d7141827be
doc/example_bosh.lua: Put url into variable
Matthew Wild <mwild1@gmail.com>
parents:
88
diff
changeset
|
11 c = verse.new_bosh(nil, url); |
88 | 12 c:add_plugin("version"); |
13 | |
14 -- Add some hooks for debugging | |
15 c:hook("opened", function () print("Stream opened!") end); | |
16 c:hook("closed", function () print("Stream closed!") end); | |
17 c:hook("stanza", function (stanza) print("Stanza:", stanza) end); | |
18 | |
19 -- This one prints all received data | |
20 c:hook("incoming-raw", print, 1000); | |
21 | |
22 -- Print a message after authentication | |
23 c:hook("authentication-success", function () print("Logged in!"); end); | |
24 c:hook("authentication-failure", function (err) print("Failed to log in! Error: "..tostring(err.condition)); end); | |
25 | |
26 -- Print a message and exit when disconnected | |
27 c:hook("disconnected", function () print("Disconnected!"); os.exit(); end); | |
28 | |
29 -- Now, actually start the connection: | |
30 c:connect_client(jid, password); | |
31 | |
32 -- Catch the "ready" event to know when the stream is ready to use | |
33 c:hook("ready", function () | |
34 print("Stream ready!"); | |
35 c.version:set{ name = "Verse example BOSH client" }; | |
36 c:query_version(c.jid, function (v) print("I am using "..(v.name or "<unknown>")); end); | |
37 end); | |
38 | |
39 print("Starting loop...") | |
40 verse.loop() |