Screen share 10: core go-live (#157) #221

Manually merged
charles merged 4 commits from screenshare-10-core-go-live into screenshare 2026-11-12 07:59:49 +00:00
Owner

What this builds

fluxer-core::voice::stream::golive (spec §3.1, §6.3 "Go live", "Stop", "Change stream", "Sharer audio mute"):

  • GoLive { Idle, Picking { switch }, Starting { source, since }, Live { source, video_sid, audio_sid, codec, params }, Stopping } in Streams.outgoing; can_stream(&App) -> Result<(), CannotStream::{NotConnected, NoPermission}> (connected room, STREAM 1 << 9 or ADMINISTRATOR; DM calls allowed).
  • UserAction::{OpenScreenSharePicker { switch }, CloseScreenSharePicker, StartScreenShare(SourceChoice), ChangeScreenShareSource(SourceChoice), StopScreenShare, SetMuteStreamAudio(bool)}.
  • Opening the picker emits CaptureCommand::ListSources { thumbnails: true }, or Start { source: SystemPicker, .. } at once once the backend listed itself without an in-app picker (a listing that arrives while the picker is open and says "no in-app picker" also starts the system picker).
  • Start order: capture Start (30 s START_TIMEOUT) -> capture Started -> PublishScreenShare -> room LocalTrackPublished(ScreenShare) -> op 4 self_stream: true -> op 4 adding the own key -> Chime::ScreenShareStart. Announced (connection.rs) now carries self_stream, and the own key is appended to viewer_stream_keys only while the video is published in the connection's channel, so every op 4 (mute, deafen, watch, resend after READY) carries the current stream flag and key, never before the publication.
  • Stop order: op 4 self_stream: false (own key still listed) -> UnpublishScreenShare -> CaptureCommand::Stop -> op 4 without own key -> Chime::ScreenShareStop; then Stopping until the video's LocalTrackUnpublished (or STOP_TIMEOUT, 5 s).
  • Triggers: user, capture Ended/Error, STREAM lost (permissions recomputed after every event) or the gateway clearing self_stream after it had confirmed it, leave, move (the move op 4 already says self_stream: false, no extra op 4), room lost / replaced, logout (capture stopped, unpublished).
  • Change stream: CaptureCommand::Switch, publication kept; the switch picker keeps the running share (it still announces while the picker is open).
  • SetMuteStreamAudio sets video.mute_stream_audio (persisted) and sends SetScreenShareAudioMuted; a share started with it on mutes its audio track when that is published.

Tests

crates/fluxer-core/tests/stream_golive.rs: start_order_capture_publish_op4_ownkey_chime, self_stream_never_true_before_publication, stop_order_op4_before_unpublish, capture_ended_stops_share, portal_cancel_returns_idle_without_op4, start_timeout_30s, permission_loss_stops_share, disconnect_and_move_reset_stream, change_source_keeps_publication, no_permission_blocks_start_with_reason, extra sharer_audio_mute_mutes_published_track, and proptest any_event_order_keeps_golive_consistent (128 random event orders: no op 4 says self_stream/own key unless the video is published, at most one capture runs, publish only after a started capture, every way back to Idle stops a started capture). FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci green locally. No real-device tests apply to this task.

Deviations / for the reviewer

  • Encoding is provisional: CaptureTarget max 1920x1080 at the settings' fps (15-60), EncodeParams = captured size scaled to fit (even), 3 Mbit/s; codec = preferred_screen_share_codec, VP8 for Auto. Screen share 11 (encode_params, capture_target) and 12 (select_codec) replace these.
  • Stream audio: Start.audio is Some(AudioRule::default()) when share_app_audio (window) / share_desktop_audio (screen, system picker) is on; with_audio follows it.
  • CaptureEvent::Ended { Cancelled } while live (a cancelled switch in the portal) keeps the share; while starting it returns to Idle silently. CaptureEvent::Error is treated as fatal.
  • Merged the current origin/screenshare (Screen share 9 is now on it; conflicts in app.rs/event.rs with the profiles work resolved by keeping both).
  • Added STOP_TIMEOUT (5 s) and GoLive::is_published(), not in the plan.
  • The go-live reducer runs from reduce_streams, which now takes me, guilds, channels and effects (app.rs one call); it needs guilds for the permission check. event.rs (the new UserActions) and persist.rs (save on SetMuteStreamAudio) touched minimally, outside the Files list. local.rs was not touched: the merged code builds op 4 in connection.rs (Announced), so self_stream went there.

Closes #157

🤖 Generated with Claude Code

## What this builds `fluxer-core::voice::stream::golive` (spec §3.1, §6.3 "Go live", "Stop", "Change stream", "Sharer audio mute"): - `GoLive { Idle, Picking { switch }, Starting { source, since }, Live { source, video_sid, audio_sid, codec, params }, Stopping }` in `Streams.outgoing`; `can_stream(&App) -> Result<(), CannotStream::{NotConnected, NoPermission}>` (connected room, STREAM `1 << 9` or ADMINISTRATOR; DM calls allowed). - `UserAction::{OpenScreenSharePicker { switch }, CloseScreenSharePicker, StartScreenShare(SourceChoice), ChangeScreenShareSource(SourceChoice), StopScreenShare, SetMuteStreamAudio(bool)}`. - Opening the picker emits `CaptureCommand::ListSources { thumbnails: true }`, or `Start { source: SystemPicker, .. }` at once once the backend listed itself without an in-app picker (a listing that arrives while the picker is open and says "no in-app picker" also starts the system picker). - Start order: capture `Start` (30 s `START_TIMEOUT`) -> capture `Started` -> `PublishScreenShare` -> room `LocalTrackPublished(ScreenShare)` -> op 4 `self_stream: true` -> op 4 adding the own key -> `Chime::ScreenShareStart`. `Announced` (connection.rs) now carries `self_stream`, and the own key is appended to `viewer_stream_keys` only while the video is published in the connection's channel, so every op 4 (mute, deafen, watch, resend after READY) carries the current stream flag and key, never before the publication. - Stop order: op 4 `self_stream: false` (own key still listed) -> `UnpublishScreenShare` -> `CaptureCommand::Stop` -> op 4 without own key -> `Chime::ScreenShareStop`; then `Stopping` until the video's `LocalTrackUnpublished` (or `STOP_TIMEOUT`, 5 s). - Triggers: user, capture `Ended`/`Error`, STREAM lost (permissions recomputed after every event) or the gateway clearing `self_stream` after it had confirmed it, leave, move (the move op 4 already says `self_stream: false`, no extra op 4), room lost / replaced, logout (capture stopped, unpublished). - Change stream: `CaptureCommand::Switch`, publication kept; the switch picker keeps the running share (it still announces while the picker is open). - `SetMuteStreamAudio` sets `video.mute_stream_audio` (persisted) and sends `SetScreenShareAudioMuted`; a share started with it on mutes its audio track when that is published. ## Tests `crates/fluxer-core/tests/stream_golive.rs`: `start_order_capture_publish_op4_ownkey_chime`, `self_stream_never_true_before_publication`, `stop_order_op4_before_unpublish`, `capture_ended_stops_share`, `portal_cancel_returns_idle_without_op4`, `start_timeout_30s`, `permission_loss_stops_share`, `disconnect_and_move_reset_stream`, `change_source_keeps_publication`, `no_permission_blocks_start_with_reason`, extra `sharer_audio_mute_mutes_published_track`, and proptest `any_event_order_keeps_golive_consistent` (128 random event orders: no op 4 says `self_stream`/own key unless the video is published, at most one capture runs, publish only after a started capture, every way back to Idle stops a started capture). `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` green locally. No real-device tests apply to this task. ## Deviations / for the reviewer - Encoding is provisional: `CaptureTarget` max 1920x1080 at the settings' fps (15-60), `EncodeParams` = captured size scaled to fit (even), 3 Mbit/s; codec = `preferred_screen_share_codec`, VP8 for Auto. Screen share 11 (`encode_params`, `capture_target`) and 12 (`select_codec`) replace these. - Stream audio: `Start.audio` is `Some(AudioRule::default())` when `share_app_audio` (window) / `share_desktop_audio` (screen, system picker) is on; `with_audio` follows it. - `CaptureEvent::Ended { Cancelled }` while live (a cancelled switch in the portal) keeps the share; while starting it returns to Idle silently. `CaptureEvent::Error` is treated as fatal. - Merged the current origin/screenshare (Screen share 9 is now on it; conflicts in app.rs/event.rs with the profiles work resolved by keeping both). - Added `STOP_TIMEOUT` (5 s) and `GoLive::is_published()`, not in the plan. - The go-live reducer runs from `reduce_streams`, which now takes `me`, guilds, channels and effects (app.rs one call); it needs guilds for the permission check. `event.rs` (the new `UserAction`s) and `persist.rs` (save on `SetMuteStreamAudio`) touched minimally, outside the Files list. `local.rs` was not touched: the merged code builds op 4 in `connection.rs` (`Announced`), so `self_stream` went there. Closes #157 🤖 Generated with [Claude Code](https://claude.com/claude-code)
feat(core): watching streams
All checks were successful
ci / Linux (x86_64) (push) Successful in 15m9s
ci / Windows (x64) (push) Successful in 13m43s
748af6f771
Watch, add and stop watching screen shares; every op 4 carries the
viewer keys the gateway accepts with the current flags; keys pruned when
the streamer leaves and rewritten on its new connection; screen-share
video/audio subscribed while watched (audio not while deafened); stream
volume and mute persisted with a 6 h TTL in store time; viewer chimes
debounced and cooled down; remote stream playback states.

Refs #156

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	crates/fluxer-core/src/voice/connection.rs
Refs #157

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

Independent review: Screen share 10 (core go-live)

Scope: git diff 9d3c24d..origin/screenshare-10-core-go-live (00c776d).

Tests (plan step 1): all 11 named tests exist (start_order_capture_publish_op4_ownkey_chime, self_stream_never_true_before_publication, stop_order_op4_before_unpublish, capture_ended_stops_share, portal_cancel_returns_idle_without_op4, start_timeout_30s, permission_loss_stops_share, disconnect_and_move_reset_stream, change_source_keeps_publication, no_permission_blocks_start_with_reason, proptest any_event_order_keeps_golive_consistent), plus sharer_audio_mute_mutes_published_track. They assert the spec's order and values: START_TIMEOUT == 30 s; start = capture Start, then Publish, then (on LocalTrackPublished of the video) op 4 self_stream:true with no own key, then op 4 with the own key, then ScreenShareStart; stop = op 4 self_stream:false with the own key still listed, then Unpublish, then Capture Stop, then op 4 without the key, then ScreenShareStop; a portal cancel or timeout sends no op 4.

Interfaces: GoLive matches spec §6.1 exactly. The six UserActions, can_stream(&App) -> Result<(), CannotStream::{NotConnected, NoPermission}> and the picker behaviour (ListSources { thumbnails: true }, or Start { SystemPicker } once the backend says it has no in-app picker) are present as written. Additions: STOP_TIMEOUT, GoLive::is_published. The op 4 lives in connection.rs (Announced.self_stream), not local.rs. That is fine because the merged code builds op 4 there.

Invariants: fluxer-core gains no dependency and no pixels or samples. Server data cannot panic it (provisional_params guards zero sizes, u64 math). No secrets.

Review Focus 1: satisfied. own_stream_key gates both self_stream and the own key on a confirmed video publication in the share's channel. Every op 4 goes through announced(), which carries the mute, deaf and stream flags and the viewer keys. The proptest checks that no op 4 carries self_stream or the own key before publication.

Implementer's questions:

  • Ended{Cancelled} while Live keeps the share. I agree for a cancelled system-picker switch. One caveat: if a backend tears down the old capture when the portal switch is cancelled, the share stays published with no frames. Task 4 and Task 21 should make sure a cancelled Switch keeps the old capture running.
  • CaptureEvent::Error is fatal: agreed.
  • Gateway self_stream:false counts only after the gateway has confirmed true: agreed, and it is reset per share.

Findings

  • minor: if the gateway silently forces self_stream:false from the start (for example a permission the client does not model), the share is never confirmed. It then stays Live and published but invisible, with no end. Consider a confirmation timeout later (follow-up material, not blocking).
  • minor: SetMuteStreamAudio changes settings.video only inside the logged-in reducer, while the other voice settings go through reduce_settings, which runs logged in or not. It is harmless today because the action is only reachable while connected.
  • minor: event.rs and persist.rs changed outside the plan's Files list. The changes are small and correct; this is noted only as a scope deviation.

Local CI: cargo xtask ci in a fresh worktree passed (all steps passed, exit 0; screenshot and livekit steps skipped as the defaults say).

Verdict: APPROVED. No blocking findings; CI green.

## Independent review: Screen share 10 (core go-live) Scope: `git diff 9d3c24d..origin/screenshare-10-core-go-live` (00c776d). **Tests (plan step 1):** all 11 named tests exist (`start_order_capture_publish_op4_ownkey_chime`, `self_stream_never_true_before_publication`, `stop_order_op4_before_unpublish`, `capture_ended_stops_share`, `portal_cancel_returns_idle_without_op4`, `start_timeout_30s`, `permission_loss_stops_share`, `disconnect_and_move_reset_stream`, `change_source_keeps_publication`, `no_permission_blocks_start_with_reason`, proptest `any_event_order_keeps_golive_consistent`), plus `sharer_audio_mute_mutes_published_track`. They assert the spec's order and values: `START_TIMEOUT == 30 s`; start = capture Start, then Publish, then (on `LocalTrackPublished` of the video) op 4 `self_stream:true` with no own key, then op 4 with the own key, then `ScreenShareStart`; stop = op 4 `self_stream:false` with the own key still listed, then Unpublish, then Capture Stop, then op 4 without the key, then `ScreenShareStop`; a portal cancel or timeout sends no op 4. **Interfaces:** `GoLive` matches spec §6.1 exactly. The six `UserAction`s, `can_stream(&App) -> Result<(), CannotStream::{NotConnected, NoPermission}>` and the picker behaviour (`ListSources { thumbnails: true }`, or `Start { SystemPicker }` once the backend says it has no in-app picker) are present as written. Additions: `STOP_TIMEOUT`, `GoLive::is_published`. The op 4 lives in `connection.rs` (`Announced.self_stream`), not `local.rs`. That is fine because the merged code builds op 4 there. **Invariants:** fluxer-core gains no dependency and no pixels or samples. Server data cannot panic it (`provisional_params` guards zero sizes, u64 math). No secrets. **Review Focus 1:** satisfied. `own_stream_key` gates both `self_stream` and the own key on a confirmed video publication in the share's channel. Every op 4 goes through `announced()`, which carries the mute, deaf and stream flags and the viewer keys. The proptest checks that no op 4 carries `self_stream` or the own key before publication. **Implementer's questions:** - `Ended{Cancelled}` while Live keeps the share. I agree for a cancelled system-picker switch. One caveat: if a backend tears down the old capture when the portal switch is cancelled, the share stays published with no frames. Task 4 and Task 21 should make sure a cancelled `Switch` keeps the old capture running. - `CaptureEvent::Error` is fatal: agreed. - Gateway `self_stream:false` counts only after the gateway has confirmed `true`: agreed, and it is reset per share. **Findings** - minor: if the gateway silently forces `self_stream:false` from the start (for example a permission the client does not model), the share is never confirmed. It then stays Live and published but invisible, with no end. Consider a confirmation timeout later (follow-up material, not blocking). - minor: `SetMuteStreamAudio` changes `settings.video` only inside the logged-in reducer, while the other voice settings go through `reduce_settings`, which runs logged in or not. It is harmless today because the action is only reachable while connected. - minor: `event.rs` and `persist.rs` changed outside the plan's Files list. The changes are small and correct; this is noted only as a scope deviation. **Local CI:** `cargo xtask ci` in a fresh worktree passed (all steps passed, exit 0; screenshot and livekit steps skipped as the defaults say). **Verdict: APPROVED. No blocking findings; CI green.**
Refs #157

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

Independent review: Screen share 10 (core go-live)

Reviewed git diff 61a073c..origin/screenshare-10-core-go-live (merge 32d0267) cold.

(1) Plan tests: all 11 tests the plan names exist in crates/fluxer-core/tests/stream_golive.rs, plus sharer_audio_mute_mutes_published_track. They assert what the plan and spec §6.3 say. The start order is capture → publish → op 4 self_stream:true → op 4 + own key → ScreenShareStart. The stop order is op 4 self_stream:false (own key still listed) → UnpublishScreenShare → CaptureCommand::Stop → op 4 without the key → ScreenShareStop. START_TIMEOUT is 30 s, and a portal cancel or a timeout sends nothing. The proptest checks that no op 4 carries self_stream or the own key before publication.

(2) Interfaces: GoLive::{Idle, Picking{switch}, Starting{source, since: TimerId}, Live{source, video_sid, audio_sid, codec, params}, Stopping} matches spec §6.1. UserAction::{OpenScreenSharePicker{switch}, CloseScreenSharePicker, StartScreenShare, ChangeScreenShareSource, StopScreenShare, SetMuteStreamAudio} exist as named. can_stream(&App) -> Result<(), CannotStream::{NotConnected, NoPermission}> exists; it uses STREAM 1<<9, and ADMINISTRATOR or owner through permissions_in. The picker emits ListSources{thumbnails:true}, or Start{SystemPicker} when the backend has no in-app picker. Re-exported from voice::stream.

(3) Invariants: fluxer-core gets no new dependency and no pixels or samples. provisional_params cannot panic: it uses u64 arithmetic, max(2) and try_from. No secrets.

(4) Review Focus 1: satisfied. Voice::announced now derives self_stream and the own key from own_stream_key, which is Some only when the video is confirmed and the share is in the connection's channel. Every op 4 therefore carries the current mute, deaf and stream flags and the viewer keys. A move op 4 carries self_stream:false and not the old key. I checked the fork's validate_viewer_keys: it does not require the streamer to be streaming, so the stop step's op 4 (own key, self_stream:false) is accepted.

Conflict resolution (app.rs): reduce_streams(&event, me, guilds, channels, effects) runs before profiles.reduce. The two touch disjoint state, so the order is fine. CaptureEvent::Sources is still stored; it moved into golive::on_capture.

(5) Local gate: FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci is green in a fresh review worktree. All steps passed and 12/12 stream_golive tests passed.

Findings

  • minor: GoLive::Live { video_sid: None } has no timeout. If the room never reports LocalTrackPublished (a publish that fails silently), the share stays "Live" and unannounced until the user stops it. Suggest a follow-up: a publish-confirm timeout, or a publish-failure VoiceEvent.
  • minor (documented deviation): these are not in the plan: STOP_TIMEOUT (5 s), GoLive::is_published(), the Stopping wait for LocalTrackUnpublished, and the provisional codec and encode params. They are additive and listed in the PR. Tasks 11 and 12 must replace provisional_* in golive.rs.

Verdict: APPROVED. No blocking findings, and the local CI is green.

## Independent review: Screen share 10 (core go-live) Reviewed `git diff 61a073c..origin/screenshare-10-core-go-live` (merge 32d0267) cold. **(1) Plan tests:** all 11 tests the plan names exist in `crates/fluxer-core/tests/stream_golive.rs`, plus `sharer_audio_mute_mutes_published_track`. They assert what the plan and spec §6.3 say. The start order is capture → publish → op 4 `self_stream:true` → op 4 + own key → `ScreenShareStart`. The stop order is op 4 `self_stream:false` (own key still listed) → `UnpublishScreenShare` → `CaptureCommand::Stop` → op 4 without the key → `ScreenShareStop`. `START_TIMEOUT` is 30 s, and a portal cancel or a timeout sends nothing. The proptest checks that no op 4 carries `self_stream` or the own key before publication. **(2) Interfaces:** `GoLive::{Idle, Picking{switch}, Starting{source, since: TimerId}, Live{source, video_sid, audio_sid, codec, params}, Stopping}` matches spec §6.1. `UserAction::{OpenScreenSharePicker{switch}, CloseScreenSharePicker, StartScreenShare, ChangeScreenShareSource, StopScreenShare, SetMuteStreamAudio}` exist as named. `can_stream(&App) -> Result<(), CannotStream::{NotConnected, NoPermission}>` exists; it uses STREAM `1<<9`, and ADMINISTRATOR or owner through `permissions_in`. The picker emits `ListSources{thumbnails:true}`, or `Start{SystemPicker}` when the backend has no in-app picker. Re-exported from `voice::stream`. **(3) Invariants:** fluxer-core gets no new dependency and no pixels or samples. `provisional_params` cannot panic: it uses u64 arithmetic, `max(2)` and `try_from`. No secrets. **(4) Review Focus 1:** satisfied. `Voice::announced` now derives `self_stream` and the own key from `own_stream_key`, which is `Some` only when the video is confirmed and the share is in the connection's channel. Every op 4 therefore carries the current mute, deaf and stream flags and the viewer keys. A move op 4 carries `self_stream:false` and not the old key. I checked the fork's `validate_viewer_keys`: it does not require the streamer to be streaming, so the stop step's op 4 (own key, `self_stream:false`) is accepted. **Conflict resolution (app.rs):** `reduce_streams(&event, me, guilds, channels, effects)` runs before `profiles.reduce`. The two touch disjoint state, so the order is fine. `CaptureEvent::Sources` is still stored; it moved into `golive::on_capture`. **(5) Local gate:** `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` is green in a fresh review worktree. All steps passed and 12/12 stream_golive tests passed. ### Findings - **minor:** `GoLive::Live { video_sid: None }` has no timeout. If the room never reports `LocalTrackPublished` (a publish that fails silently), the share stays "Live" and unannounced until the user stops it. Suggest a follow-up: a publish-confirm timeout, or a publish-failure `VoiceEvent`. - **minor (documented deviation):** these are not in the plan: `STOP_TIMEOUT` (5 s), `GoLive::is_published()`, the `Stopping` wait for `LocalTrackUnpublished`, and the provisional codec and encode params. They are additive and listed in the PR. Tasks 11 and 12 must replace `provisional_*` in `golive.rs`. **Verdict: APPROVED.** No blocking findings, and the local CI is green.
charles manually merged commit 5096dd1ee4 into screenshare 2026-11-12 07:59:49 +00:00
Sign in to join this conversation.
No description provided.