diff --git a/amqtt/broker.py b/amqtt/broker.py index 5eb1ddb..15e2a42 100644 --- a/amqtt/broker.py +++ b/amqtt/broker.py @@ -491,7 +491,9 @@ class Broker: self._sessions[client_session.client_id] = (client_session, handler) await handler.mqtt_connack_authorize(authenticated) - await self.plugins_manager.fire_event(BrokerEvents.CLIENT_CONNECTED, client_id=client_session.client_id) + await self.plugins_manager.fire_event(BrokerEvents.CLIENT_CONNECTED, + client_id=client_session.client_id, + client_session=client_session) self.logger.debug(f"{client_session.client_id} Start messages handling") await handler.start() @@ -594,7 +596,9 @@ class Broker: self.logger.debug(f"{client_session.client_id} Disconnecting session") await self._stop_handler(handler) client_session.transitions.disconnect() - await self.plugins_manager.fire_event(BrokerEvents.CLIENT_DISCONNECTED, client_id=client_session.client_id) + await self.plugins_manager.fire_event(BrokerEvents.CLIENT_DISCONNECTED, + client_id=client_session.client_id, + client_session=client_session) async def _handle_subscription( diff --git a/amqtt/plugins/sys/broker.py b/amqtt/plugins/sys/broker.py index b0ba07f..ceaf608 100644 --- a/amqtt/plugins/sys/broker.py +++ b/amqtt/plugins/sys/broker.py @@ -225,7 +225,7 @@ class BrokerSysPlugin(BasePlugin[BrokerContext]): if packet.fixed_header.packet_type == PUBLISH: self._stats[STAT_PUBLISH_SENT] += 1 - async def on_broker_client_connected(self, client_id: str) -> None: + async def on_broker_client_connected(self, client_id: str, client_session: Session) -> None: """Handle broker client connection.""" self._stats[STAT_CLIENTS_CONNECTED] += 1 self._stats[STAT_CLIENTS_MAXIMUM] = max( @@ -233,7 +233,7 @@ class BrokerSysPlugin(BasePlugin[BrokerContext]): self._stats[STAT_CLIENTS_CONNECTED], ) - async def on_broker_client_disconnected(self, client_id: str) -> None: + async def on_broker_client_disconnected(self, client_id: str, client_session: Session) -> None: """Handle broker client disconnection.""" self._stats[STAT_CLIENTS_CONNECTED] -= 1 self._stats[STAT_CLIENTS_DISCONNECTED] += 1 diff --git a/docs/custom_plugins.md b/docs/custom_plugins.md index 34eb4ec..c3357a7 100644 --- a/docs/custom_plugins.md +++ b/docs/custom_plugins.md @@ -36,8 +36,8 @@ implements one or more of these methods: - `async def on_broker_pre_shutdown() -> None` - `async def on_broker_post_shutdown() -> None` -- `async def on_broker_client_connected(self, client_id:str) -> None` -- `async def on_broker_client_disconnected(self, client_id:str) -> None` +- `async def on_broker_client_connected(self, client_id:str, client_session:Session) -> None` +- `async def on_broker_client_disconnected(self, client_id:str, client_session:Session) -> None` - `async def on_broker_client_subscribed(self, client_id: str, topic: str, qos: int) -> None` - `async def on_broker_client_unsubscribed(self, client_id: str, topic: str) -> None`