doc/example_jingle.lua

1
-- Change these:
2
local jid, password = "user@example.com/receiver", "secret";
3
 
4
-- This line squishes verse each time you run,
5
-- handy if you're hacking on Verse itself
6
--os.execute("squish --minify-level=none");
7
 
8
require "verse".init("client");
9
 
10
c = verse.new(verse.logger())
11
c:add_plugin("version");
12
c:add_plugin("disco");
13
c:add_plugin("proxy65");
14
c:add_plugin("jingle");
15
c:add_plugin("jingle_ft");
16
c:add_plugin("jingle_s5b");
17
 
18
-- Add some hooks for debugging
19
c:hook("opened", function () print("Stream opened!") end);
20
c:hook("closed", function () print("Stream closed!") end);
21
c:hook("stanza", function (stanza) print("Stanza:", stanza) end, 15);
22
 
23
-- This one prints all received data
24
--c:hook("incoming-raw", function (...) print("<<", ...) end, 1000);
25
 
26
-- Print a message after authentication
27
c:hook("authentication-success", function () print("Logged in!"); end);
28
c:hook("authentication-failure", function (err) print("Failed to log in! Error: "..tostring(err.condition)); end);
29
 
30
-- Print a message and exit when disconnected
31
c:hook("disconnected", function () print("Disconnected!"); os.exit(); end);
32
 
33
-- Now, actually start the connection:
34
c:connect_client(jid, password);
35
 
36
-- Catch the "ready" event to know when the stream is ready to use
37
c:hook("ready", function ()
38
	print("Stream ready!");
39
	
40
	-- Handle incoming Jingle requests
41
	c:hook("jingle", function (jingle)
42
		if jingle.content.type == "file" then
43
			print("File offer from "..jingle.peer.."!");
44
			print("Filename: "..jingle.content.file.name.." Size: "..jingle.content.file.size);
45
			jingle:accept({ save_file = jingle.content.file.name..".received" });
46
		end
47
	end);
48
	
49
	c:send(verse.presence()
50
		:tag("status"):text("Send me a file!"):up()
51
		:add_child(c:caps())
52
	);
53
end);
54
 
55
print("Starting loop...")
56
verse.loop()