mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-01-24 08:14:14 +03:00
Expose MtProtoSender.is_connected() and use it on .connect()
This commit is contained in:
parent
05a8723d36
commit
58fe39f060
|
@ -103,15 +103,8 @@ class TelegramBareClient:
|
|||
If 'exported_auth' is not None, it will be used instead to
|
||||
determine the authorization key for the current session.
|
||||
"""
|
||||
if self._sender and self._sender.is_connected():
|
||||
# Try sending a ping to make sure we're connected already
|
||||
# TODO Maybe there's a better way to check this
|
||||
try:
|
||||
self(PingRequest(utils.generate_random_long()))
|
||||
return True
|
||||
except:
|
||||
# If ping failed, ensure we're disconnected first
|
||||
self.disconnect()
|
||||
if self.is_connected():
|
||||
return True
|
||||
|
||||
connection = Connection(
|
||||
self.session.server_address, self.session.port,
|
||||
|
@ -168,6 +161,9 @@ class TelegramBareClient:
|
|||
)
|
||||
return False
|
||||
|
||||
def is_connected(self):
|
||||
return self._sender is not None and self._sender.is_connected()
|
||||
|
||||
def _init_connection(self, query=None):
|
||||
result = self(InvokeWithLayerRequest(LAYER, InitConnectionRequest(
|
||||
api_id=self.api_id,
|
||||
|
|
Loading…
Reference in New Issue
Block a user