public override async Task ConnectAsync(string input, IBrowserProfile browserProfile) { BeforeConnect(); _first.Reset(); _cc = GetCookieContainer(browserProfile, "twitcasting.tv"); _broadcasterId = Tools.ExtractBroadcasterId(input); _lastCommentId = 0; var(context, contextRaw) = await API.GetLiveContext(_server, _broadcasterId, _cc); if (!string.IsNullOrEmpty(context.AudienceId)) { SendSystemInfo($"ログイン済みユーザID:{context.AudienceId}", InfoType.Notice); IsLoggedIn = true; } else { SendSystemInfo("未ログイン", InfoType.Notice); IsLoggedIn = false; } //配信歴がある場合は初期コメントを取得する if (context.MovieId > 0) { var initialComments = await GetInitialComments(context.MovieId); foreach (var initialComment in initialComments) { RaiseMessageReceived(initialComment); } } var p1 = new WebsocketMessageProvider(new Websocket(), _server); p1.MessageReceived += P1_MessageReceived; var p2 = new MetadataProvider(_logger, _server, _broadcasterId, _messenger); p2.ItemReceived += P2_ItemReceived; p2.LiveIdReceived += P2_LiveIdReceived; p2.MetadataReceived += P2_MetadataReceived; _autoReconnector = new TwicasAutoReconnector(_broadcasterId, _cc, _server, _logger, p1, p2); try { await _autoReconnector.AutoReconnectAsync(); } finally { _autoReconnector = null; AfterDisconnected(); } }
public async Task AutoReconnectAsync() { _isDisconnectCalled = false; while (true) { var(context, contextRaw) = await API.GetLiveContext(_server, _broadcasterId, _cc); var liveId = context.MovieId; if (liveId < 0) { //過去に一度も配信歴が無い return; } _p1.Cc = _cc; _p1.BroadcasterId = _broadcasterId; _p1.LiveId = _currentLiveId ?? liveId; _p1.Master = _p2; //var p = new WebsocketMessageProvider(new Common.Websocket()); //p.MessageReceived += (sender, e) => { Debug.WriteLine(e.Raw); }; //var p2 = new MetadataProvider(_logger, _server, _broadcasterId); var reason = await _connectionManager.ConnectAsync(new List <IProvider> { _p1, _p2 }); if (_newLiveStarted) { _newLiveStarted = false; continue; } else if (_isDisconnectCalled) { break; } } }
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(); } }