mirror of
https://github.com/bjc/prosody.git
synced 2025-04-03 05:07:42 +03:00
util.adminstream: Expose session events (specifically "disconnected")
Currently there is no way to get this info and perform cleanup tasks.
This commit is contained in:
parent
d58c6ae7ca
commit
7a281ab905
1 changed files with 10 additions and 8 deletions
|
@ -185,9 +185,12 @@ local function new_connection(socket_path, listeners)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function new_server(sessions, stanza_handler)
|
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");
|
log("debug", "New connection");
|
||||||
local session = sessionlib.new("admin");
|
local session = sessionlib.new("admin");
|
||||||
sessionlib.set_id(session);
|
sessionlib.set_id(session);
|
||||||
|
@ -241,29 +244,28 @@ local function new_server(sessions, stanza_handler)
|
||||||
sessions[conn] = session;
|
sessions[conn] = session;
|
||||||
end
|
end
|
||||||
|
|
||||||
function listeners.onincoming(conn, data)
|
function s.listeners.onincoming(conn, data)
|
||||||
local session = sessions[conn];
|
local session = sessions[conn];
|
||||||
if session then
|
if session then
|
||||||
session.data(data);
|
session.data(data);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function listeners.ondisconnect(conn, err)
|
function s.listeners.ondisconnect(conn, err)
|
||||||
local session = sessions[conn];
|
local session = sessions[conn];
|
||||||
if session then
|
if session then
|
||||||
session.log("info", "Admin client disconnected: %s", err or "connection closed");
|
session.log("info", "Admin client disconnected: %s", err or "connection closed");
|
||||||
session.conn = nil;
|
session.conn = nil;
|
||||||
sessions[conn] = nil;
|
sessions[conn] = nil;
|
||||||
|
s.events.fire_event("disconnected", { session = session });
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function listeners.onreadtimeout(conn)
|
function s.listeners.onreadtimeout(conn)
|
||||||
return conn:send(" ");
|
return conn:send(" ");
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return s;
|
||||||
listeners = listeners;
|
|
||||||
};
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function new_client()
|
local function new_client()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue