scansion/objects/client.lua

changeset 6
0c94ea0cabec
parent 4
c54194d8cc30
child 8
42b4e73c0d30
--- a/scansion/objects/client.lua	Sat Sep 05 23:20:17 2015 +0100
+++ b/scansion/objects/client.lua	Sat Sep 05 23:24:15 2015 +0100
@@ -3,6 +3,11 @@
 verse.set_log_handler(verse._default_log_handler, { "debug", "info", "warn", "error" });
 
 local parse_xml = require "scansion.xml".parse;
+
+local stanza_timeout = 5;
+
+local stanzacmp = require "scansion.stanzacmp";
+
 return {
 	_validate = function (client)
 		assert(client.jid, "No JID specified");
@@ -14,12 +19,25 @@
 	end;
 
 	sends = function (client, data)
-		print(("%q"):format(table.concat(data)))
-		print(parse_xml(table.concat(data)));
-		print(stanza)
+		local stanza =  parse_xml(table.concat(data));
+		client.stream:send(stanza);
 	end;
 
 	receives = function (client, data)
+		local expected_stanza = parse_xml(table.concat(data));
+		local function stanza_handler(received_stanza)
+			if not stanzacmp.stanzas_match(expected_stanza, received_stanza) then
+				print("NOT IT!")
+				verse.quit();
+			else
+				print("YES!")
+			end
+			expected_stanza = nil;
+		end
+		client.stream:hook("stanza", stanza_handler, 100);
+		verse.add_task(stanza_timeout, function ()
+			if not expected_stanza then return; end
+		end);
 	end;
 
 	disconnects = function (client)

mercurial