plugins/smacks.lua

changeset 324
dbb3362c1ff3
parent 321
369d4638d775
child 326
f657ed8f464e
equal deleted inserted replaced
323:5bf3b13edb80 324:dbb3362c1ff3
42 stream:connect(stream.connect_host or stream.host, stream.connect_port or 5222); 42 stream:connect(stream.connect_host or stream.host, stream.connect_port or 5222);
43 end); 43 end);
44 return true; 44 return true;
45 end 45 end
46 end 46 end
47
48 -- Graceful shutdown
49 local function on_close()
50 stream.resumption_token = nil;
51 stream:unhook("disconnected", on_disconnect);
52 end
47 53
48 local function handle_sm_command(stanza) 54 local function handle_sm_command(stanza)
49 if stanza.name == "r" then -- Request for acks for stanzas we received 55 if stanza.name == "r" then -- Request for acks for stanzas we received
50 stream:debug("Ack requested... acking %d handled stanzas", handled_stanza_count); 56 stream:debug("Ack requested... acking %d handled stanzas", handled_stanza_count);
51 stream:send(verse.stanza("a", { xmlns = xmlns_sm, h = tostring(handled_stanza_count) })); 57 stream:send(verse.stanza("a", { xmlns = xmlns_sm, h = tostring(handled_stanza_count) }));
65 stream.smacks = true; 71 stream.smacks = true;
66 72
67 -- Catch stanzas 73 -- Catch stanzas
68 stream:hook("stanza", incoming_stanza); 74 stream:hook("stanza", incoming_stanza);
69 stream:hook("outgoing", outgoing_stanza); 75 stream:hook("outgoing", outgoing_stanza);
70 76
71 if stanza.attr.id then 77 if stanza.attr.id then
72 stream.resumption_token = stanza.attr.id; 78 stream.resumption_token = stanza.attr.id;
79 stream:hook("closed", on_close, 100);
73 stream:hook("disconnected", on_disconnect, 100); 80 stream:hook("disconnected", on_disconnect, 100);
74 end 81 end
75 elseif stanza.name == "resumed" then 82 elseif stanza.name == "resumed" then
76 local new_ack = tonumber(stanza.attr.h); 83 local new_ack = tonumber(stanza.attr.h);
77 if new_ack > last_ack then 84 if new_ack > last_ack then

mercurial