Comparison

plugins/mod_c2s.lua @ 11974:a7c183bb4e64

mod_c2s: Add event just before closing as session To allow modules to do things just before the session is closed. The '(pre-)resource-unbind' events are fired after the stream is closed, leaving no way to send something.
author Kim Alvefur <zash@zash.se>
date Wed, 01 Dec 2021 15:06:48 +0100
parent 11899:6d06068363aa
child 12071:85c8fcb4192e
comparison
equal deleted inserted replaced
11973:d4730ae60226 11974:a7c183bb4e64
188 local log = session.log or log; 188 local log = session.log or log;
189 if session.conn then 189 if session.conn then
190 if session.notopen then 190 if session.notopen then
191 session:open_stream(); 191 session:open_stream();
192 end 192 end
193 local close_event_payload = { session = session, reason = reason };
194 module:context(session.host):fire_event("pre-session-close", close_event_payload);
195 reason = close_event_payload.reason;
193 if reason then -- nil == no err, initiated by us, false == initiated by client 196 if reason then -- nil == no err, initiated by us, false == initiated by client
194 local stream_error = st.stanza("stream:error"); 197 local stream_error = st.stanza("stream:error");
195 if type(reason) == "string" then -- assume stream error 198 if type(reason) == "string" then -- assume stream error
196 stream_error:tag(reason, {xmlns = 'urn:ietf:params:xml:ns:xmpp-streams' }); 199 stream_error:tag(reason, {xmlns = 'urn:ietf:params:xml:ns:xmpp-streams' });
197 elseif st.is_stanza(reason) then 200 elseif st.is_stanza(reason) then