Screen share 8: fluxer-core stream state, ports and selectors (#155) #194

Manually merged
charles merged 0 commits from screenshare-8-core-stream-ports into screenshare 2026-11-12 05:17:18 +00:00
Owner

Stacked on: screenshare-7-proto-api-streams

What this builds (Screen share plan, Task 8; spec §6.1, §6.2, §6.4)

  • Ports (fluxer-core::voice::port): VoiceCommand::{PublishScreenShare, UpdateScreenShareEncoding, RepublishScreenShare, UnpublishScreenShare, SetScreenShareAudioMuted}; VoiceEvent::{LocalTrackPublished, LocalTrackUnpublished, CodecCapabilities, VideoFrameInfo, EncoderStats}; CaptureCommand::{ListSources, Start, Switch, Update, Stop} in the new Effect::Capture; CaptureEvent::{Sources, Started, Stalled, Resumed, Ended { reason }, Error} in the new CoreEvent::Capture; PlaybackSource::Stream(identity); Chime::{ScreenShareStart, ScreenShareStop}. Types: VideoCodec (Av1, H265, H264, Vp9, Vp8; ALL, codec_name(), from_codec_name()), CodecCap, EncodeParams { width, height, fps, max_bitrate, degradation, scalability_mode, backend }, Degradation, EncoderBackend, and mirrors of fluxer-capture's SourceChoice, CaptureTarget, AudioRule/AudioMode/AppMatch (same defaults), SourceKind, EndReason, CaptureCapabilities, plus CaptureSources { sources: Vec<CaptureSourceInfo>, capabilities } (no thumbnails: those stay in the frame bus).
  • State: Voice.streams: Streams { watching: Vec<StreamKey>, capture_sources: Option<CaptureSources> } in voice/stream/{mod,state}.rs; CaptureEvent::Sources is kept, logout clears it. Later tasks add outgoing, negotiation, previews, remote, audio_prefs as Default fields.
  • Selectors (selectors::streams): streams_in_channel(&App, channel) -> Vec<StreamRow { key, user_id, connection_id, display_name, own, watching, viewers, has_audio, video_sid }> (sidebar order); spectators(&App, &StreamKey) -> Vec<Spectator> (port of useStreamSpectators: excludes this client's connection and the sharer's devices, absent viewer_stream_keys watch nothing, keys compared parsed so @me: reads as dm:); is_streaming(&App, user_id); stream_of(&App, user_id, connection_id) -> Option<StreamKey>.
  • Live room: screen-share publications were already recorded per participant; added LiveParticipant::{screen_share, screen_share_audio} and docs. They still get one SetSubscribed { subscribed: false } and are never subscribed (Task 9 subscribes while watched).

Tests

crates/fluxer-core/tests/streams.rs: self_stream_state_lists_stream_in_channel, viewers_counted_from_viewer_keys_excluding_owner, absent_viewer_keys_are_not_listed_as_watching, screen_tracks_recorded_but_not_subscribed, dm_stream_keys, new_ports_have_debug_without_secrets, plus stream_fixture_lists_its_stream (Task 7's fixture) and capture_sources_are_kept_until_logout. Seen failing (compile errors) before the implementation, passing after. FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci green locally. No real-device tests in this task.

Deviations / outside the Files list

  • Adding enum variants broke exhaustive matches in other crates; minimal arms only: fluxer-voice/src/session.rs drops the screen-share commands with a debug log (Screen share 16/17 implement them); apps/fluxer/src/runtime.rs logs and drops Effect::Capture (Screen share 21); apps/fluxer/src/audio_rt.rs maps PlaybackSource::Stream and the two new chimes to nothing (the mixer has no stream source yet, and fluxer-audio does not bundle stream-start.mp3/stream-stop.mp3: follow-up #193). messages.rs/session.rs in core got the CoreEvent::Capture(_) arm.
  • StreamRow has no state/preview_version yet (they belong to Tasks 9 and 13); it has own and video_sid in addition, for the tile and the VideoKey::Remote { sid }.
  • CaptureSources carries CaptureCapabilities (spec §6.4 has no separate capabilities event); Task 10 may want the capabilities before the first listing and can add them where it needs.
  • Spectators include users the client has not seen (named by the display_name fallback); the original drops viewers whose user it does not have loaded.
  • selectors::voice::collate became pub(crate) to sort spectators like the participant list.

Closes #155

🤖 Generated with Claude Code

Stacked on: screenshare-7-proto-api-streams ## What this builds (Screen share plan, Task 8; spec §6.1, §6.2, §6.4) - **Ports** (`fluxer-core::voice::port`): `VoiceCommand::{PublishScreenShare, UpdateScreenShareEncoding, RepublishScreenShare, UnpublishScreenShare, SetScreenShareAudioMuted}`; `VoiceEvent::{LocalTrackPublished, LocalTrackUnpublished, CodecCapabilities, VideoFrameInfo, EncoderStats}`; `CaptureCommand::{ListSources, Start, Switch, Update, Stop}` in the new `Effect::Capture`; `CaptureEvent::{Sources, Started, Stalled, Resumed, Ended { reason }, Error}` in the new `CoreEvent::Capture`; `PlaybackSource::Stream(identity)`; `Chime::{ScreenShareStart, ScreenShareStop}`. Types: `VideoCodec` (Av1, H265, H264, Vp9, Vp8; `ALL`, `codec_name()`, `from_codec_name()`), `CodecCap`, `EncodeParams { width, height, fps, max_bitrate, degradation, scalability_mode, backend }`, `Degradation`, `EncoderBackend`, and mirrors of `fluxer-capture`'s `SourceChoice`, `CaptureTarget`, `AudioRule`/`AudioMode`/`AppMatch` (same defaults), `SourceKind`, `EndReason`, `CaptureCapabilities`, plus `CaptureSources { sources: Vec<CaptureSourceInfo>, capabilities }` (no thumbnails: those stay in the frame bus). - **State**: `Voice.streams: Streams { watching: Vec<StreamKey>, capture_sources: Option<CaptureSources> }` in `voice/stream/{mod,state}.rs`; `CaptureEvent::Sources` is kept, logout clears it. Later tasks add `outgoing`, `negotiation`, `previews`, `remote`, `audio_prefs` as `Default` fields. - **Selectors** (`selectors::streams`): `streams_in_channel(&App, channel) -> Vec<StreamRow { key, user_id, connection_id, display_name, own, watching, viewers, has_audio, video_sid }>` (sidebar order); `spectators(&App, &StreamKey) -> Vec<Spectator>` (port of `useStreamSpectators`: excludes this client's connection and the sharer's devices, absent `viewer_stream_keys` watch nothing, keys compared parsed so `@me:` reads as `dm:`); `is_streaming(&App, user_id)`; `stream_of(&App, user_id, connection_id) -> Option<StreamKey>`. - **Live room**: screen-share publications were already recorded per participant; added `LiveParticipant::{screen_share, screen_share_audio}` and docs. They still get one `SetSubscribed { subscribed: false }` and are never subscribed (Task 9 subscribes while watched). ## Tests `crates/fluxer-core/tests/streams.rs`: `self_stream_state_lists_stream_in_channel`, `viewers_counted_from_viewer_keys_excluding_owner`, `absent_viewer_keys_are_not_listed_as_watching`, `screen_tracks_recorded_but_not_subscribed`, `dm_stream_keys`, `new_ports_have_debug_without_secrets`, plus `stream_fixture_lists_its_stream` (Task 7's fixture) and `capture_sources_are_kept_until_logout`. Seen failing (compile errors) before the implementation, passing after. `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` green locally. No real-device tests in this task. ## Deviations / outside the Files list - Adding enum variants broke exhaustive matches in other crates; minimal arms only: `fluxer-voice/src/session.rs` drops the screen-share commands with a debug log (Screen share 16/17 implement them); `apps/fluxer/src/runtime.rs` logs and drops `Effect::Capture` (Screen share 21); `apps/fluxer/src/audio_rt.rs` maps `PlaybackSource::Stream` and the two new chimes to nothing (the mixer has no stream source yet, and `fluxer-audio` does not bundle `stream-start.mp3`/`stream-stop.mp3`: follow-up #193). `messages.rs`/`session.rs` in core got the `CoreEvent::Capture(_)` arm. - `StreamRow` has no `state`/`preview_version` yet (they belong to Tasks 9 and 13); it has `own` and `video_sid` in addition, for the tile and the `VideoKey::Remote { sid }`. - `CaptureSources` carries `CaptureCapabilities` (spec §6.4 has no separate capabilities event); Task 10 may want the capabilities before the first listing and can add them where it needs. - Spectators include users the client has not seen (named by the `display_name` fallback); the original drops viewers whose user it does not have loaded. - `selectors::voice::collate` became `pub(crate)` to sort spectators like the participant list. Closes #155 🤖 Generated with [Claude Code](https://claude.com/claude-code)
feat(proto,api): stream keys, instance limits, capability adverts and preview endpoints
All checks were successful
ci / Windows (x64) (push) Successful in 28m59s
ci / Linux (x86_64) (push) Successful in 37m2s
6ac431d9db
Refs #154

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
feat(core): stream state, ports and selectors
All checks were successful
ci / Linux (x86_64) (push) Successful in 13m48s
ci / Windows (x64) (push) Successful in 14m25s
0d406ebd96
Refs #155

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
Owner

Independent review: Screen share 8 (core-stream-ports), commit 0d406eb

Scope: git diff 6ac431d..origin/screenshare-8-core-stream-ports.

Tests (plan Step 1). All six named tests exist in crates/fluxer-core/tests/streams.rs and assert what the plan asks for: self_stream_state_lists_stream_in_channel, viewers_counted_from_viewer_keys_excluding_owner, absent_viewer_keys_are_not_listed_as_watching (absent, null and [] cases), screen_tracks_recorded_but_not_subscribed (one SetSubscribed{false} per screen source, publications kept, sid and audio shown in the row, audio unpublish handled), dm_stream_keys (dm:<channel>:<conn>), and new_ports_have_debug_without_secrets. There are two extra tests: stream_fixture_lists_its_stream and capture_sources_are_kept_until_logout.

Interfaces (spec §6.4 and the Task 8 block). Every listed name is present with the signature written in the plan:

  • the 5 new VoiceCommand variants and the 5 new VoiceEvent variants
  • CaptureCommand and CaptureEvent, with the exact variants
  • Effect::Capture and CoreEvent::Capture
  • VideoCodec { Av1, H265, H264, Vp9, Vp8 }, CodecCap { codec, hardware }
  • EncodeParams { width, height, fps, max_bitrate, degradation, scalability_mode: Option<String>, backend }
  • SourceChoice, CaptureTarget, AudioRule, CaptureSources, PlaybackSource::Stream(String), Chime::{ScreenShareStart, ScreenShareStop}
  • Voice.streams: Streams
  • streams_in_channel, spectators, is_streaming(&App, user_id), stream_of(&App, user_id, &str) -> Option<StreamKey>

Invariants. No Cargo.toml change, and fluxer-core gains no dependency. The only new import is fluxer_proto::rtc::CodecName, from a crate it already depends on. No pixel or sample type is added, and no LiveKit or libwebrtc type appears in a public signature. Key building and parsing cannot panic: unparseable keys simply watch nothing. No secrets or tokens appear in code or tests. The extra arms in fluxer-voice/session.rs, apps/fluxer/runtime.rs and audio_rt.rs are minimal no-ops, and each one logs at debug level.

Review Focus 2 (input to Task 9). I checked spectators against the fork's useStreamSpectators.ts. Both exclude only the local connection (not the local user's other devices) and every connection of the sharer, de-duplicate by connection, and treat an absent list as watching nothing. The sharer is found from the key's connection. This build compares keys after parsing them, a harmless improvement. Including users that are not in the cache is a documented deviation; their display name falls back to the default.

Findings

  • minor: StreamRow has no state or preview_version yet (spec §6.2). The PR documents this deviation: Tasks 9 and 13 must add these fields. The extra own and video_sid fields are additive.
  • minor: CaptureSources also carries CaptureCapabilities. This is additive. Task 10 should read in_app_picker from it, or from a runtime advert if it needs the value before the first listing.
  • minor: streams_in_channel calls spectators once per row, and spectators scans every voice state. That is O(rows × states). It is fine at today's sizes; I note it only in case the UI calls it every frame.

Local CI: FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci in a fresh worktree passed every step (livekit-interop is skipped as designed).

Verdict: APPROVE (0 blocking, 3 minor).

## Independent review: Screen share 8 (core-stream-ports), commit 0d406eb Scope: `git diff 6ac431d..origin/screenshare-8-core-stream-ports`. **Tests (plan Step 1).** All six named tests exist in `crates/fluxer-core/tests/streams.rs` and assert what the plan asks for: `self_stream_state_lists_stream_in_channel`, `viewers_counted_from_viewer_keys_excluding_owner`, `absent_viewer_keys_are_not_listed_as_watching` (absent, `null` and `[]` cases), `screen_tracks_recorded_but_not_subscribed` (one `SetSubscribed{false}` per screen source, publications kept, sid and audio shown in the row, audio unpublish handled), `dm_stream_keys` (`dm:<channel>:<conn>`), and `new_ports_have_debug_without_secrets`. There are two extra tests: `stream_fixture_lists_its_stream` and `capture_sources_are_kept_until_logout`. **Interfaces (spec §6.4 and the Task 8 block).** Every listed name is present with the signature written in the plan: - the 5 new `VoiceCommand` variants and the 5 new `VoiceEvent` variants - `CaptureCommand` and `CaptureEvent`, with the exact variants - `Effect::Capture` and `CoreEvent::Capture` - `VideoCodec { Av1, H265, H264, Vp9, Vp8 }`, `CodecCap { codec, hardware }` - `EncodeParams { width, height, fps, max_bitrate, degradation, scalability_mode: Option<String>, backend }` - `SourceChoice`, `CaptureTarget`, `AudioRule`, `CaptureSources`, `PlaybackSource::Stream(String)`, `Chime::{ScreenShareStart, ScreenShareStop}` - `Voice.streams: Streams` - `streams_in_channel`, `spectators`, `is_streaming(&App, user_id)`, `stream_of(&App, user_id, &str) -> Option<StreamKey>` **Invariants.** No `Cargo.toml` change, and `fluxer-core` gains no dependency. The only new import is `fluxer_proto::rtc::CodecName`, from a crate it already depends on. No pixel or sample type is added, and no LiveKit or libwebrtc type appears in a public signature. Key building and parsing cannot panic: unparseable keys simply watch nothing. No secrets or tokens appear in code or tests. The extra arms in `fluxer-voice/session.rs`, `apps/fluxer/runtime.rs` and `audio_rt.rs` are minimal no-ops, and each one logs at debug level. **Review Focus 2 (input to Task 9).** I checked `spectators` against the fork's `useStreamSpectators.ts`. Both exclude only the local connection (not the local user's other devices) and every connection of the sharer, de-duplicate by connection, and treat an absent list as watching nothing. The sharer is found from the key's connection. This build compares keys after parsing them, a harmless improvement. Including users that are not in the cache is a documented deviation; their display name falls back to the default. **Findings** - minor: `StreamRow` has no `state` or `preview_version` yet (spec §6.2). The PR documents this deviation: Tasks 9 and 13 must add these fields. The extra `own` and `video_sid` fields are additive. - minor: `CaptureSources` also carries `CaptureCapabilities`. This is additive. Task 10 should read `in_app_picker` from it, or from a runtime advert if it needs the value before the first listing. - minor: `streams_in_channel` calls `spectators` once per row, and `spectators` scans every voice state. That is O(rows × states). It is fine at today's sizes; I note it only in case the UI calls it every frame. **Local CI:** `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` in a fresh worktree passed every step (livekit-interop is skipped as designed). **Verdict: APPROVE** (0 blocking, 3 minor).
charles manually merged commit 69edce3d34 into screenshare 2026-11-12 05:17:18 +00:00
Sign in to join this conversation.
No description provided.