Software /
code /
verse
Annotate
doc/example_component.lua @ 176:6004486e8b6c
plugins.disco,compression: Use xmlns_* variables
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 31 Dec 2010 01:10:57 +0100 |
parent | 151:75016d851648 |
child | 260:7f6df45a3d1f |
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 |
151
75016d851648
doc/example_component.lua: Add code to echo stanzas
Matthew Wild <mwild1@gmail.com>
parents:
86
diff
changeset
|
36 -- Echo, echo, echo, echo... |
75016d851648
doc/example_component.lua: Add code to echo stanzas
Matthew Wild <mwild1@gmail.com>
parents:
86
diff
changeset
|
37 c:hook("stanza", function (stanza) |
75016d851648
doc/example_component.lua: Add code to echo stanzas
Matthew Wild <mwild1@gmail.com>
parents:
86
diff
changeset
|
38 stanza.attr.from, stanza.attr.to = stanza.attr.to, stanza.attr.from; |
75016d851648
doc/example_component.lua: Add code to echo stanzas
Matthew Wild <mwild1@gmail.com>
parents:
86
diff
changeset
|
39 c:send(stanza); |
75016d851648
doc/example_component.lua: Add code to echo stanzas
Matthew Wild <mwild1@gmail.com>
parents:
86
diff
changeset
|
40 end) |
75016d851648
doc/example_component.lua: Add code to echo stanzas
Matthew Wild <mwild1@gmail.com>
parents:
86
diff
changeset
|
41 |
85
b9e71517d6e0
docs/example_component.lua: Example for connecting to the server as a component
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 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
|
43 verse.loop() |