feat(video,chat): native player, ad-break awareness, chat send/delay reliability, and tab redesign (#567)
Squash-merge commit. Covers four areas: native video player, chat reliability, multi-tab, and hardening. ## Native video player - Direct HLS playback via `better_native_video_player` (forked from `plug-and-pay/flutter-native-video-player`, patched on `frosty-patches` branch) - Twitch GQL playback token fetching with platform cookie extraction (iOS Swift + Android Kotlin plugins) for authenticated streams - Quality selection (source, 720p, 480p, 360p, 160p, audio-only) persisted per channel - Picture-in-picture: iOS automatic inline PiP, Android auto-PiP on API 31+ guarded against older devices - Latency polling, chat latency sync, stall detection/recovery, startup auto-pause recovery, watchdog timers - **Twitch stitched-ad break detection** (HLS `EXT-X-DATERANGE`) on both platforms, emitting `adBreakChanged` so the host suspends latency/stall recovery and chat sync during ads (program-date-time is unreliable then). Matches `CLASS="twitch-stitched-ad"` / `ID="stitched-ad-"` **and** the `X-TV-TWITCH-AD-*` attribute prefix (the durable signal streamlink/yt-dlp use) - Shared `VideoPlayerInterface` so WebView and native paths are interchangeable via settings toggle - `PlaybackAccessToken` model, `TwitchGqlApi` client ## Chat delay & send reliability - **Optimistic send-finalize**: Twitch acks a sent message with a per-PRIVMSG USERSTATE (not an echo), which it can intermittently drop — more so under a long chat delay. A missing ack no longer shows a false "message may not have been sent" error; the send is finalized optimistically (local echo rendered), and only genuine rejection NOTICEs surface an error. Ack timeout scaled by the chat delay. - **Per-line chat-delay bypass**: control/state lines (USERSTATE/ROOMSTATE/GLOBALUSERSTATE), rejection NOTICEs, the reconnect notice, and untagged server lines bypass the delay so send-acks and PONGs aren't stalled; only displayable chat content is delayed, staying in sync with delayed video. - **Measured chat bottom-bar height**: the message list reflows to the composer's real measured height, fixing the input overlapping messages when a long message expands it (replaces a fixed-constant estimate). - IRC tag parsing handles valueless and escaped tags per the IRCv3 message-tags spec (fixes a recent-messages RangeError on certain tags). ## Chat / multi-tab - Redesigned tab chips: unread dot indicator, chips dim until WebSocket connects - Animated tab options popover replacing `MenuAnchor` (no animation hook in Flutter 3.44) - Simplified `ChatTabs` from `StatefulWidget` to `StatelessWidget` - Focus-current-channel fade bump to 0.55; section-header alpha lifted to match the muted-label tier - `addTab` now calls `setActiveTab` to snapshot outgoing tab's `lastSeenMessageId` — fixes spurious unread dots after adding a tab - `onActivateSourceTab` threaded into `ChatUserModal` so Reply in merged mode switches to the correct source tab's composer ## Bug fixes and hardening - **Reverted the experimental iOS low-latency mode** (5s live-edge join + 1.05x catch-up): AVPlayer can't sustain <~18s on Twitch (declared `TARGETDURATION:6` paces playlist refreshes), and the offset starved the buffer into pause-on-launch. Default join distance restored. - Fork (Android): **cap `BEHIND_LIVE_WINDOW` recovery** so a stream repeatedly falling off the live window can't silently re-prepare forever; emits `error` on exhaustion so the host recovery ladder takes over - Guard all Android `setAutoPipMode` calls with `_autoPipAvailable` — prevents `PlatformException` on Android 8–11; check `_disposed` after `isAutoPipAvailable` await to prevent post-dispose auto-PiP re-enable - Remove `_isInPipMode` guard from `_onPaused` so `_paused` tracks actual state, fixing PiP play/pause toggle getting stuck - Tighten iOS cookie domain check to exact `twitch.tv` / `.twitch.tv` suffix - Invalidate the stored web session token when Twitch rejects it with a 401 (profile card flips back to unlinked; future loads skip the doomed authenticated request), and re-extract the cookie on launch when logged in without a linked session - Send `play_session_id` and `player_backend=mediaplayer` to Usher, matching the web client / streamlink - Fork (iOS): restore program-date-time latency measurement (a prior rev measured distance to the manifest edge, reading ~0s and silently disabling high-latency recovery / chat-delay auto-sync); release platform views on dispose (per-stream view + AVPlayerViewController leak), track the observed AVPlayerItem for KVO removal (sibling-view crash), main-thread seek results, resolve superseded load futures - Fork (Android): clean up method handlers orphaned by PiP-time view disposal (leaked audio-focus listeners), drop the live-offset re-anchoring seekTo on metadata updates (latency creep), restore pre-duck volume, respect user pause in the stall watchdog, resolve superseded load futures - Deep review pass: expire the quality-switch flag so stall recovery isn't disabled for the session, cap latency-driven recovery (clock-skew loop), generation-guard the error overlay, two-strike offline confirmation, controller null-safety on quality switch - Tighten `/me` local-echo match (no longer renders `/meow ...` as an action); clear pending send text on disconnect ## Web / docs - Remove stale Cloudflare Images binding from `wrangler.jsonc` (covered by `images.unoptimized: true`) - Correct `web/AGENTS.md` Cache Components claim (feature not enabled) - Repo and agent config cleanup ## Test plan - [x] `flutter analyze` — clean (frosty + plugin lib) - [x] `flutter test` — 319/319 pass (adds `ChatLatencySync`, `StreamInfoPoller`, video timing invariants, `PlaybackAccessToken`, IRC tag parsing) - [x] Android plugin Kotlin compiles against the bumped fork rev - [ ] Native player plays live streams on iOS and Android - [ ] Quality switching works and persists across channel reopens - [ ] PiP enters/exits correctly; pause/resume toggle in PiP window works - [ ] Audio-only mode does not crash on Android < API 31 - [ ] Sending under a long synced chat delay no longer shows a false "may not have been sent" error - [ ] Long composer text reflows the message list (no input/message overlap) - [ ] Multi-tab: adding a tab does not mark previous tab as unread - [ ] Merged chat: Reply from user modal targets the correct tab's composer 🤖 Generated with [Claude Code](https://claude.com/claude-code)
This commit is contained in:
parent
8883af90f0
commit
f2b932bc93
72 changed files with 7220 additions and 3816 deletions
78
test/models/playback_access_token_test.dart
Normal file
78
test/models/playback_access_token_test.dart
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:frosty/models/playback_access_token.dart';
|
||||
|
||||
Map<String, dynamic> gqlResponse({required String value, String sig = 'sig'}) =>
|
||||
{
|
||||
'data': {
|
||||
'streamPlaybackAccessToken': {'value': value, 'signature': sig},
|
||||
},
|
||||
};
|
||||
|
||||
void main() {
|
||||
group('PlaybackAccessToken.fromGqlResponse', () {
|
||||
test('parses hide_ads and restricted bitrates from token payload', () {
|
||||
final value = jsonEncode({
|
||||
'hide_ads': true,
|
||||
'chansub': {
|
||||
'restricted_bitrates': [
|
||||
'1080p60',
|
||||
'720p60',
|
||||
'chunked',
|
||||
'archives',
|
||||
'sub_archives',
|
||||
'live',
|
||||
'audio_only',
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
final token = PlaybackAccessToken.fromGqlResponse(
|
||||
gqlResponse(value: value),
|
||||
);
|
||||
|
||||
expect(token.value, value);
|
||||
expect(token.signature, 'sig');
|
||||
expect(token.hideAds, isTrue);
|
||||
// chunked/archives/sub_archives/live are playlist-internal names, not
|
||||
// real qualities; names merely containing those words must survive.
|
||||
expect(token.restrictedQualities, [
|
||||
'1080p60',
|
||||
'720p60',
|
||||
'audio_only',
|
||||
]);
|
||||
});
|
||||
|
||||
test('does not filter qualities that merely contain reserved words', () {
|
||||
final value = jsonEncode({
|
||||
'chansub': {
|
||||
'restricted_bitrates': ['1080p60_live', 'olive', 'rearchives'],
|
||||
},
|
||||
});
|
||||
|
||||
final token = PlaybackAccessToken.fromGqlResponse(
|
||||
gqlResponse(value: value),
|
||||
);
|
||||
|
||||
expect(token.restrictedQualities, ['1080p60_live', 'olive', 'rearchives']);
|
||||
});
|
||||
|
||||
test('survives a non-JSON token payload', () {
|
||||
final token = PlaybackAccessToken.fromGqlResponse(
|
||||
gqlResponse(value: 'not-json'),
|
||||
);
|
||||
|
||||
expect(token.value, 'not-json');
|
||||
expect(token.hideAds, isFalse);
|
||||
expect(token.restrictedQualities, isEmpty);
|
||||
});
|
||||
|
||||
test('throws FormatException when token is missing', () {
|
||||
expect(
|
||||
() => PlaybackAccessToken.fromGqlResponse({'data': null}),
|
||||
throwsFormatException,
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
111
test/screens/channel/video/chat_latency_sync_test.dart
Normal file
111
test/screens/channel/video/chat_latency_sync_test.dart
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:frosty/screens/channel/video/chat_latency_sync.dart';
|
||||
import 'package:frosty/screens/channel/video/video_timing_constants.dart';
|
||||
import 'package:frosty/screens/settings/stores/settings_store.dart';
|
||||
|
||||
void main() {
|
||||
// Reference the real constant so assertions track config changes rather
|
||||
// than a hardcoded magic number.
|
||||
final tolerance =
|
||||
VideoTimingConstants.chatSyncDriftToleranceSeconds.toDouble();
|
||||
|
||||
late SettingsStore settingsStore;
|
||||
late ChatLatencySync sync;
|
||||
|
||||
setUp(() {
|
||||
settingsStore = SettingsStore.fromJson({});
|
||||
sync = ChatLatencySync(settingsStore: settingsStore);
|
||||
});
|
||||
|
||||
group('ChatLatencySync reset', () {
|
||||
test('zeroes syncedChatDelay when autoSyncChatDelay is enabled', () {
|
||||
settingsStore.autoSyncChatDelay = true;
|
||||
settingsStore.syncedChatDelay = 7.5;
|
||||
|
||||
sync.reset();
|
||||
|
||||
expect(settingsStore.syncedChatDelay, 0.0);
|
||||
});
|
||||
|
||||
test('is a no-op when autoSyncChatDelay is disabled', () {
|
||||
settingsStore.autoSyncChatDelay = false;
|
||||
settingsStore.syncedChatDelay = 7.5;
|
||||
|
||||
sync.reset();
|
||||
|
||||
expect(settingsStore.syncedChatDelay, 7.5);
|
||||
});
|
||||
});
|
||||
|
||||
group('ChatLatencySync report', () {
|
||||
test('does nothing when autoSyncChatDelay is disabled', () {
|
||||
settingsStore.autoSyncChatDelay = false;
|
||||
settingsStore.syncedChatDelay = 0.0;
|
||||
|
||||
sync.report(12.0);
|
||||
|
||||
expect(settingsStore.syncedChatDelay, 0.0);
|
||||
});
|
||||
|
||||
test('writes the first measurement when current delay is zero', () {
|
||||
settingsStore.autoSyncChatDelay = true;
|
||||
settingsStore.syncedChatDelay = 0.0;
|
||||
|
||||
// Even a tiny value writes because the current value is exactly 0.
|
||||
sync.report(0.5);
|
||||
|
||||
expect(settingsStore.syncedChatDelay, 0.5);
|
||||
});
|
||||
|
||||
test('writes when drift exceeds the tolerance', () {
|
||||
settingsStore.autoSyncChatDelay = true;
|
||||
settingsStore.syncedChatDelay = 5.0;
|
||||
|
||||
final report = 5.0 + tolerance + 1.0;
|
||||
sync.report(report);
|
||||
|
||||
expect(settingsStore.syncedChatDelay, report);
|
||||
});
|
||||
|
||||
test('does not write when drift is within the tolerance', () {
|
||||
settingsStore.autoSyncChatDelay = true;
|
||||
settingsStore.syncedChatDelay = 5.0;
|
||||
|
||||
// Strictly inside the tolerance band.
|
||||
sync.report(5.0 + (tolerance - 0.5));
|
||||
|
||||
expect(settingsStore.syncedChatDelay, 5.0);
|
||||
});
|
||||
|
||||
test('does not write when drift is exactly at the tolerance', () {
|
||||
settingsStore.autoSyncChatDelay = true;
|
||||
settingsStore.syncedChatDelay = 5.0;
|
||||
|
||||
// The code uses strictly-greater-than (`>`), so a drift equal to the
|
||||
// tolerance must NOT write.
|
||||
sync.report(5.0 + tolerance);
|
||||
|
||||
expect(settingsStore.syncedChatDelay, 5.0);
|
||||
});
|
||||
|
||||
test('writes when drift just exceeds the tolerance', () {
|
||||
settingsStore.autoSyncChatDelay = true;
|
||||
settingsStore.syncedChatDelay = 5.0;
|
||||
|
||||
final report = 5.0 + tolerance + 0.1;
|
||||
sync.report(report);
|
||||
|
||||
expect(settingsStore.syncedChatDelay, report);
|
||||
});
|
||||
|
||||
test('writes when a downward drift exceeds the tolerance', () {
|
||||
settingsStore.autoSyncChatDelay = true;
|
||||
settingsStore.syncedChatDelay = 10.0;
|
||||
|
||||
final report = 10.0 - tolerance - 1.0;
|
||||
sync.report(report);
|
||||
|
||||
expect(settingsStore.syncedChatDelay, report);
|
||||
});
|
||||
});
|
||||
}
|
||||
194
test/screens/channel/video/stream_info_poller_test.dart
Normal file
194
test/screens/channel/video/stream_info_poller_test.dart
Normal file
|
|
@ -0,0 +1,194 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:frosty/apis/twitch_api.dart';
|
||||
import 'package:frosty/models/channel.dart';
|
||||
import 'package:frosty/models/stream.dart';
|
||||
import 'package:frosty/screens/channel/video/stream_info_poller.dart';
|
||||
import 'package:mocktail/mocktail.dart';
|
||||
|
||||
import '../../../fixtures/api_responses.dart';
|
||||
|
||||
class MockTwitchApi extends Mock implements TwitchApi {}
|
||||
|
||||
void main() {
|
||||
const userLogin = 'testuser';
|
||||
const userId = '12345';
|
||||
|
||||
late MockTwitchApi api;
|
||||
|
||||
// Fresh fixtures per test so nothing leaks between cases.
|
||||
StreamTwitch buildStream() => StreamTwitch.fromJson(
|
||||
(twitchStreamResponse['data']! as List).first as Map<String, dynamic>,
|
||||
);
|
||||
|
||||
Channel buildChannel() => Channel.fromJson(
|
||||
(twitchChannelResponse['data']! as List).first as Map<String, dynamic>,
|
||||
);
|
||||
|
||||
// Fresh poller per test so _lastUpdate / _inFlight debounce state never
|
||||
// carries over between tests.
|
||||
StreamInfoPoller buildPoller() =>
|
||||
StreamInfoPoller(twitchApi: api, userLogin: userLogin, userId: userId);
|
||||
|
||||
setUp(() {
|
||||
api = MockTwitchApi();
|
||||
});
|
||||
|
||||
group('live', () {
|
||||
test('returns stream when getStream succeeds', () async {
|
||||
when(
|
||||
() => api.getStream(userLogin: any(named: 'userLogin')),
|
||||
).thenAnswer((_) async => buildStream());
|
||||
|
||||
final poller = buildPoller();
|
||||
final result = await poller.fetch();
|
||||
|
||||
expect(result, isNotNull);
|
||||
expect(result!.stream, isNotNull);
|
||||
expect(result.stream!.userName, 'TestUser');
|
||||
expect(result.offlineChannel, isNull);
|
||||
|
||||
verify(() => api.getStream(userLogin: userLogin)).called(1);
|
||||
verifyNever(() => api.getChannel(userId: any(named: 'userId')));
|
||||
});
|
||||
});
|
||||
|
||||
group('debounce', () {
|
||||
test(
|
||||
'second fetch within debounce window returns null, forceUpdate bypasses',
|
||||
() async {
|
||||
when(
|
||||
() => api.getStream(userLogin: any(named: 'userLogin')),
|
||||
).thenAnswer((_) async => buildStream());
|
||||
|
||||
final poller = buildPoller();
|
||||
|
||||
// First fetch resolves with a real result.
|
||||
final first = await poller.fetch();
|
||||
expect(first, isNotNull);
|
||||
expect(first!.stream, isNotNull);
|
||||
|
||||
// Immediate second fetch (no forceUpdate) is inside the 5s debounce
|
||||
// window -> debounced -> null.
|
||||
final second = await poller.fetch();
|
||||
expect(second, isNull);
|
||||
|
||||
// forceUpdate bypasses the debounce -> a fresh result.
|
||||
final forced = await poller.fetch(forceUpdate: true);
|
||||
expect(forced, isNotNull);
|
||||
expect(forced!.stream, isNotNull);
|
||||
|
||||
// Two real fetches (first + forced); the debounced one issued no call.
|
||||
verify(() => api.getStream(userLogin: userLogin)).called(2);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
group('in-flight dedup', () {
|
||||
test(
|
||||
'concurrent fetches await the same request and call getStream once',
|
||||
() async {
|
||||
final completer = Completer<StreamTwitch>();
|
||||
when(
|
||||
() => api.getStream(userLogin: any(named: 'userLogin')),
|
||||
).thenAnswer((_) => completer.future);
|
||||
|
||||
final poller = buildPoller();
|
||||
|
||||
// Fire both without awaiting so the second sees the in-flight future.
|
||||
final firstFuture = poller.fetch();
|
||||
final secondFuture = poller.fetch();
|
||||
|
||||
// Now let the underlying request complete.
|
||||
completer.complete(buildStream());
|
||||
|
||||
final first = await firstFuture;
|
||||
final second = await secondFuture;
|
||||
|
||||
expect(first, isNotNull);
|
||||
expect(second, isNotNull);
|
||||
// Same deduplicated result instance.
|
||||
expect(identical(first, second), isTrue);
|
||||
expect(first!.stream, isNotNull);
|
||||
|
||||
verify(() => api.getStream(userLogin: userLogin)).called(1);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
group('second-chance retry', () {
|
||||
test(
|
||||
'getStream fails once then succeeds on retry -> stream, no getChannel',
|
||||
() async {
|
||||
var calls = 0;
|
||||
when(() => api.getStream(userLogin: any(named: 'userLogin'))).thenAnswer(
|
||||
(_) async {
|
||||
calls++;
|
||||
if (calls == 1) throw Exception('transient drop');
|
||||
return buildStream();
|
||||
},
|
||||
);
|
||||
|
||||
final poller = buildPoller();
|
||||
final result = await poller.fetch();
|
||||
|
||||
expect(result, isNotNull);
|
||||
expect(result!.stream, isNotNull);
|
||||
expect(result.offlineChannel, isNull);
|
||||
|
||||
verify(() => api.getStream(userLogin: userLogin)).called(2);
|
||||
verifyNever(() => api.getChannel(userId: any(named: 'userId')));
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
group('offline', () {
|
||||
test(
|
||||
'getStream fails twice, getChannel succeeds -> offlineChannel',
|
||||
() async {
|
||||
when(
|
||||
() => api.getStream(userLogin: any(named: 'userLogin')),
|
||||
).thenThrow(Exception('offline'));
|
||||
when(
|
||||
() => api.getChannel(userId: any(named: 'userId')),
|
||||
).thenAnswer((_) async => buildChannel());
|
||||
|
||||
final poller = buildPoller();
|
||||
final result = await poller.fetch();
|
||||
|
||||
expect(result, isNotNull);
|
||||
expect(result!.stream, isNull);
|
||||
expect(result.offlineChannel, isNotNull);
|
||||
expect(result.offlineChannel!.broadcasterName, 'TestUser');
|
||||
|
||||
verify(() => api.getStream(userLogin: userLogin)).called(2);
|
||||
verify(() => api.getChannel(userId: userId)).called(1);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
group('total failure', () {
|
||||
test(
|
||||
'getStream fails twice and getChannel fails -> empty result',
|
||||
() async {
|
||||
when(
|
||||
() => api.getStream(userLogin: any(named: 'userLogin')),
|
||||
).thenThrow(Exception('stream boom'));
|
||||
when(
|
||||
() => api.getChannel(userId: any(named: 'userId')),
|
||||
).thenThrow(Exception('channel boom'));
|
||||
|
||||
final poller = buildPoller();
|
||||
final result = await poller.fetch();
|
||||
|
||||
expect(result, isNotNull);
|
||||
expect(result!.stream, isNull);
|
||||
expect(result.offlineChannel, isNull);
|
||||
|
||||
verify(() => api.getStream(userLogin: userLogin)).called(2);
|
||||
verify(() => api.getChannel(userId: userId)).called(1);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
159
test/screens/channel/video/video_timing_constants_test.dart
Normal file
159
test/screens/channel/video/video_timing_constants_test.dart
Normal file
|
|
@ -0,0 +1,159 @@
|
|||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:frosty/screens/channel/video/video_timing_constants.dart';
|
||||
|
||||
/// Regression guard for the cross-layer ordering invariants documented in
|
||||
/// [VideoTimingConstants]. These constants are tuned against native code in
|
||||
/// two other layers (iOS notification-stall recovery and the Android
|
||||
/// VideoPlayerObserver watchdog) that are NOT visible from Dart. If someone
|
||||
/// retunes a value past a safe bound, these tests fail with a message quoting
|
||||
/// the contract so the regression is self-explanatory.
|
||||
void main() {
|
||||
group('VideoTimingConstants stall-timer ordering', () {
|
||||
test(
|
||||
'stallDetectionDelay sits between iOS ~1s recovery and Android 12s watchdog',
|
||||
() {
|
||||
final seconds = VideoTimingConstants.stallDetectionDelay.inSeconds;
|
||||
|
||||
expect(
|
||||
seconds,
|
||||
greaterThan(1),
|
||||
reason:
|
||||
'Contract: 1s < stallDetectionDelay. iOS native notification-stall '
|
||||
'recovery fires at ~1s; the Dart timer must not race ahead of it.',
|
||||
);
|
||||
expect(
|
||||
seconds,
|
||||
lessThan(12),
|
||||
reason:
|
||||
'Contract: stallDetectionDelay < 12s. The Android native watchdog '
|
||||
'(VideoPlayerObserver.kt STALL_WATCHDOG_MS) fires at 12s with a '
|
||||
'heavier stop()/prepare() recovery. Dart\'s attempt-1 seek must '
|
||||
'pre-empt it, so it must fire first.',
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
group('VideoTimingConstants refreshBackoff', () {
|
||||
test('is non-empty and starts at Duration.zero', () {
|
||||
expect(VideoTimingConstants.refreshBackoff, isNotEmpty);
|
||||
expect(
|
||||
VideoTimingConstants.refreshBackoff.first,
|
||||
Duration.zero,
|
||||
reason:
|
||||
'First refresh attempt should be immediate (0 = first attempt per '
|
||||
'the doc comment).',
|
||||
);
|
||||
});
|
||||
|
||||
test('covers every refresh attempt up to maxRefreshAttempts', () {
|
||||
// The comment states attempts beyond the list length fall through to the
|
||||
// error path via [maxRefreshAttempts]. So the list must be long enough to
|
||||
// back off every attempt before that fall-through, i.e. cover all
|
||||
// maxRefreshAttempts attempts.
|
||||
expect(
|
||||
VideoTimingConstants.refreshBackoff.length,
|
||||
greaterThanOrEqualTo(VideoTimingConstants.maxRefreshAttempts),
|
||||
reason:
|
||||
'refreshBackoff must index every attempt up to maxRefreshAttempts '
|
||||
'(${VideoTimingConstants.maxRefreshAttempts}); a shorter list would '
|
||||
'drop a backoff and the attempt would fall through to the error '
|
||||
'path prematurely.',
|
||||
);
|
||||
});
|
||||
|
||||
test('delays are monotonically non-decreasing', () {
|
||||
final backoff = VideoTimingConstants.refreshBackoff;
|
||||
for (var i = 1; i < backoff.length; i++) {
|
||||
expect(
|
||||
backoff[i],
|
||||
greaterThanOrEqualTo(backoff[i - 1]),
|
||||
reason:
|
||||
'Backoff must not shrink between attempts: index $i '
|
||||
'(${backoff[i]}) < index ${i - 1} (${backoff[i - 1]}). '
|
||||
'Later retries should wait at least as long as earlier ones.',
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
group('VideoTimingConstants latency vs chat-sync tolerance', () {
|
||||
test('highLatencyThreshold is much greater than chatSyncDriftTolerance', () {
|
||||
expect(
|
||||
VideoTimingConstants.highLatencyThresholdSeconds,
|
||||
greaterThan(VideoTimingConstants.chatSyncDriftToleranceSeconds),
|
||||
reason:
|
||||
'High-latency intervention (seek/refresh) must only trigger far '
|
||||
'past the chat-sync drift tolerance '
|
||||
'(${VideoTimingConstants.chatSyncDriftToleranceSeconds}s); otherwise '
|
||||
'normal sync drift would be misread as a latency problem and trigger '
|
||||
'recovery.',
|
||||
);
|
||||
});
|
||||
|
||||
test('highLatencyThreshold sits comfortably above normal live latency', () {
|
||||
// Normal live latency is well under ~15s; the threshold must clear that
|
||||
// so routine live playback is never flagged as high-latency.
|
||||
expect(
|
||||
VideoTimingConstants.highLatencyThresholdSeconds,
|
||||
greaterThanOrEqualTo(15),
|
||||
reason:
|
||||
'highLatencyThresholdSeconds must stay above normal live latency '
|
||||
'(under ~15s) so healthy playback is not flagged for recovery.',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('VideoTimingConstants short-play loop detection', () {
|
||||
test('shortPlayWindow is positive', () {
|
||||
expect(VideoTimingConstants.shortPlayWindow, greaterThan(Duration.zero));
|
||||
});
|
||||
|
||||
test('shortPlayLoopThreshold is a small positive int', () {
|
||||
expect(
|
||||
VideoTimingConstants.shortPlayLoopThreshold,
|
||||
greaterThan(0),
|
||||
reason: 'Need at least one bounce to detect a failed-recovery loop.',
|
||||
);
|
||||
expect(
|
||||
VideoTimingConstants.shortPlayLoopThreshold,
|
||||
lessThanOrEqualTo(10),
|
||||
reason:
|
||||
'Threshold should stay small so a tailored error surfaces promptly '
|
||||
'rather than after many silent loops.',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('VideoTimingConstants overlay ordering', () {
|
||||
test('overlayQuickHide is not slower than overlayAutoHide', () {
|
||||
expect(
|
||||
VideoTimingConstants.overlayQuickHide,
|
||||
lessThanOrEqualTo(VideoTimingConstants.overlayAutoHide),
|
||||
reason:
|
||||
'The quick-hide path must hide the overlay at least as fast as the '
|
||||
'auto-hide path; otherwise "quick" would be slower than the default.',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('VideoTimingConstants positive intervals', () {
|
||||
test('nativeStreamInfoInterval is positive', () {
|
||||
expect(
|
||||
VideoTimingConstants.nativeStreamInfoInterval,
|
||||
greaterThan(Duration.zero),
|
||||
);
|
||||
});
|
||||
|
||||
test('latencyPollingInterval is positive', () {
|
||||
expect(
|
||||
VideoTimingConstants.latencyPollingInterval,
|
||||
greaterThan(Duration.zero),
|
||||
);
|
||||
});
|
||||
|
||||
test('maxRefreshAttempts is positive', () {
|
||||
expect(VideoTimingConstants.maxRefreshAttempts, greaterThan(0));
|
||||
});
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue