7 -- State for outgoing stanzas |
7 -- State for outgoing stanzas |
8 local outgoing_queue = {}; |
8 local outgoing_queue = {}; |
9 local last_ack = 0; |
9 local last_ack = 0; |
10 local last_stanza_time = now(); |
10 local last_stanza_time = now(); |
11 local timer_active; |
11 local timer_active; |
12 |
12 |
13 -- State for incoming stanzas |
13 -- State for incoming stanzas |
14 local handled_stanza_count = 0; |
14 local handled_stanza_count = 0; |
15 |
15 |
16 -- Catch incoming stanzas |
16 -- Catch incoming stanzas |
17 local function incoming_stanza(stanza) |
17 local function incoming_stanza(stanza) |
18 if stanza.attr.xmlns == "jabber:client" or not stanza.attr.xmlns then |
18 if stanza.attr.xmlns == "jabber:client" or not stanza.attr.xmlns then |
19 handled_stanza_count = handled_stanza_count + 1; |
19 handled_stanza_count = handled_stanza_count + 1; |
20 stream:debug("Increasing handled stanzas to %d for %s", handled_stanza_count, stanza:top_tag()); |
20 stream:debug("Increasing handled stanzas to %d for %s", handled_stanza_count, stanza:top_tag()); |
57 verse.add_task(1, function () |
57 verse.add_task(1, function () |
58 stream:connect(stream.connect_host or stream.host, stream.connect_port or 5222); |
58 stream:connect(stream.connect_host or stream.host, stream.connect_port or 5222); |
59 end); |
59 end); |
60 return true; |
60 return true; |
61 end |
61 end |
62 end |
62 end |
63 |
63 |
64 -- Graceful shutdown |
64 -- Graceful shutdown |
65 local function on_close() |
65 local function on_close() |
66 stream.resumption_token = nil; |
66 stream.resumption_token = nil; |
67 stream:unhook("disconnected", on_disconnect); |
67 stream:unhook("disconnected", on_disconnect); |
68 end |
68 end |
69 |
69 |
70 local function handle_sm_command(stanza) |
70 local function handle_sm_command(stanza) |
71 if stanza.name == "r" then -- Request for acks for stanzas we received |
71 if stanza.name == "r" then -- Request for acks for stanzas we received |
72 stream:debug("Ack requested... acking %d handled stanzas", handled_stanza_count); |
72 stream:debug("Ack requested... acking %d handled stanzas", handled_stanza_count); |
73 stream:send(verse.stanza("a", { xmlns = xmlns_sm, h = tostring(handled_stanza_count) })); |
73 stream:send(verse.stanza("a", { xmlns = xmlns_sm, h = tostring(handled_stanza_count) })); |
74 elseif stanza.name == "a" then -- Ack for stanzas we sent |
74 elseif stanza.name == "a" then -- Ack for stanzas we sent |