private async Task EndCommentClientConnection() { if (_NicoLiveCommentClient != null) { await _NicoLiveCommentClient.Stop(); _NicoLiveCommentClient.CommentServerConnected -= _NicoLiveCommentReciever_CommentServerConnected; _NicoLiveCommentClient.CommentPosted -= _NicoLiveCommentReciever_CommentPosted; _NicoLiveCommentClient.Dispose(); _NicoLiveCommentClient = null; } }
private async Task StartCommentClientConnection() { await EndCommentClientConnection(); var baseTime = PlayerStatusResponse.Program.BaseAt; _NicoLiveCommentClient = new NicoLiveCommentClient(LiveId, PlayerStatusResponse.Program.CommentCount, baseTime, PlayerStatusResponse.Comment.Server, HohoemaApp.NiconicoContext); _NicoLiveCommentClient.CommentServerConnected += _NicoLiveCommentReciever_CommentServerConnected; _NicoLiveCommentClient.Heartbeat += _NicoLiveCommentClient_Heartbeat; _NicoLiveCommentClient.EndConnect += _NicoLiveCommentClient_EndConnect; _NicoLiveCommentClient.CommentRecieved += _NicoLiveCommentReciever_CommentRecieved; _NicoLiveCommentClient.OperationCommandRecieved += _NicoLiveCommentClient_OperationCommandRecieved; await _NicoLiveCommentClient.Start(); }
private async void _NicoLiveCommentClient_OperationCommandRecieved(NicoLiveCommentClient sender, NicoLiveOperationCommandEventArgs args) { await HohoemaApp.UIDispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() => { switch (args.CommandType) { case NicoLiveOperationCommandType.Play: break; case NicoLiveOperationCommandType.PlaySound: break; case NicoLiveOperationCommandType.PermanentDisplay: if (args.Arguments.Length > 0) { PermanentDisplayText = args.Arguments[0]; } break; case NicoLiveOperationCommandType.ClearPermanentDisplay: PermanentDisplayText = null; break; case NicoLiveOperationCommandType.Vote: break; case NicoLiveOperationCommandType.CommentMode: break; case NicoLiveOperationCommandType.Call: break; case NicoLiveOperationCommandType.Free: break; case NicoLiveOperationCommandType.Reset: // 動画接続のリセット await RetryRtmpConnection(); break; case NicoLiveOperationCommandType.Info: // 1:市場登録 2:コミュニティ参加 3:延長 4,5:未確認 6,7:地震速報 8:現在の放送ランキングの順位 // /info 数字 "表示内容" if (args.Arguments.Length >= 2) { int infoType; if (int.TryParse(args.Arguments[0], out infoType)) { var nicoLiveInfoType = (NicoLiveInfoType)infoType; args.Chat.Text = args.Arguments[1]; args.Chat.Mail = "shita"; _LiveComments.Add(args.Chat); } } break; case NicoLiveOperationCommandType.Press: // http://dic.nicovideo.jp/a/%E3%83%90%E3%83%83%E3%82%AF%E3%82%B9%E3%83%86%E3%83%BC%E3%82%B8%E3%83%91%E3%82%B9 // TODO: BSPユーザーによるコメントに対応 // BSPコメへの風当たりはやや強いのでオプションでON/OFF切り替え対応必要かも if (args.Arguments.Length >= 4) { args.Chat.Mail = args.Arguments[1]; args.Chat.Text = args.Arguments[2]; //var name = args.Arguments[3]; _LiveComments.Add(args.Chat); } break; case NicoLiveOperationCommandType.Disconnect: // 放送者側からの切断要請 // Note: RTMPによる動画受信の停止はDisconnect後の // RtmpClient.Closedイベントによって処理されます。 // また、RtmpClientがクローズ中にここでRtmpClient.Close()を行うと // スレッドセーフではないためか、例外が発生します。 await CloseRtmpConnection(); await Task.Delay(500); // 次枠の自動巡回を開始 // await StartNextLiveSubscribe(DefaultNextLiveSubscribeDuration); break; case NicoLiveOperationCommandType.Koukoku: break; case NicoLiveOperationCommandType.Telop: /* * on ニコ生クルーズ(リンク付き)/ニコニコ実況コメント * show クルーズが到着/実況に接続 * show0 実際に流れているコメント * perm ニコ生クルーズが去って行きました<改行>(降りた人の名前、人数) * off (プレイヤー下部のテロップを消去) */ if (args.Arguments.Length >= 2) { // TODO: } break; case NicoLiveOperationCommandType.Hidden: break; case NicoLiveOperationCommandType.CommentLock: break; default: break; } }); }