/// <summary> /// Connects to the league client api. /// </summary> /// <returns>A new instance of <see cref="LeagueAPI" /> that's connected to the client api.</returns> public async Task <PykeAPI> ConnectAsync() { var(port, token, processId) = await GetAuthCredentialsAsync().ConfigureAwait(false); this.ProcessId = processId; var eventHandler = new LeagueEventHandler(port, token); var api = new PykeAPI(port, token, eventHandler, _processHandler, _lockFileHandler, logger); return(await EnsureConnectionAsync(api).ConfigureAwait(false)); }
/// <summary> /// Ensures the connection is successful by sending a test request. /// </summary> /// <param name="api">The league client api.</param> /// <returns>The league client api.</returns> private async Task <PykeAPI> EnsureConnectionAsync(PykeAPI api) { while (true) { try { await api.RequestHandler.GetResponseAsync <string>(HttpMethod.Get, "/riotclient/app-name").ConfigureAwait(false); await Task.Run(() => api.EventHandler.Connect()).ConfigureAwait(false); return(api); } catch (Exception ex) { logger.Error("Failed to connect to the League Client\n" + ex.Message); await Task.Delay(100).ConfigureAwait(false); } } }