Software /
code /
verse
Annotate
doc/example_adhoc.lua @ 375:ec9e76bc7c7b
Added tag 0.9.0 for changeset 3267ae7c9217
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 01 Jan 2016 17:14:21 +0000 |
parent | 260:7f6df45a3d1f |
rev | line source |
---|---|
117
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 -- Change these: |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 local jid, password = "user@example.com", "secret"; |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 -- This line squishes verse each time you run, |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 -- handy if you're hacking on Verse itself |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 --os.execute("squish --minify-level=none"); |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 |
260
7f6df45a3d1f
doc/example*.lua: Update to use new .init() method
Matthew Wild <mwild1@gmail.com>
parents:
117
diff
changeset
|
8 require "verse".init("client"); |
117
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 c = verse.new(verse.logger()); |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 c:add_plugin("version"); |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 c:add_plugin("disco"); |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 c:add_plugin("adhoc"); |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 -- Add some hooks for debugging |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 c:hook("opened", function () print("Stream opened!") end); |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 c:hook("closed", function () print("Stream closed!") end); |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 c:hook("stanza", function (stanza) print("Stanza:", stanza) end); |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 -- This one prints all received data |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 c:hook("incoming-raw", print, 1000); |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 -- Print a message after authentication |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 c:hook("authentication-success", function () print("Logged in!"); end); |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 c:hook("authentication-failure", function (err) print("Failed to log in! Error: "..tostring(err.condition)); end); |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 -- Print a message and exit when disconnected |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 c:hook("disconnected", function () print("Disconnected!"); os.exit(); end); |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 -- Now, actually start the connection: |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 c:connect_client(jid, password); |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 -- Catch the "ready" event to know when the stream is ready to use |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 c:hook("ready", function () |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 print("Stream ready!"); |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 c.version:set{ name = "verse example client" }; |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 local function random_handler() |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 return { info = tostring(math.random(1,100)), status = "completed" }; |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 end |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 c:add_adhoc_command("Get random number", "random", random_handler); |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 c:send(verse.presence():add_child(c:caps())); |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 end); |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 print("Starting loop...") |
f523516196ce
doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 verse.loop() |