Skip to content
This repository was archived by the owner on Dec 5, 2021. It is now read-only.

Commit f25058d

Browse files
committed
Core: allow re-connecting from same TelegramClient
If the connection dropped, there was no way to reconnect from the same instance of TelegramClient.
1 parent b961897 commit f25058d

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

TLSharp.Core/TelegramClient.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public class TelegramClient : IDisposable
2929
private string apiHash = String.Empty;
3030
private int apiId = 0;
3131
private Session session;
32+
private string sessionUserId;
33+
private ISessionStore store;
3234
private List<TLDcOption> dcOptions;
3335
private TcpClientConnectionHandler handler;
3436
private DataCenterIPVersion dcIpVersion;
@@ -58,20 +60,22 @@ public TelegramClient(int apiId, string apiHash,
5860

5961
if (store == null)
6062
store = new FileSessionStore();
63+
this.store = store;
6164

6265
this.apiHash = apiHash;
6366
this.apiId = apiId;
6467
this.handler = handler;
6568
this.dcIpVersion = dcIpVersion;
66-
67-
session = Session.TryLoadOrCreateNew(store, sessionUserId);
68-
transport = new TcpTransport (session.DataCenter.Address, session.DataCenter.Port, this.handler);
69+
this.sessionUserId = sessionUserId;
6970
}
7071

7172
public async Task ConnectAsync(bool reconnect = false, CancellationToken token = default(CancellationToken))
7273
{
7374
token.ThrowIfCancellationRequested();
7475

76+
session = Session.TryLoadOrCreateNew (store, sessionUserId);
77+
transport = new TcpTransport (session.DataCenter.Address, session.DataCenter.Port, this.handler);
78+
7579
if (session.AuthKey == null || reconnect)
7680
{
7781
var result = await Authenticator.DoAuthentication(transport, token).ConfigureAwait(false);

0 commit comments

Comments
 (0)