Comparison

plugins/mod_csi_simple.lua @ 9913:7d78b24d8449

mod_csi_simple: Trigger buffer flush on seeing incoming data I.e. the client sent us something, which means its network / radio is active.
author Kim Alvefur <zash@zash.se>
date Sun, 24 Mar 2019 18:58:53 +0100
parent 9912:601f9781a605
child 9914:2c6b7247c3d9
comparison
equal deleted inserted replaced
9912:601f9781a605 9913:7d78b24d8449
102 end 102 end
103 session.csi_counter = ctr + 1; 103 session.csi_counter = ctr + 1;
104 return stanza; 104 return stanza;
105 end 105 end
106 106
107 local function flush_buffer(data, session)
108 session.conn:resume_writes();
109 return data;
110 end
111
107 module:hook("csi-client-inactive", function (event) 112 module:hook("csi-client-inactive", function (event)
108 local session = event.origin; 113 local session = event.origin;
109 if session.conn and session.conn and session.conn.pause_writes then 114 if session.conn and session.conn and session.conn.pause_writes then
110 session.conn:pause_writes(); 115 session.conn:pause_writes();
111 filters.add_filter(session, "stanzas/out", manage_buffer); 116 filters.add_filter(session, "stanzas/out", manage_buffer);
117 filters.add_filter(session, "bytes/in", flush_buffer);
112 elseif session.pump then 118 elseif session.pump then
113 session.pump:pause(); 119 session.pump:pause();
114 else 120 else
115 local bare_jid = jid.join(session.username, session.host); 121 local bare_jid = jid.join(session.username, session.host);
116 local send = session.send; 122 local send = session.send;
134 local session = event.origin; 140 local session = event.origin;
135 if session.pump then 141 if session.pump then
136 session.pump:resume(); 142 session.pump:resume();
137 elseif session.conn and session.conn and session.conn.resume_writes then 143 elseif session.conn and session.conn and session.conn.resume_writes then
138 filters.remove_filter(session, "stanzas/out", manage_buffer); 144 filters.remove_filter(session, "stanzas/out", manage_buffer);
145 filters.remove_filter(session, "bytes/in", flush_buffer);
139 session.conn:resume_writes(); 146 session.conn:resume_writes();
140 end 147 end
141 end); 148 end);
142 149
143 150