feat(stream): one-click Back on air — a new broadcast, honestly labelled (TASK 32·3)

The last resilience slice. When a drop ends the broadcast, YouTube cannot resume it, so the only way
back is a new one — and that is what the app now offers, in one click.

- `Services/BroadcastTitle.cs` — the resume marker is applied to the title the show was using, and any
  existing marker is REPLACED rather than stacked ("Show (resumed)" → "Show (resumed 2)"), with the base
  truncated so the whole title fits YouTube's 100-character limit. Otherwise a channel grows two
  identically named videos and the creator has to explain it.
- `MainViewModel.BackOnAirCommand` — reuses the ordinary go-live path with the saved details and the
  cached stream: new broadcast, new VOD, no dialog. It appears only after a drop ended the session and
  the ordinary start button steps aside, so there is exactly one way forward.
- The running line goes red OFF AIR (not amber) in that state; the button reads "● Back on air".

Tests: `BackOnAirTests` — first re-air marks the title, a second drop counts instead of stacking, the
100-character limit holds, an empty title still works, and the post-drop state exposes exactly one
start affordance. FAST gate: 552 passed, 0 failed, 0 warnings.

TASK 32 is now complete: fragmented MP4, blip retry, poll-driven RECONNECTING, ingest pre-flight, Back
on air.
This commit is contained in:
2026-11-05 14:59:00 -08:00
parent ec1091a170
commit dd51f7842a
6 changed files with 176 additions and 2 deletions
+9
View File
@@ -107,6 +107,15 @@
<Button Content="{Binding PrimaryStartButtonLabel}" Style="{StaticResource YtButton}"
Height="32" Margin="10,0,0,0" Command="{Binding PrimaryStartCommand}"
Visibility="{Binding ShowPrimaryStartButton, Converter={StaticResource BoolToVis}}"/>
<!-- TASK 32·3: the drop ended this broadcast. YouTube cannot resume a completed one, so
the only honest action is a new broadcast — one click, saved details, and the title
says it is a resume so the channel shows what happened. -->
<Button x:Name="BackOnAirButton" Content="{Binding BackOnAirLabel}"
Style="{StaticResource YtButton}" Height="32" Margin="10,0,0,0"
Background="{StaticResource Brush.Primary}"
Command="{Binding BackOnAirCommand}"
ToolTip="Start a new broadcast from your saved details — this begins a new video"
Visibility="{Binding IsOffAirAfterDrop, Converter={StaticResource BoolToVis}}"/>
<!-- No separate TEST button (creator ruling 2026-10-30): EDIT decides whether
the ON-AIR start is the real livestream or the test one. -->
</StackPanel>
+33
View File
@@ -0,0 +1,33 @@
using System;
using System.Text.RegularExpressions;
namespace ytLive.Services;
/// <summary>
/// TASK 32·3 — naming the broadcast that resumes a dropped show. A resumed stream is a NEW broadcast
/// with a new VOD (YouTube cannot resume a completed one), so the title has to say so; otherwise the
/// channel grows two identically named videos and the creator has to explain it.
/// <para>Pure, because the interesting cases are the boring ones: a title already marked, a second drop
/// in the same session, and YouTube's 100-character limit.</para>
/// </summary>
public static class BroadcastTitle
{
public const int MaxLength = 100;
private static readonly Regex ResumeMarker =
new(@"\s*\(resumed(?: \d+)?\)\s*$", RegexOptions.IgnoreCase | RegexOptions.Compiled);
/// <summary>The title for resume number <paramref name="resumeCount"/> (1 = first re-air).
/// Any existing marker is replaced rather than stacked, and the base is truncated so the whole
/// title fits YouTube's limit.</summary>
public static string ForResume(string? title, int resumeCount)
{
var baseTitle = ResumeMarker.Replace(title ?? string.Empty, string.Empty).Trim();
if (baseTitle.Length == 0) baseTitle = "LlamaCasty";
var marker = resumeCount <= 1 ? " (resumed)" : $" (resumed {Math.Max(2, resumeCount)})";
var room = MaxLength - marker.Length;
if (baseTitle.Length > room) baseTitle = baseTitle[..room].TrimEnd();
return baseTitle + marker;
}
}
+6 -1
View File
@@ -39,9 +39,14 @@ the API — creator ruling 2026-09-01): no lying in the copy.
Test: a fake status provider drives the sign through live → reconnecting → off air; a `chatEndedEvent`
triggers an immediate status check rather than a decision of its own.
3. ☐ **One-click Back on air** — the relabeled button fires the existing go-live path with saved
3. ✅ **One-click Back on air** (shipped 2026-11-05) — the relabeled button fires the existing go-live path with saved
`Broadcast.*` + cached stream, dialog skipped: new broadcast, new VOD (accepted cost, stated
in-product). Test: seeded saved form + fake stream service → click creates + pushes, no dialog.
**Shipped:** `Services/BroadcastTitle.cs` (pure — resume marker replaces rather than stacks, base
truncated to YouTube's 100 characters) and `MainViewModel.BackOnAirCommand`, which reuses the ordinary
go-live path with the saved details and the cached stream: new broadcast, new VOD, no dialog. The
button appears only after a drop ended the session, in place of the normal start button, and the
ordinary start button steps aside so there is exactly one way forward. Tests: `BackOnAirTests`.
4. ✅ **Crash-safe recording** (shipped 2026-11-05) — fragmented MP4 on the record block (`-movflags
frag_keyframe+empty_moov+default_base_moof`): plain MP4's trailing moov atom means a power loss
kills the WHOLE file. Rename-on-stop unchanged. Closes the TASK 18 "MKV as an option" design-note
+62
View File
@@ -34,6 +34,63 @@ public partial class MainViewModel
private bool _isReconnecting;
/// <summary>True after a drop ended the session with the broadcast gone: the show is over and the
/// only honest action left is a new broadcast. Drives the red OFF AIR line and the
/// "Back on air" button (TASK 32·3).</summary>
public bool IsOffAirAfterDrop
{
get => _isOffAirAfterDrop;
private set
{
if (!SetProperty(ref _isOffAirAfterDrop, value)) return;
RaiseTopBarModes();
OnPropertyChanged(nameof(ShowPrimaryStartButton));
OnPropertyChanged(nameof(BackOnAirLabel));
}
}
private bool _isOffAirAfterDrop;
public string BackOnAirLabel => "● Back on air";
private RelayCommand? _backOnAirCommand;
/// <summary>One click: build a new broadcast from the saved details and push — no dialog, and the
/// title carries the resume marker so the channel shows what happened.</summary>
public RelayCommand BackOnAirCommand =>
_backOnAirCommand ??= new RelayCommand(_ => BackOnAir(), _ => IsOffAirAfterDrop && IsOffline);
/// <summary>How many times this session has been resumed — the title marker counts.</summary>
private int _resumeCount;
/// <summary>The title the dropped show was using, kept so the resumed broadcast is named after it
/// rather than after whatever the form happens to hold now.</summary>
private string? _lastLiveTitle;
private void BackOnAir()
{
if (!IsOffAirAfterDrop) return;
_resumeCount++;
StreamTitle = BroadcastTitle.ForResume(_lastLiveTitle ?? StreamTitle, _resumeCount);
WindowTitle = $"{StreamTitle} — LlamaCasty";
// Clear the state BEFORE starting: the go-live path reuses the primary-button gate, and a
// session that starts while this flag is set would show two ways to start at once.
IsOffAirAfterDrop = false;
AppLog.Write($"RECONNECT: back on air as a new broadcast — '{StreamTitle}'");
OnAirPillOn = true;
StartStreamingSession(alsoRecord: false); // the ordinary path: new broadcast, same cached stream
}
/// <summary>Test seam: puts the view-model in the post-drop state without a live session.</summary>
internal void MarkOffAirAfterDropForTest(string? title)
{
_lastLiveTitle = title;
IsOffAirAfterDrop = true;
}
/// <summary>The attempt currently in flight (0 when idle).</summary>
public int ReconnectAttempt
{
@@ -184,9 +241,14 @@ public partial class MainViewModel
default:
// Gave up, or the broadcast was already complete: this session is over. The alert
// stack keeps the reason; the normal stop path clears pills, audio and recording.
// Then the honest next step is offered as one click — a NEW broadcast (TASK 32·3),
// which is the only way back on air once YouTube has completed this one.
AppLog.Write("RECONNECT: session ended — the broadcast could not be recovered",
AppLogMessageType.Error, AppLogErrorClass.Class1);
var droppedTitle = StreamTitle;
StopStream();
MarkOffAirAfterDropForTest(null);
_lastLiveTitle = droppedTitle;
break;
}
}
+1 -1
View File
@@ -175,7 +175,7 @@ public partial class MainViewModel : ViewModelBase
/// and the old gate needed a sign-in or a lit pill — signed-out creators found a
/// blank bar). No dead ends: an unarmed Start records (local needs no account);
/// sign-in lives in the Start context menu.</summary>
public bool ShowPrimaryStartButton => IsOffline && !IsRecording;
public bool ShowPrimaryStartButton => IsOffline && !IsRecording && !IsOffAirAfterDrop;
/// <summary>Either output selected makes the button actionable.</summary>
public bool CanStartSession => RecordPillOn || OnAirPillOn;
+65
View File
@@ -0,0 +1,65 @@
using System;
using System.IO;
using Microsoft.Data.Sqlite;
using Xunit;
using ytLive.Services;
using ytLive.ViewModels;
namespace ytLive.Tests;
/// <summary>
/// TASK 32·3 — Back on air. Once YouTube completes a broadcast it cannot be resumed, so the only honest
/// route back is a NEW broadcast: one click, saved details, no dialog, and a title that says it is a
/// resume (otherwise the channel grows two identically named videos).
/// </summary>
public class BackOnAirTests
{
[Fact]
public void ResumeTitle_MarksTheFirstReAir()
=> Assert.Equal("Friday Night Show (resumed)", BroadcastTitle.ForResume("Friday Night Show", 1));
[Fact]
public void ResumeTitle_CountsASecondDrop_InsteadOfStackingMarkers()
=> Assert.Equal("Friday Night Show (resumed 2)", BroadcastTitle.ForResume("Friday Night Show (resumed)", 2));
[Fact]
public void ResumeTitle_FitsYouTubesHundredCharacterLimit()
{
var longTitle = new string('x', 140);
var resumed = BroadcastTitle.ForResume(longTitle, 1);
Assert.Equal(BroadcastTitle.MaxLength, resumed.Length);
Assert.EndsWith(" (resumed)", resumed);
}
[Fact]
public void ResumeTitle_HandlesAnEmptyTitle()
=> Assert.Equal("LlamaCasty (resumed)", BroadcastTitle.ForResume(" ", 1));
[Fact]
public void AfterADrop_TheCreatorIsOfferedOneClickBackOnAir()
{
var tempDb = Path.Combine(Path.GetTempPath(), $"ytLlive-backonair-{Guid.NewGuid():N}.db");
MainViewModel.LayoutPathOverride = tempDb;
var vm = new MainViewModel();
try
{
Assert.False(vm.IsOffAirAfterDrop);
Assert.False(vm.BackOnAirCommand.CanExecute(null));
vm.MarkOffAirAfterDropForTest("Friday Night Show");
Assert.True(vm.IsOffAirAfterDrop);
Assert.True(vm.BackOnAirCommand.CanExecute(null));
Assert.Equal("● Back on air", vm.BackOnAirLabel);
// The ordinary start button steps aside so there is exactly one way forward.
Assert.False(vm.ShowPrimaryStartButton);
}
finally
{
MainViewModel.LayoutPathOverride = null;
SqliteConnection.ClearAllPools();
try { File.Delete(tempDb); } catch { /* best-effort cleanup */ }
}
}
}