/// <summary> /// ニコ生へのコメント送信の有効性を保つために /// LiveAPIのハートビートへ定期的にアクセスする<br /> /// </summary> /// <returns></returns> /// <remarks>https://www59.atwiki.jp/nicoapi/pages/19.html</remarks> private async Task TryHeartbeat() { using (var releaser = await _HeartbeatTimerLock.LockAsync()) { if (LiveId == null) { return; } try { var res = await NiconicoContext.Live.HeartbeatAsync(LiveId); Debug.WriteLine("heartbeat to " + LiveId); await HohoemaApp.UIDispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { // TODO: 視聴者数やコメント数の更新 CommentCount = res.CommentCount; WatchCount = res.WatchCount; Heartbeat?.Invoke(res.CommentCount, res.WatchCount); }); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); // ハートビートに失敗した場合は、放送終了か追い出された EndConnect?.Invoke(); } } }
/// <summary> /// ニコ生へのコメント送信の有効性を保つために /// LiveAPIのハートビートへ定期的にアクセスする<br /> /// </summary> /// <returns></returns> /// <remarks>https://www59.atwiki.jp/nicoapi/pages/19.html</remarks> private async Task TryHeartbeat() { using (var releaser = await _HeartbeatTimerLock.LockAsync()) { if (LiveId == null) { return; } try { var res = await NicoLiveProvider.HeartbeatAsync(LiveId); Debug.WriteLine("heartbeat to " + LiveId); // 視聴者数やコメント数の更新 CommentCount = res.CommentCount; WatchCount = res.WatchCount; Heartbeat?.Invoke(res.CommentCount, res.WatchCount); } catch (Exception ex) when(ex.Message.Contains("NOTFOUND_SLOT")) { // await Stop(); //EndConnect?.Invoke(NicoLiveDisconnectReason.NotFoundSlot); } catch (Exception ex) { Close(); Debug.WriteLine(ex.ToString()); // ハートビートに失敗した場合は、放送終了か追い出された EndConnect?.Invoke(NicoLiveDisconnectReason.Close); } } }