Software /
code /
verse
Annotate
doc/example_component.lua @ 447:f3ecbf65a81e
squishy: Include util.hex used by util.uuid
Fixes errors because of its absence
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 06 Nov 2021 18:26:31 +0100 |
parent | 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"); |
260
7f6df45a3d1f
doc/example*.lua: Update to use new .init() method
Matthew Wild <mwild1@gmail.com>
parents:
151
diff
changeset
|
4 |
7f6df45a3d1f
doc/example*.lua: Update to use new .init() method
Matthew Wild <mwild1@gmail.com>
parents:
151
diff
changeset
|
5 require "verse".init("component"); |
7f6df45a3d1f
doc/example*.lua: Update to use new .init() method
Matthew Wild <mwild1@gmail.com>
parents:
151
diff
changeset
|
6 |
85
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() |