|
1 local jid, password = "echo.localhost", "testtest123testtesttesttest123testtests"; --"hellohello"; |
|
2 |
|
3 --os.execute("squish --minify-level=none verse"); |
|
4 require "verse" |
|
5 require "verse.component" |
|
6 require "socket" |
|
7 c = verse.new(verse.logger()) |
|
8 c:add_plugin("version"); |
|
9 c:add_plugin("ping"); |
|
10 |
|
11 -- Add some hooks for debugging |
|
12 c:hook("opened", function () print("Stream opened!") end); |
|
13 c:hook("closed", function () print("Stream closed!") end); |
|
14 c:hook("stanza", function (stanza) print("Stanza:", stanza) end); |
|
15 |
|
16 -- This one prints all received data |
|
17 c:hook("incoming-raw", print, 1000); |
|
18 |
|
19 -- Print a message after authentication |
|
20 c:hook("authentication-success", function () print("Logged in!"); end); |
|
21 c:hook("authentication-failure", function (err) print("Failed to log in! Error: "..tostring(err.condition)); end); |
|
22 |
|
23 -- Print a message and exit when disconnected |
|
24 c:hook("disconnected", function () print("Disconnected!"); os.exit(); end); |
|
25 |
|
26 -- Now, actually start the connection: |
|
27 c.connect_host = "127.0.0.1" |
|
28 c:connect_component(jid, password); |
|
29 |
|
30 -- Catch binding-success which is (currently) how you know when a stream is ready |
|
31 c:hook("ready", function () |
|
32 print("Stream ready!"); |
|
33 c.version:set{ name = "verse example component" }; |
|
34 end); |
|
35 |
|
36 print("Starting loop...") |
|
37 verse.loop() |