Skip to content

Lightweight native Discord client for Windows, Linux and macOS, written in Rust. No Electron, no browser engine.

Watch several Go Live streams at once (#19)

Miroslaw Helmkec28600a42dfc
diff --git a/README.md b/README.md
index 9754762..0990eb4 100644
--- a/README.md
+++ b/README.md
@@ -238,7 +238,8 @@ GitHub uses for the releases, and starts the app on a Mac to check it.
- Per-person volume (0–200 %) and local mute, plus server mute, deafen and disconnect with permissions
- Camera video in calls
- Go Live: share a screen or window at 720p, 1080p or source quality, 15–60 fps, with audio on
- Windows 11; watch other people's streams
+ Windows 11; watch other people's streams, up to four at once, each playing in its tile, or one
+ on the stage with the call below it
- Soundboard: every server's sounds and Discord's, and you hear the ones others play
- End-to-end encrypted calls (Discord's DAVE protocol)
diff --git a/apps/rustcord/assets/call/grid-square.svg b/apps/rustcord/assets/call/grid-square.svg
new file mode 100644
index 0000000..e82fb14
--- /dev/null
+++ b/apps/rustcord/assets/call/grid-square.svg
@@ -0,0 +1 @@
+<svg width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path fill="currentColor" d="M15 11a2 2 0 0 1-2-2V4c0-1.1.9-2 2-2h5a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-5ZM2 20c0 1.1.9 2 2 2h5a2 2 0 0 0 2-2v-5a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v5ZM13 20c0 1.1.9 2 2 2h5a2 2 0 0 0 2-2v-5a2 2 0 0 0-2-2h-5a2 2 0 0 0-2 2v5ZM2 9c0 1.1.9 2 2 2h5a2 2 0 0 0 2-2V4a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v5Z"/></svg>
diff --git a/apps/rustcord/src/app.rs b/apps/rustcord/src/app.rs
index b2ac610..335cf1e 100644
--- a/apps/rustcord/src/app.rs
+++ b/apps/rustcord/src/app.rs
@@ -492,11 +492,11 @@ pub struct RustCord {
pub registry_sent: (bool, bool),
/// Listen Along: (whose Spotify, the track we last started).
pub listen_along: Option<(Id, String)>,
- /// Go Live: your stream, the one you watch, the screen picker.
+ /// Go Live: your stream, the ones you watch, the screen picker.
pub go_live: Option<crate::golive::GoLive>,
/// Your camera (see camera.rs).
pub camera: crate::camera::CameraState,
- pub watching: Option<crate::golive::Watching>,
+ pub watching: Vec<crate::golive::Watching>,
pub share_picker: Option<crate::golive::SharePicker>,
pub golive_ui: crate::golive::GoLiveUi,
/// Your full profile's server tag dropdown: where it opens.
@@ -769,7 +769,7 @@ impl RustCord {
listen_along: None,
go_live: None,
camera: Default::default(),
- watching: None,
+ watching: Vec::new(),
share_picker: None,
golive_ui: Default::default(),
tag_picker: None,
@@ -3995,7 +3995,7 @@ impl eframe::App for RustCord {
// With nothing on screen that changes by itself (no toast, nobody
// typing, no call or stream), a slow heartbeat is enough: everything
// else redraws when its event arrives.
- let lively = !self.toasts.is_empty() || self.store.typing.values().any(|t| !t.is_empty()) || self.voice.is_some() || self.go_live.is_some() || self.watching.is_some();
+ let lively = !self.toasts.is_empty() || self.store.typing.values().any(|t| !t.is_empty()) || self.voice.is_some() || self.go_live.is_some() || !self.watching.is_empty();
let every = if self.audio.is_playing() {
150
} else if lively {
@@ -4025,7 +4025,7 @@ impl eframe::App for RustCord {
self.trim_memory(ctx);
{
let (input, foreground) = ctx.input(|i| (!i.events.is_empty(), i.focused && i.viewport().minimized != Some(true)));
- let in_call = self.voice.is_some() || self.go_live.is_some() || self.watching.is_some();
+ let in_call = self.voice.is_some() || self.go_live.is_some() || !self.watching.is_empty();
let busy = self.audio.is_playing() || self.gif_picker.is_some() || self.emoji_picker.is_some();
crate::diagnostics::idle::note(input, foreground, busy, in_call);
}
diff --git a/apps/rustcord/src/golive.rs b/apps/rustcord/src/golive.rs
index d846b76..4ff9e03 100644
--- a/apps/rustcord/src/golive.rs
+++ b/apps/rustcord/src/golive.rs
@@ -26,6 +26,9 @@ pub const EXIT_FULLSCREEN: &str = "\u{E73F}";
pub const LIVE_RED: Color32 = Color32::from_rgb(0xed, 0x42, 0x45);
/// How long Discord gets to set a stream up.
const SETUP_TIMEOUT: Duration = Duration::from_secs(25);
+/// How many streams you can watch at once (each is its own video connection
+/// and decoder, so RustCord keeps it to a few).
+pub const MAX_WATCHING: usize = 4;
/// Stream generations (events of a stopped stream are ignored).
fn next_gen() -> u64 {
@@ -112,6 +115,20 @@ pub struct GoLiveUi {
pub pending_watch: Option<(Id, Id)>,
/// The voice channel's text chat is open beside the call.
pub chat_open: bool,
+ /// The stream on the stage (clicked last), whose volume and full screen
+ /// the call bar has; None: the first one.
+ pub focused: Option<Id>,
+ /// Discord's grid view: no stage, every tile the same size, the streams
+ /// you watch playing in theirs.
+ pub stream_grid: bool,
+}
+
+/// What happened to one stream on the stage this frame.
+#[derive(Default)]
+struct StreamCell {
+ double_clicked: bool,
+ close: bool,
+ menu_at: Option<egui::Pos2>,
}
/// The "Screen Share" picker: monitors and windows with thumbnails, quality, audio.
@@ -248,20 +265,45 @@ impl RustCord {
// ---- watching ---------------------------------------------------------------
- /// Op 20: watch `streamer`'s stream in the call we're in.
+ /// The stream that gets the big stage, the call bar's volume and full screen:
+ /// the one picked last (or the first one, once that ends).
+ pub fn focused_watch(&self) -> Option<&Watching> {
+ let focused = self.golive_ui.focused;
+ self.watching.iter().find(|w| Some(w.streamer) == focused).or(self.watching.first())
+ }
+
+ /// Op 20: watch `streamer`'s stream in the call you're in. Discord's rule:
+ /// with two or more others live in the call it plays beside the streams
+ /// already open (up to `MAX_WATCHING`) and the view stays as it is;
+ /// otherwise it takes their place, on the stage. Already watching it:
+ /// put it on the stage.
pub fn watch_stream(&mut self, streamer: Id) {
let Some((guild, channel)) = self.voice.as_ref().filter(|v| v.connected).map(|v| (v.guild, v.channel)) else {
self.toast("Join the voice channel to watch.", true);
return;
};
- if self.watching.as_ref().is_some_and(|w| w.streamer == streamer) {
+ if self.watching.iter().any(|w| w.streamer == streamer) {
+ self.focus_stream(Some(streamer));
+ return;
+ }
+ let me = self.store.me_id();
+ let live = self.store.voice.get(&channel).map_or(0, |users| {
+ users.iter().filter(|u| Some(**u) != me && self.store.voice_flags.get(*u).is_some_and(|f| f.streaming)).count()
+ });
+ let multiple = live >= 2;
+ // Streams of a call you've left go first; one stream replaces another.
+ let stop: Vec<Id> = self.watching.iter().filter(|w| !multiple || w.channel != channel).map(|w| w.streamer).collect();
+ for s in stop {
+ self.stop_watch(s);
+ }
+ if self.watching.len() >= MAX_WATCHING {
+ self.toast(format!("You can watch up to {MAX_WATCHING} streams at once. Stop one first."), true);
return;
}
- self.stop_watching();
let key = stream_key(guild, channel, streamer);
log::info!("watch: requesting {key}");
self.backend.send(Command::StreamWatch(key.clone()));
- self.watching = Some(Watching {
+ self.watching.push(Watching {
key,
streamer,
channel,
@@ -277,21 +319,46 @@ impl RustCord {
fullscreen: false,
viewers: Vec::new(),
});
+ if !multiple {
+ self.focus_stream(Some(streamer));
+ } else if self.watching.len() == 1 {
+ // The first of several: it plays in its tile, in the grid.
+ self.focus_stream(None);
+ }
}
- pub fn stop_watching(&mut self) {
- let Some(w) = self.watching.take() else { return };
- log::info!("watch: stopping {}", w.key);
+ /// Takes watch `i` off the list and closes its connection (without telling Discord).
+ fn drop_watch(&mut self, i: usize) -> Watching {
+ let w = self.watching.remove(i);
if let Some(h) = &w.handle {
h.stop();
}
if w.fullscreen {
self.ctx.send_viewport_cmd(egui::ViewportCommand::Fullscreen(false));
}
+ if self.golive_ui.focused == Some(w.streamer) {
+ self.golive_ui.focused = None;
+ }
+ w
+ }
+
+ /// Stop watching `streamer`'s stream; the others keep going.
+ pub fn stop_watch(&mut self, streamer: Id) {
+ let Some(i) = self.watching.iter().position(|w| w.streamer == streamer) else { return };
+ let w = self.drop_watch(i);
+ log::info!("watch: stopping {}", w.key);
self.backend.send(Command::StreamDelete(w.key));
}
- /// Leaving or losing the call ends both.
+ /// Stop watching every stream.
+ pub fn stop_watching(&mut self) {
+ let all: Vec<Id> = self.watching.iter().map(|w| w.streamer).collect();
+ for s in all {
+ self.stop_watch(s);
+ }
+ }
+
+ /// Leaving or losing the call ends them all.
pub fn end_streams(&mut self) {
self.stop_go_live();
self.stop_watching();
@@ -304,8 +371,8 @@ impl RustCord {
pub fn stream_dispatch(&mut self, name: &str, d: &Value) {
let Some(key) = d["stream_key"].as_str() else { return };
let mine = self.go_live.as_ref().is_some_and(|g| g.key == key);
- let watched = self.watching.as_ref().is_some_and(|w| w.key == key);
- if !mine && !watched {
+ let watched = self.watching.iter().position(|w| w.key == key);
+ if !mine && watched.is_none() {
return;
}
match name {
@@ -320,7 +387,8 @@ impl RustCord {
}
// Unpause it (the official app does this right after creating).
self.backend.send(Command::StreamSetPaused { key: key.to_string(), paused: false });
- } else if let Some(w) = self.watching.as_mut() {
+ } else if let Some(i) = watched {
+ let w = &mut self.watching[i];
w.setup.rtc = Some(rtc);
w.viewers = ids(&d["viewer_ids"]);
}
@@ -334,7 +402,8 @@ impl RustCord {
g.setup.server = server;
g.setup.started = false;
}
- } else if let Some(w) = self.watching.as_mut() {
+ } else if let Some(i) = watched {
+ let w = &mut self.watching[i];
w.setup.server = server;
w.setup.started = false;
}
@@ -354,7 +423,8 @@ impl RustCord {
note(before, g.viewers.len());
}
}
- if let Some(w) = self.watching.as_mut().filter(|_| watched) {
+ if let Some(i) = watched {
+ let w = &mut self.watching[i];
let before = w.viewers.len();
w.viewers = ids(&d["viewer_ids"]);
if w.connected {
@@ -376,13 +446,8 @@ impl RustCord {
if let Some(w) = why {
self.toast(format!("Your stream ended: {w}"), true);
}
- } else if let Some(w) = self.watching.take() {
- if let Some(h) = &w.handle {
- h.stop();
- }
- if w.fullscreen {
- self.ctx.send_viewport_cmd(egui::ViewportCommand::Fullscreen(false));
- }
+ } else if let Some(i) = watched {
+ self.drop_watch(i);
self.toast(why.unwrap_or("The stream ended."), false);
}
return;
@@ -412,7 +477,7 @@ impl RustCord {
self.backend.send(Command::GoLiveConnect { gen: g.gen, cfg: c, source: g.source.clone(), quality: g.quality, audio: g.audio });
}
}
- if let Some(w) = self.watching.as_mut().filter(|w| !w.setup.started) {
+ for w in self.watching.iter_mut().filter(|w| !w.setup.started) {
if let Some(c) = cfg(&w.setup) {
w.setup.started = true;
w.gen = next_gen();
@@ -432,7 +497,7 @@ impl RustCord {
Some(g) => g.handle = Some(h),
None => h.stop(),
},
- (_, Some(h)) => match self.watching.as_mut().filter(|w| w.gen == gen) {
+ (_, Some(h)) => match self.watching.iter_mut().find(|w| w.gen == gen) {
Some(w) => {
h.set_volume(w.volume);
w.handle = Some(h);
@@ -445,14 +510,14 @@ impl RustCord {
pub fn on_stream_event(&mut self, gen: u64, e: voice::StreamEvent) {
let mine = self.go_live.as_ref().is_some_and(|g| g.gen == gen);
- let watched = self.watching.as_ref().is_some_and(|w| w.gen == gen);
+ let watched = self.watching.iter().find(|w| w.gen == gen).map(|w| w.streamer);
match e {
voice::StreamEvent::Connected => {
if let Some(g) = self.go_live.as_mut().filter(|_| mine) {
log::info!("go live: live (stream {gen})");
g.connected = true;
}
- if let Some(w) = self.watching.as_mut().filter(|_| watched) {
+ if let Some(w) = self.watching.iter_mut().find(|w| w.gen == gen) {
log::info!("watch: connected (stream {gen})");
w.connected = true;
}
@@ -464,8 +529,8 @@ impl RustCord {
if mine {
self.stop_go_live();
self.toast(format!("Your stream stopped: {r}"), true);
- } else if watched {
- self.stop_watching();
+ } else if let Some(streamer) = watched {
+ self.stop_watch(streamer);
self.toast(format!("Stopped watching: {r}"), true);
}
}
@@ -479,12 +544,15 @@ impl RustCord {
self.stop_go_live();
self.toast("Discord didn't set up the stream in time. Try again.", true);
}
- if self.watching.as_ref().is_some_and(|w| !w.connected && now >= w.requested_at + SETUP_TIMEOUT) {
- self.stop_watching();
+ let late: Vec<Id> = self.watching.iter().filter(|w| !w.connected && now >= w.requested_at + SETUP_TIMEOUT).map(|w| w.streamer).collect();
+ if !late.is_empty() {
+ for s in late {
+ self.stop_watch(s);
+ }
self.toast("Couldn't connect to the stream. Try again.", true);
}
// The call went away: so do its streams.
- if self.voice.is_none() && (self.go_live.is_some() || self.watching.is_some()) {
+ if self.voice.is_none() && (self.go_live.is_some() || !self.watching.is_empty()) {
self.end_streams();
}
// "Watch Stream" from the channel list joined the call first: now watch.
@@ -498,7 +566,7 @@ impl RustCord {
_ => self.golive_ui.pending_watch = None,
}
}
- if self.go_live.is_some() || self.watching.is_some() {
+ if self.go_live.is_some() || !self.watching.is_empty() {
self.ctx.request_repaint_after(Duration::from_millis(500));
// Every 10 s: what's flowing (for diagnosing quality reports).
static LAST: std::sync::Mutex<Option<Instant>> = std::sync::Mutex::new(None);
@@ -513,8 +581,10 @@ impl RustCord {
let fmt = |s: &voice::StreamStats| {
format!("{} {}x{} {:.0}fps {}kbps via {} (dropped {}, keyframe requests {})", s.codec, s.width, s.height, s.fps, s.bitrate_kbps, s.engine, s.dropped, s.keyframe_requests)
};
- if let Some(h) = self.watching.as_ref().and_then(|w| w.handle.as_ref()) {
- log::info!("watch stats: {}", fmt(&h.stats()));
+ for w in &self.watching {
+ if let Some(h) = &w.handle {
+ log::info!("watch stats ({}): {}", w.streamer, fmt(&h.stats()));
+ }
}
if let Some(h) = self.go_live.as_ref().and_then(|g| g.handle.as_ref()) {
log::info!("go live stats: {}", fmt(&h.stats()));
@@ -525,11 +595,11 @@ impl RustCord {
/// Fresh pixels for the textures that are on screen.
fn refresh_frames(&mut self, ctx: &egui::Context) {
- if let Some(w) = self.watching.as_mut() {
+ for w in self.watching.iter_mut() {
if let Some(f) = w.handle.as_ref().and_then(|h| h.latest_frame()).filter(|f| f.seq != w.seq) {
w.seq = f.seq;
w.size = (f.width, f.height);
- upload(ctx, &mut w.frame, "go-live-watch", &f);
+ upload(ctx, &mut w.frame, &format!("go-live-watch-{}", w.streamer), &f);
}
}
if let Some(g) = self.go_live.as_mut() {
@@ -558,25 +628,62 @@ impl RustCord {
Some(if fps > 0 { format!("{p}p {fps}FPS") } else { format!("{p}p") })
}
- /// The watched stream's stats (zeros until it's up).
+ /// The focused stream's stats (zeros until it's up).
pub fn watching_stats(&self) -> voice::StreamStats {
- self.watching.as_ref().and_then(|w| w.handle.as_ref()).map(|h| h.stats()).unwrap_or_default()
+ self.focused_watch().and_then(|w| w.handle.as_ref()).map(|h| h.stats()).unwrap_or_default()
+ }
+
+ /// Put a stream you watch on the stage (clicking its tile, as in Discord),
+ /// or `None`: Discord's grid view.
+ pub fn focus_stream(&mut self, streamer: Option<Id>) {
+ self.golive_ui.stream_grid = streamer.is_none();
+ if streamer.is_some() {
+ self.golive_ui.focused = streamer;
+ }
}
- /// The stream you're watching, big, above a strip of the call's tiles.
- /// Hovering it shows Discord's "Stream Info" (codec, resolution, FPS);
- /// double-click for full screen. Returns the rect left for the tiles.
+ /// The stream on the stage, above a strip of the call's tiles, where the
+ /// other streams you watch play in their tiles (see `call_tiles`). In the
+ /// grid view there is no stage. Hovering the stream shows Discord's
+ /// "Stream Info" (codec, resolution, FPS); double-click for full screen.
+ /// Returns the rect left for the tiles.
pub fn watching_stage(&mut self, ui: &mut Ui, t: &Theme, area: Rect) -> Rect {
let ctx = ui.ctx().clone();
self.refresh_frames(&ctx);
- let stats = self.watching_stats();
- let Some(w) = self.watching.as_ref() else { return area };
+ if self.golive_ui.stream_grid {
+ return area;
+ }
+ let Some(focused) = self.focused_watch().map(|w| w.streamer) else { return area };
let strip = 118.0_f32.min(area.height() * 0.24);
let stage = Rect::from_min_max(area.min, pos2(area.right(), area.bottom() - strip - 12.0));
- let (connected, size, tex) = (w.connected, w.size, w.frame.clone());
- let p = ui.painter_at(stage);
- p.rect_filled(stage, 12.0, Color32::BLACK);
- let video = fit(stage, size.0 as f32, size.1 as f32);
+ let cell = self.paint_stream(ui, t, stage, focused, self.watching.len() > 1);
+ if cell.double_clicked {
+ self.toggle_watch_fullscreen(focused);
+ }
+ if cell.close {
+ self.stop_watch(focused);
+ }
+ if let Some(at) = cell.menu_at {
+ self.toggle_voice_menu(crate::ui::voice_menu::VoiceMenuKind::Stream(focused), Rect::from_min_size(at, vec2(1.0, 1.0)));
+ }
+ Rect::from_min_max(pos2(area.left(), area.bottom() - strip), area.max)
+ }
+
+ /// One watched stream in `rect`: its picture (or how far it got), Stream Info
+ /// on hover when there's room, and with several streams its name and a
+ /// close button.
+ fn paint_stream(&mut self, ui: &mut Ui, t: &Theme, rect: Rect, streamer: Id, several: bool) -> StreamCell {
+ let ctx = ui.ctx().clone();
+ let mut out = StreamCell::default();
+ let Some(w) = self.watching.iter().find(|w| w.streamer == streamer) else { return out };
+ let (connected, size, tex, channel) = (w.connected, w.size, w.frame.clone(), w.channel);
+ let stats = w.handle.as_ref().map(|h| h.stats()).unwrap_or_default();
+ let resp = ui.interact(rect, egui::Id::new(("watch_video", streamer.0)), Sense::click());
+ let hovered = ui.rect_contains_pointer(rect);
+ let p = ui.painter_at(rect.expand(3.0));
+ p.rect_filled(rect, 12.0, Color32::BLACK);
+ let video = fit(rect, size.0 as f32, size.1 as f32);
+ let small = rect.width() < 320.0;
match &tex {
Some(tex) => {
// Drawn at its own size when it fits (1:1 pixels are sharpest).
@@ -584,14 +691,15 @@ impl RustCord {
}
None => {
let text = if connected { "Waiting for the first frame…" } else { "Connecting to the stream…" };
- p.text(stage.center() - vec2(0.0, 14.0), Align2::CENTER_CENTER, SCREEN, icon_font(30.0), t.text_muted);
- p.text(stage.center() + vec2(0.0, 22.0), Align2::CENTER_CENTER, text, FontId::proportional(14.0), t.text_muted);
+ let (icon, font) = if small { (20.0, 12.0) } else { (30.0, 14.0) };
+ p.text(rect.center() - vec2(0.0, icon * 0.5), Align2::CENTER_CENTER, SCREEN, icon_font(icon), t.text_muted);
+ p.text(rect.center() + vec2(0.0, font * 1.6), Align2::CENTER_CENTER, text, FontId::proportional(font), t.text_muted);
ctx.request_repaint_after(Duration::from_millis(250));
}
}
+ let bold = |size: f32| FontId::new(size, egui::FontFamily::Name(crate::style::BOLD.into()));
// Stream Info, top-left, while the pointer is on it.
- if ui.rect_contains_pointer(stage) && tex.is_some() {
- let bold = FontId::new(13.0, egui::FontFamily::Name(crate::style::BOLD.into()));
+ if hovered && tex.is_some() && !small {
let rows = [
("Video Codec:", if stats.codec.is_empty() { "H264".to_string() } else { stats.codec.to_string() }),
("Resolution:", if stats.width > 0 { format!("{} x {}", stats.width, stats.height) } else { format!("{} x {}", size.0, size.1) }),
@@ -605,51 +713,69 @@ impl RustCord {
extra.push(("Decoder:", stats.engine.to_string()));
}
let lines = 1 + rows.len() + extra.len();
- let card = Rect::from_min_size(stage.min + vec2(12.0, 12.0), vec2(210.0, 12.0 + 19.0 * lines as f32));
+ let card = Rect::from_min_size(rect.min + vec2(12.0, 12.0), vec2(210.0, 12.0 + 19.0 * lines as f32));
p.rect_filled(card, 8.0, Color32::from_black_alpha(185));
- p.text(card.min + vec2(10.0, 8.0), Align2::LEFT_TOP, "Stream Info", bold.clone(), Color32::WHITE);
+ p.text(card.min + vec2(10.0, 8.0), Align2::LEFT_TOP, "Stream Info", bold(13.0), Color32::WHITE);
for (i, (k, v)) in rows.iter().map(|(k, v)| (*k, v.clone())).chain(extra.into_iter()).enumerate() {
let y = card.top() + 8.0 + 19.0 * (i + 1) as f32;
p.text(pos2(card.left() + 10.0, y), Align2::LEFT_TOP, k, FontId::proportional(12.5), crate::style::rgba(255, 255, 255, 200));
- p.text(pos2(card.right() - 10.0, y), Align2::RIGHT_TOP, v, bold.clone(), Color32::WHITE);
+ p.text(pos2(card.right() - 10.0, y), Align2::RIGHT_TOP, v, bold(13.0), Color32::WHITE);
}
// Keep the numbers fresh while it's shown.
ctx.request_repaint_after(Duration::from_millis(500));
}
- // Double-click the picture: full screen, like Discord. Right-click: the stream's menu.
- let streamer = w.streamer;
- let resp = ui.interact(stage, egui::Id::new("watch_video"), Sense::click());
- if resp.double_clicked() {
- self.toggle_watch_fullscreen();
+ if several {
+ // Whose stream it is, bottom-left.
+ let gid = self.store.channels.get(&channel).and_then(|c| c.guild_id);
+ let name = self.store.nick_in(gid, Some(channel), streamer).or_else(|| self.store.users.get(&streamer).map(|u| u.display_name().to_string())).unwrap_or_default();
+ let g = p.layout_no_wrap(name, bold(12.5), Color32::WHITE);
+ let label = Rect::from_min_size(pos2(rect.left() + 8.0, rect.bottom() - 8.0 - 22.0), vec2(g.size().x + 16.0, 22.0));
+ p.rect_filled(label, 6.0, Color32::from_black_alpha(170));
+ p.galley(pos2(label.left() + 8.0, label.center().y - g.size().y / 2.0), g, Color32::WHITE);
+ // Stop watching this one, top-right, while the pointer is on it.
+ if hovered {
+ let b = Rect::from_min_size(pos2(rect.right() - 8.0 - 28.0, rect.top() + 8.0), vec2(28.0, 28.0));
+ let r = ui.interact(b, egui::Id::new(("watch_close", streamer.0)), Sense::click()).on_hover_cursor(CursorIcon::PointingHand);
+ p.rect_filled(b, 8.0, if r.hovered() { LIVE_RED } else { Color32::from_black_alpha(170) });
+ p.text(b.center(), Align2::CENTER_CENTER, crate::style::icon::CLOSE, icon_font(12.0), Color32::WHITE);
+ out.close = r.on_hover_text("Stop Watching").clicked();
+ }
}
+ // Double-click the picture: full screen, like Discord. Right-click: the stream's menu.
+ out.double_clicked = resp.double_clicked();
if resp.secondary_clicked() {
- let at = resp.interact_pointer_pos().unwrap_or(stage.center());
- self.toggle_voice_menu(crate::ui::voice_menu::VoiceMenuKind::Stream(streamer), Rect::from_min_size(at, vec2(1.0, 1.0)));
+ out.menu_at = Some(resp.interact_pointer_pos().unwrap_or(rect.center()));
}
- Rect::from_min_max(pos2(area.left(), area.bottom() - strip), area.max)
+ out
}
- pub fn toggle_watch_fullscreen(&mut self) {
- if let Some(w) = self.watching.as_mut() {
- w.fullscreen = !w.fullscreen;
- self.ctx.send_viewport_cmd(egui::ViewportCommand::Fullscreen(w.fullscreen));
+ /// Full screen for `streamer`'s stream (or back); only one stream at a time.
+ pub fn toggle_watch_fullscreen(&mut self, streamer: Id) {
+ let mut on = false;
+ for w in self.watching.iter_mut() {
+ w.fullscreen = w.streamer == streamer && !w.fullscreen;
+ on |= w.fullscreen;
+ }
+ if on {
+ self.golive_ui.focused = Some(streamer);
}
+ self.ctx.send_viewport_cmd(egui::ViewportCommand::Fullscreen(on));
}
- /// The watched stream's volume (0–2), applied at once; remembered for that streamer
- /// and saved when `save` (the slider let go).
- pub fn set_watch_volume(&mut self, v: f32, save: bool) {
- let Some(w) = self.watching.as_mut() else { return };
+ /// `streamer`'s stream volume (0–2), applied at once; remembered for that
+ /// streamer and saved when `save` (the slider let go).
+ pub fn set_watch_volume(&mut self, streamer: Id, v: f32, save: bool) {
+ let Some(w) = self.watching.iter_mut().find(|w| w.streamer == streamer) else { return };
w.volume = v.clamp(0.0, 2.0);
if let Some(h) = &w.handle {
h.set_volume(w.volume);
}
- let (streamer, percent) = (w.streamer.0, w.volume * 100.0);
+ let percent = w.volume * 100.0;
let volumes = &mut self.voice_ui.prefs.stream_volumes;
if (percent - 100.0).abs() < 0.5 {
- volumes.remove(&streamer);
+ volumes.remove(&streamer.0);
} else {
- volumes.insert(streamer, percent);
+ volumes.insert(streamer.0, percent);
}
if save {
self.voice_ui.changed();
@@ -658,14 +784,21 @@ impl RustCord {
/// The volume of `streamer`'s stream in percent, while you watch it.
pub fn watched_stream_volume(&self, streamer: Id) -> Option<f32> {
- self.watching.as_ref().filter(|w| w.streamer == streamer).map(|w| w.volume * 100.0)
+ self.watching.iter().find(|w| w.streamer == streamer).map(|w| w.volume * 100.0)
+ }
+
+ /// Whether `streamer`'s stream is the one shown full screen.
+ pub fn watch_is_fullscreen(&self, streamer: Id) -> bool {
+ self.watching.iter().any(|w| w.streamer == streamer && w.fullscreen)
}
/// Full screen: the picture over everything, Esc (or double-click) to leave.
pub fn watching_fullscreen_ui(&mut self, ctx: &egui::Context) {
- let Some(w) = self.watching.as_ref().filter(|w| w.fullscreen) else { return };
- let (tex, size, streamer) = (w.frame.clone(), w.size, w.streamer);
+ let Some(w) = self.watching.iter().find(|w| w.fullscreen) else { return };
+ let streamer = w.streamer;
self.refresh_frames(ctx);
+ let Some(w) = self.watching.iter().find(|w| w.streamer == streamer) else { return };
+ let (tex, size) = (w.frame.clone(), w.size);
let screen = ctx.screen_rect();
// Esc closes an open menu first.
let menu_open = self.voice_menu_open(crate::ui::voice_menu::VoiceMenuKind::Stream(streamer));
@@ -690,7 +823,7 @@ impl RustCord {
self.toggle_voice_menu(crate::ui::voice_menu::VoiceMenuKind::Stream(streamer), Rect::from_min_size(at, vec2(1.0, 1.0)));
}
if leave {
- if let Some(w) = self.watching.as_mut() {
+ for w in self.watching.iter_mut() {
w.fullscreen = false;
}
ctx.send_viewport_cmd(egui::ViewportCommand::Fullscreen(false));
@@ -772,7 +905,7 @@ impl RustCord {
let key = stream_key(guild, channel, streamer);
let preview = self.stream_preview(&key);
let activity = self.stream_activity(streamer);
- let watching = self.watching.as_ref().is_some_and(|w| w.streamer == streamer);
+ let watching = self.watching.iter().any(|w| w.streamer == streamer);
let mut watch = false;
let area = egui::Area::new(egui::Id::new("stream_card")).order(Order::Foreground).fixed_pos(at).constrain(true).show(ctx, |ui| {
Frame::none()
diff --git a/apps/rustcord/src/ui/call.rs b/apps/rustcord/src/ui/call.rs
index 2fe199c..17de1ac 100644
--- a/apps/rustcord/src/ui/call.rs
+++ b/apps/rustcord/src/ui/call.rs
@@ -144,7 +144,7 @@ impl RustCord {
p.text(pos2(header.left() + 24.0, cy), Align2::CENTER_CENTER, icon::SPEAK, icon_font(18.0), t.interactive_normal);
let bold = |size: f32| FontId::new(size, egui::FontFamily::Name(crate::style::BOLD.into()));
let title = paint_text_emoji(ui, &p, pos2(header.left() + 42.0, cy), &name, bold(16.0), t.header_primary);
- let watching = self.watching.as_ref().filter(|w| w.channel == channel).map(|w| (w.streamer, w.viewers.clone()));
+ let watching = self.focused_watch().filter(|w| w.channel == channel).map(|w| (w.streamer, w.viewers.clone()));
let mut right = header.right() - 12.0;
let mut header_button = |ui: &mut Ui, id: &str, glyph: &str, on: bool, tip: &str| -> bool {
let b = Rect::from_center_size(pos2(right - 17.0, cy), vec2(34.0, 34.0));
@@ -319,7 +319,10 @@ impl RustCord {
let ctx = ui.ctx().clone();
// Your tile shows your stream, else your camera.
let own = self.own_stream_texture(&ctx).or_else(|| self.camera_texture(&ctx));
- let watched = self.watching.as_ref().filter(|w| w.channel == channel).map(|w| w.streamer);
+ // The streams you watch play in their tiles, but for the one on the stage.
+ let on_stage = (!self.golive_ui.stream_grid).then(|| self.focused_watch().map(|w| w.streamer)).flatten();
+ let watched: Vec<(Id, Option<egui::TextureHandle>)> =
+ self.watching.iter().filter(|w| w.channel == channel).map(|w| (w.streamer, w.frame.clone())).collect();
let in_this_call = self.voice.as_ref().is_some_and(|v| v.channel == channel);
for tile in tiles.iter_mut() {
if tile.me {
@@ -328,9 +331,11 @@ impl RustCord {
// Their camera.
tile.preview = self.camera.remote_texture(&ctx, tile.id.0);
}
- // The one you're watching is on the big stage already.
- if Some(tile.id) == watched {
+ if let Some((_, frame)) = watched.iter().find(|(s, _)| *s == tile.id) {
tile.streaming = false;
+ if Some(tile.id) != on_stage && frame.is_some() {
+ tile.preview = frame.clone();
+ }
} else if tile.streaming && !tile.me && tile.preview.is_none() {
let key = crate::golive::stream_key(gid, channel, tile.id);
tile.stream_preview = self.stream_preview(&key);
@@ -412,7 +417,10 @@ impl RustCord {
self.toggle_voice_menu(super::voice_menu::VoiceMenuKind::User(uid), Rect::from_min_size(at, vec2(1.0, 1.0)));
}
if let Some((i, at)) = clicked {
- if tiles[i].streaming && !tiles[i].me {
+ if watched.iter().any(|(s, _)| *s == tiles[i].id) {
+ // A stream you watch: onto the stage.
+ self.focus_stream(Some(tiles[i].id));
+ } else if tiles[i].streaming && !tiles[i].me {
self.watch_from_list(tiles[i].id, channel);
} else if let Some(user) = tiles[i].user.clone() {
self.open_profile(user, gid, at + vec2(12.0, -60.0));
@@ -581,8 +589,9 @@ impl RustCord {
// Hang up (or, while watching a stream, stop watching).
let end = Rect::from_min_size(pos2(x, cy - 25.0), vec2(hang_w, 50.0));
let red = Color32::from_rgb(210, 45, 57);
- let watching = self.watching.is_some();
- if watching {
+ // The focused stream gets the bar's volume and full screen.
+ let focused = self.focused_watch().map(|w| (w.streamer, w.volume, w.fullscreen));
+ if focused.is_some() {
if round_button(ui, end, egui::Id::new("call_stop_watching"), red, red.lerp_to_gamma(Color32::BLACK, 0.15), crate::style::icon::CLOSE, 18.0, Color32::WHITE, "Stop Watching").clicked() {
self.stop_watching();
}
@@ -604,15 +613,22 @@ impl RustCord {
}
}
}
- if watching {
- // Right end: stream volume (click for the slider) and full screen.
+ if let Some((streamer, volume, fullscreen)) = focused {
+ // Right end: stream volume (click for the slider), full screen and,
+ // while a stream is on the stage, Discord's grid view.
let full = Rect::from_center_size(pos2(bar.right() - 34.0, cy), vec2(40.0, 40.0));
let vol = Rect::from_center_size(pos2(bar.right() - 80.0, cy), vec2(40.0, 40.0));
- let fullscreen = self.watching.as_ref().is_some_and(|w| w.fullscreen);
if round_button(ui, full, egui::Id::new("call_fullscreen"), Color32::TRANSPARENT, overlay(0.16), if fullscreen { crate::golive::EXIT_FULLSCREEN } else { crate::golive::FULLSCREEN }, 17.0, t.header_primary, if fullscreen { "Exit Full Screen" } else { "Full Screen" }).clicked() {
- self.toggle_watch_fullscreen();
+ self.toggle_watch_fullscreen(streamer);
+ }
+ if !self.golive_ui.stream_grid {
+ let lay = Rect::from_center_size(pos2(bar.right() - 126.0, cy), vec2(40.0, 40.0));
+ if round_button(ui, lay, egui::Id::new("call_grid_view"), Color32::TRANSPARENT, overlay(0.16), "", 17.0, t.header_primary, "Grid View").clicked() {
+ self.focus_stream(None);
+ }
+ let icon = super::add_server::tinted_svg("grid-square", include_bytes!("../../assets/call/grid-square.svg"), t.header_primary);
+ egui::Image::new(icon).fit_to_exact_size(vec2(20.0, 20.0)).paint_at(ui, Rect::from_center_size(lay.center(), vec2(20.0, 20.0)));
}
- let volume = self.watching.as_ref().map_or(1.0, |w| w.volume);
let glyph = if volume <= 0.001 { SPEAKER_OFF } else { crate::style::icon::SPEAK };
let vr = round_button(ui, vol, egui::Id::new("call_stream_volume"), Color32::TRANSPARENT, overlay(0.16), glyph, 17.0, t.header_primary, "Stream Volume");
let open_id = egui::Id::new("call_stream_volume_open");
@@ -641,7 +657,7 @@ impl RustCord {
});
let (v, done) = resp.inner;
if (v - volume).abs() > f32::EPSILON || done {
- self.set_watch_volume(v, done);
+ self.set_watch_volume(streamer, v, done);
}
let outside = ui.input(|i| i.pointer.any_pressed() && i.pointer.interact_pos().is_some_and(|p| !resp.response.rect.contains(p) && !vol.contains(p)));
if outside {
@@ -852,7 +868,7 @@ impl RustCord {
/// or watched stream (used to switch the DM call panel into grid / stage mode).
pub fn dm_call_has_video(&self, channel: Id) -> bool {
let in_call = self.voice.as_ref().is_some_and(|v| v.channel == channel);
- if in_call && (self.watching.as_ref().is_some_and(|w| w.channel == channel) || self.go_live.as_ref().is_some_and(|g| g.channel == channel) || self.camera.on.is_some()) {
+ if in_call && (self.watching.iter().any(|w| w.channel == channel) || self.go_live.as_ref().is_some_and(|g| g.channel == channel) || self.camera.on.is_some()) {
return true;
}
self.store.voice.get(&channel).is_some_and(|users| users.iter().any(|id| self.store.voice_flags.get(id).is_some_and(|f| f.streaming || f.video)))
@@ -871,7 +887,7 @@ impl RustCord {
let ringing = self.calls.get(&channel).map(|c| c.ringing.clone()).unwrap_or_default();
let bar_h = 76.0;
let stage = Rect::from_min_max(area.min, pos2(area.right(), area.bottom() - bar_h));
- let watched = in_call.then(|| self.watching.as_ref().filter(|w| w.channel == channel).map(|w| (w.streamer, w.viewers.clone()))).flatten();
+ let watched = in_call.then(|| self.focused_watch().filter(|w| w.channel == channel).map(|w| (w.streamer, w.viewers.clone()))).flatten();
if self.dm_call_has_video(channel) {
if let Some((streamer, viewers)) = watched {
let hdr = Rect::from_min_size(stage.min, vec2(stage.width(), 32.0));
diff --git a/apps/rustcord/src/ui/chat.rs b/apps/rustcord/src/ui/chat.rs
index f251b9f..5703e19 100644
--- a/apps/rustcord/src/ui/chat.rs
+++ b/apps/rustcord/src/ui/chat.rs
@@ -955,7 +955,7 @@ impl RustCord {
self.chat_side_panel(ui);
// A call in this DM: Discord's call area above the messages.
if channel.guild_id.is_none() && self.dm_call_visible(ch) {
- let watching = self.voice.as_ref().is_some_and(|v| v.channel == ch) && self.watching.as_ref().is_some_and(|w| w.channel == ch);
+ let watching = self.voice.as_ref().is_some_and(|v| v.channel == ch) && self.watching.iter().any(|w| w.channel == ch);
let height = if watching {
let max_h = (ui.available_height() - 150.0).max(320.0);
(ui.available_height() * 0.68).clamp(320.0, max_h)
diff --git a/apps/rustcord/src/ui/moderation.rs b/apps/rustcord/src/ui/moderation.rs
index 72d8691..418b1dd 100644
--- a/apps/rustcord/src/ui/moderation.rs
+++ b/apps/rustcord/src/ui/moderation.rs
@@ -829,7 +829,7 @@ impl RustCord {
Pick::AddNote => self.open_full_profile(user, Some(g)),
Pick::FriendNickname => self.open_friend_nickname(uid),
Pick::Volume(v, done) => self.set_user_volume(uid, v, done),
- Pick::StreamVolume(v, done) => self.set_watch_volume(v / 100.0, done),
+ Pick::StreamVolume(v, done) => self.set_watch_volume(uid, v / 100.0, done),
Pick::LocalMute => self.toggle_local_mute(uid),
Pick::SelfDeafen => self.toggle_self_deaf(),
Pick::Nickname => {
diff --git a/apps/rustcord/src/ui/updates.rs b/apps/rustcord/src/ui/updates.rs
index 769eb61..154e478 100644
--- a/apps/rustcord/src/ui/updates.rs
+++ b/apps/rustcord/src/ui/updates.rs
@@ -28,7 +28,7 @@ impl RustCord {
/// The title bar button or Settings' "Restart": restart into the update,
/// asking first during a call.
pub fn install_update(&mut self, ctx: &egui::Context) {
- if self.voice.is_some() || self.go_live.is_some() || self.watching.is_some() {
+ if self.voice.is_some() || self.go_live.is_some() || !self.watching.is_empty() {
self.update_confirm = true;
} else {
log::info!("updater: restarting into the new version");
diff --git a/apps/rustcord/src/ui/voice_menu.rs b/apps/rustcord/src/ui/voice_menu.rs
index b6961de..90beb04 100644
--- a/apps/rustcord/src/ui/voice_menu.rs
+++ b/apps/rustcord/src/ui/voice_menu.rs
@@ -83,10 +83,10 @@ enum Act {
Invite,
ShowNonVideo,
UserVolume(Id, f32, bool),
- StreamVolume(f32, bool),
- StreamFullscreen,
+ StreamVolume(Id, f32, bool),
+ StreamFullscreen(Id),
WatchStream(Id),
- StopWatching,
+ StopWatching(Id),
LocalMute(Id),
Profile(Id),
Mention(Id),
@@ -387,7 +387,7 @@ impl RustCord {
VoiceMenuKind::User(uid) | VoiceMenuKind::Stream(uid) => self.watched_stream_volume(uid),
_ => None,
};
- let fullscreen = self.watching.as_ref().is_some_and(|w| w.fullscreen);
+ let fullscreen = matches!(kind, VoiceMenuKind::Stream(s) if self.watch_is_fullscreen(s));
let (pivot, pos) = match kind {
VoiceMenuKind::Input | VoiceMenuKind::Output => (Align2::LEFT_BOTTOM, pos2(menu.anchor.left(), menu.anchor.top() - 4.0)),
@@ -526,14 +526,14 @@ impl RustCord {
let mut v = stream_volume.unwrap_or(100.0);
let (changed, done) = slider_row(ui, &t, egui::Id::new(("vm_stream_vol", streamer.0)), "Stream Volume", &mut v, 200.0);
if changed || done {
- acts.push(Act::StreamVolume(v, done));
+ acts.push(Act::StreamVolume(streamer, v, done));
}
separator(ui, &t);
if item_row(ui, &t, None, if fullscreen { "Exit Full Screen" } else { "Full Screen" }, false).clicked() {
- acts.push(Act::StreamFullscreen);
+ acts.push(Act::StreamFullscreen(streamer));
}
if item_row(ui, &t, None, "Stop Watching", true).clicked() {
- acts.push(Act::StopWatching);
+ acts.push(Act::StopWatching(streamer));
}
}
VoiceMenuKind::Notify(_) => {
@@ -562,10 +562,10 @@ impl RustCord {
}
if !is_me {
if flags.streaming {
- let watching_them = self.watching.as_ref().is_some_and(|w| w.streamer == uid);
+ let watching_them = self.watching.iter().any(|w| w.streamer == uid);
let label = if watching_them { "Stop Watching" } else { "Watch Stream" };
if item_row(ui, &t, Some(crate::golive::SCREEN), label, false).clicked() {
- acts.push(if watching_them { Act::StopWatching } else { Act::WatchStream(uid) });
+ acts.push(if watching_them { Act::StopWatching(uid) } else { Act::WatchStream(uid) });
}
}
separator(ui, &t);
@@ -577,7 +577,7 @@ impl RustCord {
if let Some(mut v) = stream_volume {
let (changed, done) = slider_row(ui, &t, egui::Id::new(("vm_stream_vol", uid.0)), "Stream Volume", &mut v, 200.0);
if changed || done {
- acts.push(Act::StreamVolume(v, done));
+ acts.push(Act::StreamVolume(uid, v, done));
}
}
if check_row(ui, &t, "Mute", local_mute).clicked() {
@@ -737,9 +737,9 @@ impl RustCord {
self.voice_ui.changed();
}
Act::UserVolume(uid, v, done) => self.set_user_volume(uid, v, done),
- Act::StreamVolume(v, done) => self.set_watch_volume(v / 100.0, done),
- Act::StreamFullscreen => {
- self.toggle_watch_fullscreen();
+ Act::StreamVolume(uid, v, done) => self.set_watch_volume(uid, v / 100.0, done),
+ Act::StreamFullscreen(uid) => {
+ self.toggle_watch_fullscreen(uid);
close = true;
}
Act::WatchStream(uid) => {
@@ -748,8 +748,8 @@ impl RustCord {
}
close = true;
}
- Act::StopWatching => {
- self.stop_watching();
+ Act::StopWatching(uid) => {
+ self.stop_watch(uid);
close = true;
}
Act::LocalMute(uid) => self.toggle_local_mute(uid),
diff --git a/apps/rustcord/src/voice_call.rs b/apps/rustcord/src/voice_call.rs
index 951b1b5..903254a 100644
--- a/apps/rustcord/src/voice_call.rs
+++ b/apps/rustcord/src/voice_call.rs
@@ -890,7 +890,7 @@ impl RustCord {
}
let wait = REJOIN_BACKOFF[v.attempt];
v.attempt += 1;
- let streaming = self.go_live.is_some() || self.watching.is_some();
+ let streaming = self.go_live.is_some() || !self.watching.is_empty();
let Some(v) = self.voice.as_mut() else { return };
log::info!("voice: rejoin {} in {:?}: {why}", v.attempt, wait);
// Stop the old call; its late events belong to an old generation.