File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -37,6 +37,9 @@ class ConnectHandler(Handler):
3737 client (:obj:`~pyrogram.Client`):
3838 The Client itself. Useful, for example, when you want to change the proxy before a new connection
3939 is established.
40+
41+ session (:obj:`~pyrogram.session.Session`):
42+ The Session used for the connection.
4043 """
4144
4245 def __init__ (self , callback : Callable ):
Original file line number Diff line number Diff line change @@ -37,6 +37,9 @@ class DisconnectHandler(Handler):
3737 client (:obj:`~pyrogram.Client`):
3838 The Client itself. Useful, for example, when you want to change the proxy before a new connection
3939 is established.
40+
41+ session (:obj:`~pyrogram.session.Session`):
42+ The Session used for the connection.
4043 """
4144
4245 def __init__ (self , callback : Callable ):
Original file line number Diff line number Diff line change @@ -146,12 +146,6 @@ async def start(self):
146146
147147 self .ping_task = self .client .loop .create_task (self .ping_worker ())
148148
149- if not self .is_media and callable (self .client .connect_handler ):
150- try :
151- await self .client .connect_handler (self .client )
152- except Exception as e :
153- log .exception (e )
154-
155149 log .info ("Session initialized: Pyrogram v%s (Layer %s)" , pyrogram .__version__ , layer )
156150 log .info ("Device: %s - %s" , self .client .device_model , self .client .app_version )
157151 log .info ("System: %s (%s)" , self .client .system_version , self .client .lang_code )
@@ -173,7 +167,19 @@ async def start(self):
173167
174168 log .info ("Session started" )
175169
170+ if callable (self .client .connect_handler ):
171+ try :
172+ await self .client .connect_handler (self .client , self )
173+ except Exception as e :
174+ log .exception (e )
175+
176176 async def stop (self ):
177+ if callable (self .client .disconnect_handler ):
178+ try :
179+ await self .client .disconnect_handler (self .client , self )
180+ except Exception as e :
181+ log .exception (e )
182+
177183 self .is_started .clear ()
178184
179185 self .stored_msg_ids .clear ()
@@ -190,12 +196,6 @@ async def stop(self):
190196 if self .recv_task :
191197 await self .recv_task
192198
193- if not self .is_media and callable (self .client .disconnect_handler ):
194- try :
195- await self .client .disconnect_handler (self .client )
196- except Exception as e :
197- log .exception (e )
198-
199199 log .info ("Session stopped" )
200200
201201 async def restart (self ):
You can’t perform that action at this time.
0 commit comments