public async Task ConnectAsync(string input, global::ryu_s.BrowserCookie.IBrowserProfile browserProfile) { if (_cts != null) { throw new InvalidOperationException("_cts is not null!"); } _cts = new CancellationTokenSource(); CanConnect = false; CanDisconnect = true; Connected?.Invoke(this, new ConnectedEventArgs { IsInputStoringNeeded = false, }); while (!_cts.IsCancellationRequested) { try { await Task.Delay(1000, _cts.Token); } catch (TaskCanceledException) { break; } } CanConnect = true; CanDisconnect = false; _cts = null; }
public Task <ICurrentUserInfo> GetCurrentUserInfo(global::ryu_s.BrowserCookie.IBrowserProfile browserProfile) { ICurrentUserInfo info = new CurrentUserInfo { Username = "******", IsLoggedIn = true, }; return(Task.FromResult(info)); }
public async Task ConnectAsync(string input, global::ryu_s.BrowserCookie.IBrowserProfile browserProfile) { var broadcasterId = Tools.ExtractBroadcasterId(input); _broadcasterId = broadcasterId; if (string.IsNullOrEmpty(broadcasterId)) { //Info return; } _cc = CreateCookieContainer(browserProfile); CanConnect = false; CanDisconnect = true; _first.Reset(); int cnum = -1; string audienceId; try { var(context, contextRaw) = await API.GetLiveContext(_server, broadcasterId, _cc); cnum = context.MovieCnum; _liveId = context.MovieId; Connected?.Invoke(this, new ConnectedEventArgs { IsInputStoringNeeded = true, UrlToRestore = broadcasterId, }); if (!string.IsNullOrEmpty(context.AudienceId)) { audienceId = context.AudienceId; SendSystemInfo($"ログイン済みユーザID:{audienceId}", InfoType.Notice); IsLoggedIn = true; } else { SendSystemInfo("未ログイン", InfoType.Notice); IsLoggedIn = false; } } catch (HttpRequestException ex) { _logger.LogException(ex); string message; if (ex.InnerException != null) { message = ex.InnerException.Message; } else { message = ex.Message; } SendSystemInfo(message, InfoType.Debug); } catch (InvalidBroadcasterIdException ex) { _logger.LogException(ex, "", $"input=\"{input}\""); SendSystemInfo("入力されたURLまたはIDは存在しないか無効な値です", InfoType.Notice); } catch (Exception ex) { Debug.WriteLine(ex.Message); _logger.LogException(ex); SendSystemInfo(ex.Message, InfoType.Debug); } if (cnum < 0 || _liveId < 0) { AfterDisconnected(); return; } try { _messageProvider = new MessageProvider(_server, _siteOptions, _cc, _userStoreManager, _options, this, _logger) { SiteContextGuid = SiteContextGuid, }; _messageProvider.MetaReceived += MessageProvider_MetaReceived; _messageProvider.MessageReceived += MessageProvider_MessageReceived; _messageProvider.InfoOccured += MessageProvider_InfoOccured; await _messageProvider.ConnectAsync(broadcasterId, cnum, _liveId); } catch (Exception ex) { SendSystemInfo(ex.Message, InfoType.Error); _logger.LogException(ex); } finally { AfterDisconnected(); } }