Software /
code /
verse
Annotate
doc/example.lua @ 209:48a404e083c4
plugins.roster: Don't signal roster events if there was no such item
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 24 May 2011 20:22:02 +0200 |
parent | 108:c67ed3fc5571 |
child | 260:7f6df45a3d1f |
rev | line source |
---|---|
58
f9d025fde8dc
doc/example.lua: Example XMPP client script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 -- Change these: |
f9d025fde8dc
doc/example.lua: Example XMPP client script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 local jid, password = "user@example.com", "secret"; |
f9d025fde8dc
doc/example.lua: Example XMPP client script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 |
f9d025fde8dc
doc/example.lua: Example XMPP client script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 -- This line squishes verse each time you run, |
f9d025fde8dc
doc/example.lua: Example XMPP client script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 -- handy if you're hacking on Verse itself |
f9d025fde8dc
doc/example.lua: Example XMPP client script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 --os.execute("squish --minify-level=none verse"); |
f9d025fde8dc
doc/example.lua: Example XMPP client script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 |
f9d025fde8dc
doc/example.lua: Example XMPP client script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 require "verse" -- Verse main library |
f9d025fde8dc
doc/example.lua: Example XMPP client script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 require "verse.client" -- XMPP client library |
f9d025fde8dc
doc/example.lua: Example XMPP client script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 |
108
c67ed3fc5571
doc/example.lua: Don't add sasl plugin, since it is enabled by default
Matthew Wild <mwild1@gmail.com>
parents:
77
diff
changeset
|
11 c = verse.new(); |
58
f9d025fde8dc
doc/example.lua: Example XMPP client script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 c:add_plugin("version"); |
f9d025fde8dc
doc/example.lua: Example XMPP client script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 |
f9d025fde8dc
doc/example.lua: Example XMPP client script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 -- Add some hooks for debugging |
f9d025fde8dc
doc/example.lua: Example XMPP client script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 c:hook("opened", function () print("Stream opened!") end); |
f9d025fde8dc
doc/example.lua: Example XMPP client script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 c:hook("closed", function () print("Stream closed!") end); |
f9d025fde8dc
doc/example.lua: Example XMPP client script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 c:hook("stanza", function (stanza) print("Stanza:", stanza) end); |
f9d025fde8dc
doc/example.lua: Example XMPP client script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 |
f9d025fde8dc
doc/example.lua: Example XMPP client script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 -- This one prints all received data |
f9d025fde8dc
doc/example.lua: Example XMPP client script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 c:hook("incoming-raw", print, 1000); |
f9d025fde8dc
doc/example.lua: Example XMPP client script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 |
f9d025fde8dc
doc/example.lua: Example XMPP client script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 -- Print a message after authentication |
f9d025fde8dc
doc/example.lua: Example XMPP client script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 c:hook("authentication-success", function () print("Logged in!"); end); |
f9d025fde8dc
doc/example.lua: Example XMPP client script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 c:hook("authentication-failure", function (err) print("Failed to log in! Error: "..tostring(err.condition)); end); |
f9d025fde8dc
doc/example.lua: Example XMPP client script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 |
f9d025fde8dc
doc/example.lua: Example XMPP client script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 -- Print a message and exit when disconnected |
f9d025fde8dc
doc/example.lua: Example XMPP client script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 c:hook("disconnected", function () print("Disconnected!"); os.exit(); end); |
f9d025fde8dc
doc/example.lua: Example XMPP client script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 |
f9d025fde8dc
doc/example.lua: Example XMPP client script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 -- Now, actually start the connection: |
f9d025fde8dc
doc/example.lua: Example XMPP client script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 c:connect_client(jid, password); |
f9d025fde8dc
doc/example.lua: Example XMPP client script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 |
77
7af3e57501c2
doc/example.lua: Update to use 'ready' event
Matthew Wild <mwild1@gmail.com>
parents:
58
diff
changeset
|
32 -- Catch the "ready" event to know when the stream is ready to use |
7af3e57501c2
doc/example.lua: Update to use 'ready' event
Matthew Wild <mwild1@gmail.com>
parents:
58
diff
changeset
|
33 c:hook("ready", function () |
58
f9d025fde8dc
doc/example.lua: Example XMPP client script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 print("Stream ready!"); |
f9d025fde8dc
doc/example.lua: Example XMPP client script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 c.version:set{ name = "verse example client" }; |
f9d025fde8dc
doc/example.lua: Example XMPP client script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 c:query_version(c.jid, function (v) print("I am using "..(v.name or "<unknown>")); end); |
f9d025fde8dc
doc/example.lua: Example XMPP client script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 end); |
f9d025fde8dc
doc/example.lua: Example XMPP client script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 |
f9d025fde8dc
doc/example.lua: Example XMPP client script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 print("Starting loop...") |
f9d025fde8dc
doc/example.lua: Example XMPP client script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 verse.loop() |