feat(stream): RECONNECTING driven by the status poll — no invented countdown (TASK 32·2)
Creator challenge (2026-11-05): "I really don't think that's going to be a constant — it's going to
depend on so many variables, some that are dark to us." Correct, so the measured-grace constant and
the countdown are dropped from the spec. YouTube's cutoff is server-side and depends on ingest health,
prior stream quality, region and load; a pinned number would be a guess wearing a timer, and it would
be wrong exactly when the creator is staring at it.
What ships instead:
- **Amber RECONNECTING** in the top bar with measured facts only: elapsed seconds and the attempt
number ("0:12 · attempt 2 of 4"). The seconds come from a stopwatch started at the drop.
- **The status poll speeds up while recovering** (30 s → 4 s) and drives the sign; it restores 30 s
when recovery ends.
- **`chatEndedEvent`** — already in the chat feed we poll and previously skipped — now raises a signal
that prompts an immediate status check. It never decides anything: `liveBroadcasts.list`
`lifeCycleStatus` stays authoritative, with `liveStreams.list` health as the push-received signal.
- At `complete`: red OFF AIR (the existing stop path) rather than a pretend-live sign.
Tests: `ChatEndedSignalTests` (the marker is not a chat row, the service raises the signal, and a
complete broadcast ends recovery with the honest message). FAST gate: 543 passed, 0 warnings.
This commit is contained in:
@@ -19,11 +19,79 @@ public partial class MainViewModel
|
||||
{
|
||||
private CancellationTokenSource? _recoveryCts;
|
||||
|
||||
/// <summary>True while a push is being relaunched — slice 2 binds the amber sign to this.</summary>
|
||||
public bool IsReconnecting { get; private set; }
|
||||
/// <summary>True while a push is being relaunched — the top bar shows amber RECONNECTING.</summary>
|
||||
public bool IsReconnecting
|
||||
{
|
||||
get => _isReconnecting;
|
||||
private set
|
||||
{
|
||||
if (!SetProperty(ref _isReconnecting, value)) return;
|
||||
RaiseTopBarModes();
|
||||
OnPropertyChanged(nameof(ReconnectDetailText));
|
||||
ApplyReconnectPollCadence();
|
||||
}
|
||||
}
|
||||
|
||||
private bool _isReconnecting;
|
||||
|
||||
/// <summary>The attempt currently in flight (0 when idle).</summary>
|
||||
public int ReconnectAttempt { get; private set; }
|
||||
public int ReconnectAttempt
|
||||
{
|
||||
get => _reconnectAttempt;
|
||||
private set
|
||||
{
|
||||
if (!SetProperty(ref _reconnectAttempt, value)) return;
|
||||
OnPropertyChanged(nameof(ReconnectDetailText));
|
||||
}
|
||||
}
|
||||
|
||||
private int _reconnectAttempt;
|
||||
|
||||
/// <summary>Whole seconds since the drop — measured, never predicted.</summary>
|
||||
public int ReconnectElapsedSeconds
|
||||
{
|
||||
get => _reconnectElapsedSeconds;
|
||||
private set
|
||||
{
|
||||
if (!SetProperty(ref _reconnectElapsedSeconds, value)) return;
|
||||
OnPropertyChanged(nameof(ReconnectDetailText));
|
||||
}
|
||||
}
|
||||
|
||||
private int _reconnectElapsedSeconds;
|
||||
private System.Windows.Threading.DispatcherTimer? _reconnectTick;
|
||||
|
||||
/// <summary>While recovering, ask YouTube much more often — the status IS the sign, so it has to
|
||||
/// keep up with a reconnect that can succeed or die inside a few seconds.</summary>
|
||||
private void ApplyReconnectPollCadence()
|
||||
{
|
||||
if (IsReconnecting)
|
||||
{
|
||||
_healthPollTimer.Interval = TimeSpan.FromSeconds(4);
|
||||
_reconnectTick ??= new System.Windows.Threading.DispatcherTimer
|
||||
{
|
||||
Interval = TimeSpan.FromSeconds(1),
|
||||
};
|
||||
_reconnectTick.Tick -= OnReconnectTick;
|
||||
_reconnectTick.Tick += OnReconnectTick;
|
||||
_reconnectTick.Start();
|
||||
}
|
||||
else
|
||||
{
|
||||
_healthPollTimer.Interval = TimeSpan.FromSeconds(30);
|
||||
if (_reconnectTick != null)
|
||||
{
|
||||
_reconnectTick.Stop();
|
||||
_reconnectTick.Tick -= OnReconnectTick;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnReconnectTick(object? sender, EventArgs e)
|
||||
=> ReconnectElapsedSeconds = (int)Math.Round(_reconnectStarted?.Elapsed.TotalSeconds ?? 0);
|
||||
|
||||
// Measured from the drop, so the displayed seconds are facts rather than a projection.
|
||||
private System.Diagnostics.Stopwatch? _reconnectStarted;
|
||||
|
||||
private void OnEncoderFailed(object? sender, string message)
|
||||
{
|
||||
@@ -38,8 +106,11 @@ public partial class MainViewModel
|
||||
|
||||
private async Task RecoverStreamAsync(string reason, CancellationToken cancellationToken)
|
||||
{
|
||||
ReconnectElapsedSeconds = 0;
|
||||
_reconnectStarted = System.Diagnostics.Stopwatch.StartNew();
|
||||
IsReconnecting = true;
|
||||
ReconnectAttempt = 0;
|
||||
var dropped = _reconnectStarted;
|
||||
|
||||
var logFrom = AppLog.SnapshotCurrentLaunch().Count > 0
|
||||
? AppLog.SnapshotCurrentLaunch()[^1].Sequence + 1
|
||||
@@ -126,6 +197,7 @@ public partial class MainViewModel
|
||||
}
|
||||
finally
|
||||
{
|
||||
_reconnectStarted = null;
|
||||
IsReconnecting = false;
|
||||
ReconnectAttempt = 0;
|
||||
_recoveryCts?.Dispose();
|
||||
@@ -145,4 +217,13 @@ public partial class MainViewModel
|
||||
|
||||
/// <summary>The creator asked to stop: never race a stop against a relaunch.</summary>
|
||||
private void CancelStreamRecovery() => _recoveryCts?.Cancel();
|
||||
|
||||
/// <summary>YouTube ended the chat: ask the broadcast status now rather than at the next tick.
|
||||
/// The API decides — this signal only saves up to 30 s of lying to the creator.</summary>
|
||||
private void OnChatEnded()
|
||||
{
|
||||
if (!IsLive) return;
|
||||
AppLog.Write("Chat ended event received — checking the broadcast status now");
|
||||
_ = PollHealthAsync();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,16 +271,26 @@ public partial class MainViewModel : ViewModelBase
|
||||
|
||||
/// <summary>The reality word: TEST while a test broadcast runs, LIVE while on the
|
||||
/// air, REC during a local-record session.</summary>
|
||||
public string RunningText => IsTestStream ? "TEST" : IsLive ? "LIVE" : "REC";
|
||||
public string RunningText => IsReconnecting
|
||||
? "RECONNECTING"
|
||||
: IsTestStream ? "TEST" : IsLive ? "LIVE" : "REC";
|
||||
|
||||
/// <summary>Measured facts only while reconnecting: how long, and which attempt. No countdown —
|
||||
/// YouTube's cutoff is not a constant we can promise (spec revised 2026-11-05).</summary>
|
||||
public string ReconnectDetailText => IsReconnecting
|
||||
? $"0:{ReconnectElapsedSeconds:00} · attempt {Math.Max(1, ReconnectAttempt)} of {StreamRetryPolicy.Default.Attempts}"
|
||||
: string.Empty;
|
||||
|
||||
/// <summary>Reality dot color, one meaning per mode: gold = test, red = live,
|
||||
/// green = recording. The pre-spec pulsing lamp never shipped; the word + bar
|
||||
/// color carry the state and the dot just pins it.</summary>
|
||||
public string RunningDotBrush => IsTestStream
|
||||
? ThemeBrush.Hex("Brush.TestContainer")
|
||||
: IsLive
|
||||
? ThemeBrush.Hex("Brush.Primary")
|
||||
: ThemeBrush.Hex("Brush.Positive");
|
||||
public string RunningDotBrush => IsReconnecting
|
||||
? ThemeBrush.Hex("Brush.Attention")
|
||||
: IsTestStream
|
||||
? ThemeBrush.Hex("Brush.TestContainer")
|
||||
: IsLive
|
||||
? ThemeBrush.Hex("Brush.Primary")
|
||||
: ThemeBrush.Hex("Brush.Positive");
|
||||
|
||||
/// <summary>Raises every flag the top bar renders, so any state change re-renders
|
||||
/// exactly the world that is now true.</summary>
|
||||
|
||||
@@ -226,6 +226,7 @@ public partial class MainViewModel : ViewModelBase
|
||||
ApplyStreamQuality(_selectedQuality);
|
||||
|
||||
_youtubeChat.MessageReceived += OnChatMessageReceived;
|
||||
_youtubeChat.ChatEnded += OnChatEnded;
|
||||
|
||||
_liveTimer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(1) };
|
||||
_liveTimer.Tick += OnLiveTimerTick;
|
||||
|
||||
Reference in New Issue
Block a user