forked from Foxyz/sync_replay_project
Server and core: version ranges on both sides with a coded refusal; a client id maps to the same member and token for the server's life; a drop is `gone` for a 10-minute grace keeping ready, presence, queue items, relay and avatar; `bye` leaves at once; ordered takeover (seq, replaced/stale); presence joining/in/away/gone with one PresencePolicy; joiners never pause playback and hold a held gate at most ~15 s; state.hold; feed ids, seq and replay; the relay lives through its source's grace and continues on re-dial; queue `by` lasting, auto items and cancel; MediaRef carried; client ids never logged. App: persisted client id and seq; Connection with unstable/lost/ replaced states, backoff with jitter, no lost/back pair per flap; a drop keeps the session (state, player, media, relay source); presence in the strip and members card; sit out = away intent; feed matched by id; auto sit-out (idle when not playing, minimised for a while; never when alone) replaces auto-unready; bye on close and Leave, not on update restart; relay source re-dials through its grace. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
28 lines
1.2 KiB
Dart
28 lines
1.2 KiB
Dart
import 'package:sync_relay_core/core.dart';
|
|
|
|
// The app's reading of presence (PROTOCOL.md "Presence"): every count,
|
|
// list and wait in the UI goes through these, on top of core's
|
|
// [PresencePolicy] and [isAlone].
|
|
|
|
/// What each presence counts for (the one table, shared with the server).
|
|
const presencePolicy = PresencePolicy();
|
|
|
|
/// Counted in "2/3 ready" and waited for by name: its presence counts for
|
|
/// the ready counter and its player can open the media.
|
|
bool countsForReady(MemberView m) => m.error.isEmpty && presencePolicy.countsFor(m.presence, Purpose.readyCounter);
|
|
|
|
/// Connected and watching (`in` or `joining`): can do things for the
|
|
/// party now (put up an Up next item, the auto-advance swap).
|
|
bool isPresent(MemberView m) => m.presence == Presence.watching || m.presence == Presence.joining;
|
|
|
|
/// Nobody but [selfId] is connected in [members] (D9, core's [isAlone]).
|
|
bool aloneIn(List<MemberView> members, String selfId) =>
|
|
isAlone([for (final m in members) if (m.id != selfId) m.presence]);
|
|
|
|
/// "3 min" / "40 s": how long since [since] (a `goneSince`), at [now].
|
|
String sinceText(DateTime since, DateTime now) {
|
|
final d = now.difference(since);
|
|
if (d.inMinutes >= 1) return '${d.inMinutes} min';
|
|
return '${d.inSeconds.clamp(0, 59)} s';
|
|
}
|