diff options
author | Matthew Wild <mwild1@gmail.com> | 2025-01-07 18:07:45 +0000 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2025-01-07 18:07:45 +0000 |
commit | 7a281ab90559cbe614ccc4d002d0e675fadb033c (patch) | |
tree | 969101cd79d01a60e5fc2d3cf137f60f6906859e | |
parent | d58c6ae7ca37c591411f72217676a52183bcf126 (diff) | |
download | prosody-7a281ab90559cbe614ccc4d002d0e675fadb033c.tar.gz prosody-7a281ab90559cbe614ccc4d002d0e675fadb033c.zip |
util.adminstream: Expose session events (specifically "disconnected")
Currently there is no way to get this info and perform cleanup tasks.
-rw-r--r-- | util/adminstream.lua | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/util/adminstream.lua b/util/adminstream.lua index a29222cf..5387c906 100644 --- a/util/adminstream.lua +++ b/util/adminstream.lua @@ -185,9 +185,12 @@ local function new_connection(socket_path, listeners) end local function new_server(sessions, stanza_handler) - local listeners = {}; + local s = { + events = events.new(); + listeners = {}; + }; - function listeners.onconnect(conn) + function s.listeners.onconnect(conn) log("debug", "New connection"); local session = sessionlib.new("admin"); sessionlib.set_id(session); @@ -241,29 +244,28 @@ local function new_server(sessions, stanza_handler) sessions[conn] = session; end - function listeners.onincoming(conn, data) + function s.listeners.onincoming(conn, data) local session = sessions[conn]; if session then session.data(data); end end - function listeners.ondisconnect(conn, err) + function s.listeners.ondisconnect(conn, err) local session = sessions[conn]; if session then session.log("info", "Admin client disconnected: %s", err or "connection closed"); session.conn = nil; sessions[conn] = nil; + s.events.fire_event("disconnected", { session = session }); end end - function listeners.onreadtimeout(conn) + function s.listeners.onreadtimeout(conn) return conn:send(" "); end - return { - listeners = listeners; - }; + return s; end local function new_client() |