Software /
code /
verse
Annotate
doc/example_component.lua @ 130:5de7f66e4168
libs/encodings.lua: Use mime.b64 for base64.encode
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 13 Sep 2010 14:47:20 +0100 |
parent | 86:508f653e9d46 |
child | 151:75016d851648 |
rev | line source |
---|---|
86
508f653e9d46
example_component.lua: Fix password
Matthew Wild <mwild1@gmail.com>
parents:
85
diff
changeset
|
1 local jid, password = "echo.localhost", "hellohello"; |
85
b9e71517d6e0
docs/example_component.lua: Example for connecting to the server as a component
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 |
b9e71517d6e0
docs/example_component.lua: Example for connecting to the server as a component
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 --os.execute("squish --minify-level=none verse"); |
b9e71517d6e0
docs/example_component.lua: Example for connecting to the server as a component
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 require "verse" |
b9e71517d6e0
docs/example_component.lua: Example for connecting to the server as a component
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 require "verse.component" |
b9e71517d6e0
docs/example_component.lua: Example for connecting to the server as a component
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 require "socket" |
b9e71517d6e0
docs/example_component.lua: Example for connecting to the server as a component
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 c = verse.new(verse.logger()) |
b9e71517d6e0
docs/example_component.lua: Example for connecting to the server as a component
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 c:add_plugin("version"); |
b9e71517d6e0
docs/example_component.lua: Example for connecting to the server as a component
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 c:add_plugin("ping"); |
b9e71517d6e0
docs/example_component.lua: Example for connecting to the server as a component
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 |
b9e71517d6e0
docs/example_component.lua: Example for connecting to the server as a component
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 -- Add some hooks for debugging |
b9e71517d6e0
docs/example_component.lua: Example for connecting to the server as a component
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 c:hook("opened", function () print("Stream opened!") end); |
b9e71517d6e0
docs/example_component.lua: Example for connecting to the server as a component
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 c:hook("closed", function () print("Stream closed!") end); |
b9e71517d6e0
docs/example_component.lua: Example for connecting to the server as a component
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 c:hook("stanza", function (stanza) print("Stanza:", stanza) end); |
b9e71517d6e0
docs/example_component.lua: Example for connecting to the server as a component
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 |
b9e71517d6e0
docs/example_component.lua: Example for connecting to the server as a component
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 -- This one prints all received data |
b9e71517d6e0
docs/example_component.lua: Example for connecting to the server as a component
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 c:hook("incoming-raw", print, 1000); |
b9e71517d6e0
docs/example_component.lua: Example for connecting to the server as a component
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 |
b9e71517d6e0
docs/example_component.lua: Example for connecting to the server as a component
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 -- Print a message after authentication |
b9e71517d6e0
docs/example_component.lua: Example for connecting to the server as a component
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 c:hook("authentication-success", function () print("Logged in!"); end); |
b9e71517d6e0
docs/example_component.lua: Example for connecting to the server as a component
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 c:hook("authentication-failure", function (err) print("Failed to log in! Error: "..tostring(err.condition)); end); |
b9e71517d6e0
docs/example_component.lua: Example for connecting to the server as a component
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 |
b9e71517d6e0
docs/example_component.lua: Example for connecting to the server as a component
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 -- Print a message and exit when disconnected |
b9e71517d6e0
docs/example_component.lua: Example for connecting to the server as a component
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 c:hook("disconnected", function () print("Disconnected!"); os.exit(); end); |
b9e71517d6e0
docs/example_component.lua: Example for connecting to the server as a component
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 |
b9e71517d6e0
docs/example_component.lua: Example for connecting to the server as a component
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 -- Now, actually start the connection: |
b9e71517d6e0
docs/example_component.lua: Example for connecting to the server as a component
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 c.connect_host = "127.0.0.1" |
b9e71517d6e0
docs/example_component.lua: Example for connecting to the server as a component
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 c:connect_component(jid, password); |
b9e71517d6e0
docs/example_component.lua: Example for connecting to the server as a component
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 |
b9e71517d6e0
docs/example_component.lua: Example for connecting to the server as a component
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 -- Catch binding-success which is (currently) how you know when a stream is ready |
b9e71517d6e0
docs/example_component.lua: Example for connecting to the server as a component
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 c:hook("ready", function () |
b9e71517d6e0
docs/example_component.lua: Example for connecting to the server as a component
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 print("Stream ready!"); |
b9e71517d6e0
docs/example_component.lua: Example for connecting to the server as a component
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 c.version:set{ name = "verse example component" }; |
b9e71517d6e0
docs/example_component.lua: Example for connecting to the server as a component
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 end); |
b9e71517d6e0
docs/example_component.lua: Example for connecting to the server as a component
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 |
b9e71517d6e0
docs/example_component.lua: Example for connecting to the server as a component
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 print("Starting loop...") |
b9e71517d6e0
docs/example_component.lua: Example for connecting to the server as a component
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 verse.loop() |