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

Commit

Permalink
Core: allow re-connecting from same TelegramClient
Browse files Browse the repository at this point in the history
If the connection dropped, there was no way to reconnect from the same
instance of TelegramClient.
  • Loading branch information
knocte committed Apr 10, 2020
1 parent b961897 commit f25058d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions TLSharp.Core/TelegramClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class TelegramClient : IDisposable
private string apiHash = String.Empty;
private int apiId = 0;
private Session session;
private string sessionUserId;
private ISessionStore store;
private List<TLDcOption> dcOptions;
private TcpClientConnectionHandler handler;
private DataCenterIPVersion dcIpVersion;
Expand Down Expand Up @@ -58,20 +60,22 @@ public TelegramClient(int apiId, string apiHash,

if (store == null)
store = new FileSessionStore();
this.store = store;

this.apiHash = apiHash;
this.apiId = apiId;
this.handler = handler;
this.dcIpVersion = dcIpVersion;

session = Session.TryLoadOrCreateNew(store, sessionUserId);
transport = new TcpTransport (session.DataCenter.Address, session.DataCenter.Port, this.handler);
this.sessionUserId = sessionUserId;
}

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

session = Session.TryLoadOrCreateNew (store, sessionUserId);
transport = new TcpTransport (session.DataCenter.Address, session.DataCenter.Port, this.handler);

if (session.AuthKey == null || reconnect)
{
var result = await Authenticator.DoAuthentication(transport, token).ConfigureAwait(false);
Expand Down

0 comments on commit f25058d

Please sign in to comment.