Merge pull request #15: Wayland screen share via the ScreenCast portal
@@ -61,7 +61,7 @@
61
61
**Calls**
62
62
- Test call to the Teams Echo bot from the avatar menu: native WebRTC audio, mute (`Ctrl+Shift+M`), device switching, mini window while you read other chats
63
63
- Phone button in 1:1 and group chat headers: callee tiles show Calling and Ringing, Cancel while ringing, notices like "Bea declined" or "No answer"
64
- Video and screen sharing: H264 tiles, shared screen on a stage (double click for full window, Esc back), camera and screen share buttons with a "You are sharing" banner. Linux needs glib at run time
64
- Video and screen sharing: H264 tiles, shared screen on a stage (double click for full window, Esc back), camera and screen share buttons with a "You are sharing" banner. Linux needs glib at run time. On Wayland, sharing opens the desktop ScreenCast portal dialog, including on KDE, GNOME and Hyprland
65
65
- Incoming calls: topmost ring toast with Decline and Accept, ring tone, missed calls in Activity
66
66
- Join a running meeting from its chat (audio): roster tiles, speaking ring, lobby state, Leave or End meeting for the organizer
67
67
- After every call a pseudonymized test report (JSON and Markdown, newest 30) is saved to the app data folder `call-reports`; toast "Test report saved" with Open folder, Settings > Devices switch
@@ -74,6 +74,11 @@
74
74
- One-click install for Claude Code, Codex CLI, Copilot CLI, VS Code and Cursor, Windows and WSL. WSL needs `networkingMode=mirrored`
75
75
- Delegate a message to a coding-agent CLI (Claude Code, Copilot, any CLI) from the hover toolbar: progress chip, Agents page, toast when it finishes, Open session
76
76
77
**Calendar (fork)**
78
- Outlook calendar as today, plus optional Google Calendar accounts (Settings > Calendar)
79
- Merge by iCal UID / Teams join URL; New meeting writes to the home calendar and optional extra targets
80
- Google OAuth Desktop (PKCE): set `TEAMS_GOOGLE_CLIENT_ID` and optionally `TEAMS_GOOGLE_CLIENT_SECRET` before Connect
81
77
82
**App**
78
83
- Dark theme, opens instantly from the cache
79
84
- Self-update from an update folder
@@ -84,8 +89,8 @@
84
89
| Platform | State |
85
90
|---|---|
86
91
| 🪟 Windows | Main target. Login through an embedded WebView2 |
87
| 🐧 Linux | Starts Google Chrome or Chromium on its own (debug port 9222, own profile in the XDG data folder) and keeps it headless in the background. When Teams asks for a login, the Chrome window shows itself and goes back to the background once you are signed in. `--endpoint` connects to a Chrome you started yourself instead. The app opens an Outlook on the web tab next to Teams when missing (some tenants grant chat scopes only to Outlook). Built-in login without Chrome is planned |
88
| 🍎 macOS | Experimental. Universal arm64 + x86_64 binary, connects to a Chrome like Linux |
92
| 🐧 Linux | Starts Google Chrome or Chromium on its own (debug port 9222, own profile in the XDG data folder) and keeps it headless in the background. When Teams asks for a login, the Chrome window shows itself and goes back to the background once you are signed in. `--endpoint` connects to a Chrome you started yourself instead. The app opens an Outlook on the web tab next to Teams when missing (some tenants grant chat scopes only to Outlook). Color emoji use a bundled bitmap Noto Color Emoji font; a system COLRv1 face of the same name is left out of the font list. The window id is `rusty-teams`. Copy `crates/app/assets/linux/rusty-teams.desktop` to `~/.local/share/applications/` and `crates/app/assets/icon/teams-fast-256.png` to `~/.local/share/icons/hicolor/256x256/apps/rusty-teams.png` so the dock can match it. Built-in login without Chrome is planned |
93
| 🍎 macOS | Starts Google Chrome or Chromium on its own (debug port 9222, own profile under Application Support) and keeps it headless in the background. When Teams asks for a login, the Chrome window shows itself and goes back to the background once you are signed in. `--endpoint` connects to a Chrome you started yourself instead. Universal arm64 + x86_64 `.app` bundle. Screen share uses the ScreenCaptureKit system dialog |
89
94
90
95
The remaining gaps are planned, see [ROADMAP.md](ROADMAP.md).
91
96
@@ -97,6 +102,21 @@ Try it with demo data, no account needed:
97
102
cargo run -p app -- --demo
98
103
```
99
104
105
### Google Calendar (optional)
106
107
1. Create an OAuth Desktop client in Google Cloud Console with redirect `http://127.0.0.1:<port>/` (loopback; the app picks a free port).
108
2. Export before starting the app:
109
110
```bash
111
export TEAMS_GOOGLE_CLIENT_ID="….apps.googleusercontent.com"
112
# only if the client has a secret:
113
export TEAMS_GOOGLE_CLIENT_SECRET="…"
114
```
115
116
3. Settings > Calendar > Connect Google, then choose home calendar and optional dual-write targets.
117
118
Without these env vars the calendar stays Outlook-only.
119
100
120
| Task | Command |
101
121
|---|---|
102
122
| Linux build needs clang 21+ (libwebrtc's hermetic libc++) + mold (set in `.cargo/config.toml`); sccache shares compiled deps across worktrees | `sudo apt install clang mold sccache`, clang from [apt.llvm.org](https://apt.llvm.org) if the distro one is older than 21 |
@@ -61,7 +61,7 @@61
**Calls**61
**Calls**62
- Test call to the Teams Echo bot from the avatar menu: native WebRTC audio, mute (`Ctrl+Shift+M`), device switching, mini window while you read other chats62
- Test call to the Teams Echo bot from the avatar menu: native WebRTC audio, mute (`Ctrl+Shift+M`), device switching, mini window while you read other chats63
- Phone button in 1:1 and group chat headers: callee tiles show Calling and Ringing, Cancel while ringing, notices like "Bea declined" or "No answer"63
- Phone button in 1:1 and group chat headers: callee tiles show Calling and Ringing, Cancel while ringing, notices like "Bea declined" or "No answer"64
- Video and screen sharing: H264 tiles, shared screen on a stage (double click for full window, Esc back), camera and screen share buttons with a "You are sharing" banner. Linux needs glib at run time64
- Video and screen sharing: H264 tiles, shared screen on a stage (double click for full window, Esc back), camera and screen share buttons with a "You are sharing" banner. Linux needs glib at run time. On Wayland, sharing opens the desktop ScreenCast portal dialog, including on KDE, GNOME and Hyprland65
- Incoming calls: topmost ring toast with Decline and Accept, ring tone, missed calls in Activity65
- Incoming calls: topmost ring toast with Decline and Accept, ring tone, missed calls in Activity66
- Join a running meeting from its chat (audio): roster tiles, speaking ring, lobby state, Leave or End meeting for the organizer66
- Join a running meeting from its chat (audio): roster tiles, speaking ring, lobby state, Leave or End meeting for the organizer67
- After every call a pseudonymized test report (JSON and Markdown, newest 30) is saved to the app data folder `call-reports`; toast "Test report saved" with Open folder, Settings > Devices switch67
- After every call a pseudonymized test report (JSON and Markdown, newest 30) is saved to the app data folder `call-reports`; toast "Test report saved" with Open folder, Settings > Devices switch@@ -74,6 +74,11 @@74
- One-click install for Claude Code, Codex CLI, Copilot CLI, VS Code and Cursor, Windows and WSL. WSL needs `networkingMode=mirrored`74
- One-click install for Claude Code, Codex CLI, Copilot CLI, VS Code and Cursor, Windows and WSL. WSL needs `networkingMode=mirrored`75
- Delegate a message to a coding-agent CLI (Claude Code, Copilot, any CLI) from the hover toolbar: progress chip, Agents page, toast when it finishes, Open session75
- Delegate a message to a coding-agent CLI (Claude Code, Copilot, any CLI) from the hover toolbar: progress chip, Agents page, toast when it finishes, Open session76
76
77
**Calendar (fork)**78
- Outlook calendar as today, plus optional Google Calendar accounts (Settings > Calendar)79
- Merge by iCal UID / Teams join URL; New meeting writes to the home calendar and optional extra targets80
- Google OAuth Desktop (PKCE): set `TEAMS_GOOGLE_CLIENT_ID` and optionally `TEAMS_GOOGLE_CLIENT_SECRET` before Connect81
77
**App**82
**App**78
- Dark theme, opens instantly from the cache83
- Dark theme, opens instantly from the cache79
- Self-update from an update folder84
- Self-update from an update folder@@ -84,8 +89,8 @@84
| Platform | State |89
| Platform | State |85
|---|---|90
|---|---|86
| 🪟 Windows | Main target. Login through an embedded WebView2 |91
| 🪟 Windows | Main target. Login through an embedded WebView2 |87
| 🐧 Linux | Starts Google Chrome or Chromium on its own (debug port 9222, own profile in the XDG data folder) and keeps it headless in the background. When Teams asks for a login, the Chrome window shows itself and goes back to the background once you are signed in. `--endpoint` connects to a Chrome you started yourself instead. The app opens an Outlook on the web tab next to Teams when missing (some tenants grant chat scopes only to Outlook). Built-in login without Chrome is planned |92
| 🐧 Linux | Starts Google Chrome or Chromium on its own (debug port 9222, own profile in the XDG data folder) and keeps it headless in the background. When Teams asks for a login, the Chrome window shows itself and goes back to the background once you are signed in. `--endpoint` connects to a Chrome you started yourself instead. The app opens an Outlook on the web tab next to Teams when missing (some tenants grant chat scopes only to Outlook). Color emoji use a bundled bitmap Noto Color Emoji font; a system COLRv1 face of the same name is left out of the font list. The window id is `rusty-teams`. Copy `crates/app/assets/linux/rusty-teams.desktop` to `~/.local/share/applications/` and `crates/app/assets/icon/teams-fast-256.png` to `~/.local/share/icons/hicolor/256x256/apps/rusty-teams.png` so the dock can match it. Built-in login without Chrome is planned |88
| 🍎 macOS | Experimental. Universal arm64 + x86_64 binary, connects to a Chrome like Linux |93
| 🍎 macOS | Starts Google Chrome or Chromium on its own (debug port 9222, own profile under Application Support) and keeps it headless in the background. When Teams asks for a login, the Chrome window shows itself and goes back to the background once you are signed in. `--endpoint` connects to a Chrome you started yourself instead. Universal arm64 + x86_64 `.app` bundle. Screen share uses the ScreenCaptureKit system dialog |89
94
90
The remaining gaps are planned, see [ROADMAP.md](ROADMAP.md).95
The remaining gaps are planned, see [ROADMAP.md](ROADMAP.md).91
96
@@ -97,6 +102,21 @@ Try it with demo data, no account needed:97
cargo run -p app -- --demo102
cargo run -p app -- --demo98
```103
```99
104
105
### Google Calendar (optional)106
107
1. Create an OAuth Desktop client in Google Cloud Console with redirect `http://127.0.0.1:<port>/` (loopback; the app picks a free port).108
2. Export before starting the app:109
110
```bash111
export TEAMS_GOOGLE_CLIENT_ID="….apps.googleusercontent.com"112
# only if the client has a secret:113
export TEAMS_GOOGLE_CLIENT_SECRET="…"114
```115
116
3. Settings > Calendar > Connect Google, then choose home calendar and optional dual-write targets.117
118
Without these env vars the calendar stays Outlook-only.119
100
| Task | Command |120
| Task | Command |101
|---|---|121
|---|---|102
| Linux build needs clang 21+ (libwebrtc's hermetic libc++) + mold (set in `.cargo/config.toml`); sccache shares compiled deps across worktrees | `sudo apt install clang mold sccache`, clang from [apt.llvm.org](https://apt.llvm.org) if the distro one is older than 21 |122
| Linux build needs clang 21+ (libwebrtc's hermetic libc++) + mold (set in `.cargo/config.toml`); sccache shares compiled deps across worktrees | `sudo apt install clang mold sccache`, clang from [apt.llvm.org](https://apt.llvm.org) if the distro one is older than 21 |@@ -441,13 +441,27 @@ impl CallWindows {
441
441
fn local_share(&self, cx: &App) -> Option<Option<ShareSource>> {
442
442
let model = &self.app.read(cx).call.as_ref()?.model;
443
443
let label = model.local_share.as_ref()?;
444
Some(
445
model
446
.share_sources
447
.iter()
448
.find(|source| &source.label() == label)
449
.cloned(),
450
)
444
if let Some(source) = model
445
.share_sources
446
.iter()
447
.find(|source| &source.label() == label)
448
.cloned()
449
{
450
return Some(Some(source));
451
}
452
Some(model.share_kind.map(|kind| ShareSource {
453
id: 0,
454
kind,
455
title: label.clone(),
456
}))
457
}
458
459
fn portal_picker(&self, cx: &App) -> bool {
460
self.app
461
.read(cx)
462
.call
463
.as_ref()
464
.is_some_and(|call| call.model.uses_portal_picker())
451
465
}
452
466
453
467
fn sync_share(&mut self, refresh_geometry: bool, cx: &mut Context<Self>) {
@@ -546,6 +560,7 @@ impl CallWindows {
546
560
self.local_share_mode(),
547
561
platform::window_rect(native),
548
562
shared,
563
self.portal_picker(cx),
549
564
) {
550
565
return;
551
566
}
@@ -441,13 +441,27 @@ impl CallWindows {441
fn local_share(&self, cx: &App) -> Option<Option<ShareSource>> {441
fn local_share(&self, cx: &App) -> Option<Option<ShareSource>> {442
let model = &self.app.read(cx).call.as_ref()?.model;442
let model = &self.app.read(cx).call.as_ref()?.model;443
let label = model.local_share.as_ref()?;443
let label = model.local_share.as_ref()?;444
Some(444
if let Some(source) = model445
model445
.share_sources446
.share_sources446
.iter()447
.iter()447
.find(|source| &source.label() == label)448
.find(|source| &source.label() == label)448
.cloned()449
.cloned(),449
{450
)450
return Some(Some(source));451
}452
Some(model.share_kind.map(|kind| ShareSource {453
id: 0,454
kind,455
title: label.clone(),456
}))457
}458
459
fn portal_picker(&self, cx: &App) -> bool {460
self.app461
.read(cx)462
.call463
.as_ref()464
.is_some_and(|call| call.model.uses_portal_picker())451
}465
}452
466
453
fn sync_share(&mut self, refresh_geometry: bool, cx: &mut Context<Self>) {467
fn sync_share(&mut self, refresh_geometry: bool, cx: &mut Context<Self>) {@@ -546,6 +560,7 @@ impl CallWindows {546
self.local_share_mode(),560
self.local_share_mode(),547
platform::window_rect(native),561
platform::window_rect(native),548
shared,562
shared,563
self.portal_picker(cx),549
) {564
) {550
return;565
return;551
}566
}@@ -1,7 +1,7 @@
1
1
use std::sync::Arc;
2
2
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
3
3
4
use calling::{DeviceEntry, MicSettings, NoiseSuppression, Reaction, VideoKey};
4
use calling::{DeviceEntry, MicSettings, NoiseSuppression, Reaction, ShareKind, VideoKey};
5
5
use gpui_kit::assets::IconName;
6
6
use gpui_kit::component::{
7
7
button::{Button, ButtonVariants as _},
@@ -661,14 +661,33 @@ fn share_items(
661
661
model: &CallModel,
662
662
options: ShareOptions,
663
663
) -> PopupMenu {
664
let screens = model.screens();
665
let single_screen = screens.len() == 1;
666
664
let mut popup = popup
667
665
.min_w(px(SHARE_MENU_WIDTH))
668
666
.item(sound_switch_item(app, options.sound))
669
667
.item(motion_switch_item(app, options.motion))
670
668
.item(standout_switch_item(app, options.standout, model.camera_on))
671
669
.separator();
670
if model.uses_portal_picker() {
671
let screen_app = app.clone();
672
let window_app = app.clone();
673
return popup
674
.item(
675
PopupMenuItem::new("Share entire screen").on_click(move |_, _, cx| {
676
screen_app.update(cx, |state, cx| {
677
state.start_portal_share(ShareKind::Screen, cx)
678
})
679
}),
680
)
681
.item(
682
PopupMenuItem::new("Share a window").on_click(move |_, _, cx| {
683
window_app.update(cx, |state, cx| {
684
state.start_portal_share(ShareKind::Window, cx)
685
})
686
}),
687
);
688
}
689
let screens = model.screens();
690
let single_screen = screens.len() == 1;
672
691
for (index, source) in screens.into_iter().enumerate() {
673
692
let label = if single_screen {
674
693
"Share entire screen".to_owned()
@@ -1,7 +1,7 @@1
use std::sync::Arc;1
use std::sync::Arc;2
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};2
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};3
3
4
use calling::{DeviceEntry, MicSettings, NoiseSuppression, Reaction, VideoKey};4
use calling::{DeviceEntry, MicSettings, NoiseSuppression, Reaction, ShareKind, VideoKey};5
use gpui_kit::assets::IconName;5
use gpui_kit::assets::IconName;6
use gpui_kit::component::{6
use gpui_kit::component::{7
button::{Button, ButtonVariants as _},7
button::{Button, ButtonVariants as _},@@ -661,14 +661,33 @@ fn share_items(661
model: &CallModel,661
model: &CallModel,662
options: ShareOptions,662
options: ShareOptions,663
) -> PopupMenu {663
) -> PopupMenu {664
let screens = model.screens();665
let single_screen = screens.len() == 1;666
let mut popup = popup664
let mut popup = popup667
.min_w(px(SHARE_MENU_WIDTH))665
.min_w(px(SHARE_MENU_WIDTH))668
.item(sound_switch_item(app, options.sound))666
.item(sound_switch_item(app, options.sound))669
.item(motion_switch_item(app, options.motion))667
.item(motion_switch_item(app, options.motion))670
.item(standout_switch_item(app, options.standout, model.camera_on))668
.item(standout_switch_item(app, options.standout, model.camera_on))671
.separator();669
.separator();670
if model.uses_portal_picker() {671
let screen_app = app.clone();672
let window_app = app.clone();673
return popup674
.item(675
PopupMenuItem::new("Share entire screen").on_click(move |_, _, cx| {676
screen_app.update(cx, |state, cx| {677
state.start_portal_share(ShareKind::Screen, cx)678
})679
}),680
)681
.item(682
PopupMenuItem::new("Share a window").on_click(move |_, _, cx| {683
window_app.update(cx, |state, cx| {684
state.start_portal_share(ShareKind::Window, cx)685
})686
}),687
);688
}689
let screens = model.screens();690
let single_screen = screens.len() == 1;672
for (index, source) in screens.into_iter().enumerate() {691
for (index, source) in screens.into_iter().enumerate() {673
let label = if single_screen {692
let label = if single_screen {674
"Share entire screen".to_owned()693
"Share entire screen".to_owned()@@ -20,7 +20,7 @@ use crate::organizer::{MeetingCapability, Modality};
20
20
use crate::reaction::Reaction;
21
21
use crate::recording::{RecordingKind, StopScope};
22
22
use crate::roster::{MeetingRole, RosterEntry};
23
use crate::screen::ShareSource;
23
use crate::screen::{ShareKind, SharePicker, ShareSource};
24
24
use crate::signaling::{Callee, MeetingTarget};
25
25
use crate::state::CallState;
26
26
use crate::transfer::Replacement;
@@ -35,10 +35,17 @@ pub enum CallCommand {
35
35
SelectInput(DeviceChoice),
36
36
SelectOutput(DeviceChoice),
37
37
SetMicSettings(MicSettings),
38
SetVideoQuality(crate::video_quality::VideoQuality),
38
39
RefreshDevices,
39
40
SetCamera(bool),
40
41
SelectCamera(DeviceChoice),
41
42
StartShare(ShareSource),
43
StartPortalShare(ShareKind),
44
FinishPortalShare {
45
source: ShareSource,
46
generation: u64,
47
},
48
AbandonPortalShare,
42
49
StopShare,
43
50
SetShareSound(bool),
44
51
SetShareMotion(bool),
@@ -155,6 +162,8 @@ pub enum CallUpdate {
155
162
Camera(bool),
156
163
Cameras(Vec<CameraDevice>),
157
164
LocalShare(Option<String>),
165
SharePicker(SharePicker),
166
ShareKind(Option<ShareKind>),
158
167
ShareSources(Vec<ShareSource>),
159
168
ShareThumbnail {
160
169
source: ShareSource,
@@ -207,6 +216,7 @@ pub struct CallHandle {
207
216
208
217
pub struct CallControl {
209
218
commands: UnboundedReceiver<CallCommand>,
219
command_sender: UnboundedSender<CallCommand>,
210
220
updates: UnboundedSender<CallUpdate>,
211
221
deferred: Vec<CallCommand>,
212
222
pub video: Arc<VideoHub>,
@@ -218,12 +228,13 @@ pub fn call_channel() -> (CallHandle, CallControl) {
218
228
let video = VideoHub::new(update_sender.clone());
219
229
(
220
230
CallHandle {
221
commands: command_sender,
231
commands: command_sender.clone(),
222
232
updates: update_receiver,
223
233
video: video.clone(),
224
234
},
225
235
CallControl {
226
236
commands: command_receiver,
237
command_sender,
227
238
updates: update_sender,
228
239
deferred: Vec::new(),
229
240
video,
@@ -240,6 +251,10 @@ impl CallControl {
240
251
self.updates.clone()
241
252
}
242
253
254
pub fn command_sender(&self) -> UnboundedSender<CallCommand> {
255
self.command_sender.clone()
256
}
257
243
258
pub fn defer(&mut self, command: CallCommand) {
244
259
self.deferred.push(command);
245
260
}
@@ -20,7 +20,7 @@ use crate::organizer::{MeetingCapability, Modality};20
use crate::reaction::Reaction;20
use crate::reaction::Reaction;21
use crate::recording::{RecordingKind, StopScope};21
use crate::recording::{RecordingKind, StopScope};22
use crate::roster::{MeetingRole, RosterEntry};22
use crate::roster::{MeetingRole, RosterEntry};23
use crate::screen::ShareSource;23
use crate::screen::{ShareKind, SharePicker, ShareSource};24
use crate::signaling::{Callee, MeetingTarget};24
use crate::signaling::{Callee, MeetingTarget};25
use crate::state::CallState;25
use crate::state::CallState;26
use crate::transfer::Replacement;26
use crate::transfer::Replacement;@@ -35,10 +35,17 @@ pub enum CallCommand {35
SelectInput(DeviceChoice),35
SelectInput(DeviceChoice),36
SelectOutput(DeviceChoice),36
SelectOutput(DeviceChoice),37
SetMicSettings(MicSettings),37
SetMicSettings(MicSettings),38
SetVideoQuality(crate::video_quality::VideoQuality),38
RefreshDevices,39
RefreshDevices,39
SetCamera(bool),40
SetCamera(bool),40
SelectCamera(DeviceChoice),41
SelectCamera(DeviceChoice),41
StartShare(ShareSource),42
StartShare(ShareSource),43
StartPortalShare(ShareKind),44
FinishPortalShare {45
source: ShareSource,46
generation: u64,47
},48
AbandonPortalShare,42
StopShare,49
StopShare,43
SetShareSound(bool),50
SetShareSound(bool),44
SetShareMotion(bool),51
SetShareMotion(bool),@@ -155,6 +162,8 @@ pub enum CallUpdate {155
Camera(bool),162
Camera(bool),156
Cameras(Vec<CameraDevice>),163
Cameras(Vec<CameraDevice>),157
LocalShare(Option<String>),164
LocalShare(Option<String>),165
SharePicker(SharePicker),166
ShareKind(Option<ShareKind>),158
ShareSources(Vec<ShareSource>),167
ShareSources(Vec<ShareSource>),159
ShareThumbnail {168
ShareThumbnail {160
source: ShareSource,169
source: ShareSource,@@ -207,6 +216,7 @@ pub struct CallHandle {207
216
208
pub struct CallControl {217
pub struct CallControl {209
commands: UnboundedReceiver<CallCommand>,218
commands: UnboundedReceiver<CallCommand>,219
command_sender: UnboundedSender<CallCommand>,210
updates: UnboundedSender<CallUpdate>,220
updates: UnboundedSender<CallUpdate>,211
deferred: Vec<CallCommand>,221
deferred: Vec<CallCommand>,212
pub video: Arc<VideoHub>,222
pub video: Arc<VideoHub>,@@ -218,12 +228,13 @@ pub fn call_channel() -> (CallHandle, CallControl) {218
let video = VideoHub::new(update_sender.clone());228
let video = VideoHub::new(update_sender.clone());219
(229
(220
CallHandle {230
CallHandle {221
commands: command_sender,231
commands: command_sender.clone(),222
updates: update_receiver,232
updates: update_receiver,223
video: video.clone(),233
video: video.clone(),224
},234
},225
CallControl {235
CallControl {226
commands: command_receiver,236
commands: command_receiver,237
command_sender,227
updates: update_sender,238
updates: update_sender,228
deferred: Vec::new(),239
deferred: Vec::new(),229
video,240
video,@@ -240,6 +251,10 @@ impl CallControl {240
self.updates.clone()251
self.updates.clone()241
}252
}242
253
254
pub fn command_sender(&self) -> UnboundedSender<CallCommand> {255
self.command_sender.clone()256
}257
243
pub fn defer(&mut self, command: CallCommand) {258
pub fn defer(&mut self, command: CallCommand) {244
self.deferred.push(command);259
self.deferred.push(command);245
}260
}@@ -36,6 +36,7 @@ pub mod matte;
36
36
#[cfg(windows)]
37
37
mod mic_windows;
38
38
pub mod motion;
39
pub mod notices;
39
40
#[cfg(windows)]
40
41
pub use loopback_windows::start_process_capture;
41
42
#[cfg(windows)]
@@ -74,6 +75,7 @@ pub mod trouter_events;
74
75
pub mod video_frame;
75
76
pub mod video_layout;
76
77
pub mod video_pattern;
78
pub mod video_quality;
77
79
pub mod video_receive;
78
80
pub mod video_send;
79
81
pub mod voice_high_pass;
@@ -84,7 +86,7 @@ pub use audio_io::AudioMode;
84
86
pub use background::{BackgroundCache, BackgroundChoice, BackgroundPicture, DefaultBackground};
85
87
pub use breakout::BreakoutMove;
86
88
pub use call::{AcceptMode, CallOptions, CallReport, CallSpec, run_test_call};
87
pub use camera::{CameraDevice, camera_entries};
89
pub use camera::{CameraCaptureStats, CameraDevice, camera_entries};
88
90
pub use captions::{CaptionEntry, CaptionState, SPOKEN_LANGUAGES};
89
91
pub use control::{CallCommand, CallControl, CallHandle, CallUpdate, Progress, call_channel};
90
92
pub use devices::{AudioDevice, DeviceChoice, DeviceEntry, DeviceLists};
@@ -106,12 +108,13 @@ pub use recording::{RecordingKind, StopScope};
106
108
pub use renegotiation::MediaPath;
107
109
pub use ring::{RING_TIMEOUT, RingEnd, RingSignal, RingState};
108
110
pub use roster::{AttendeeLimits, MeetingRole, PublishedState, RaisedHand, RosterEntry, Spotlight};
109
pub use screen::{ShareKind, ShareSource};
111
pub use screen::{ShareKind, SharePicker, ShareSource};
110
112
pub use signaling::{Callee, MeetingTarget};
111
113
pub use sound_capture::LoopbackKind;
112
114
pub use state::{CallSignal, CallState, EndReason};
113
115
pub use transfer::Replacement;
114
116
pub use video_frame::{VideoHub, VideoKey, VideoPicture};
115
117
pub use video_layout::{TileDetail, VideoWant};
118
pub use video_quality::VideoQuality;
116
119
pub use video_send::VideoMode;
117
120
pub use whiteboard::ContentShare;
@@ -36,6 +36,7 @@ pub mod matte;36
#[cfg(windows)]36
#[cfg(windows)]37
mod mic_windows;37
mod mic_windows;38
pub mod motion;38
pub mod motion;39
pub mod notices;39
#[cfg(windows)]40
#[cfg(windows)]40
pub use loopback_windows::start_process_capture;41
pub use loopback_windows::start_process_capture;41
#[cfg(windows)]42
#[cfg(windows)]@@ -74,6 +75,7 @@ pub mod trouter_events;74
pub mod video_frame;75
pub mod video_frame;75
pub mod video_layout;76
pub mod video_layout;76
pub mod video_pattern;77
pub mod video_pattern;78
pub mod video_quality;77
pub mod video_receive;79
pub mod video_receive;78
pub mod video_send;80
pub mod video_send;79
pub mod voice_high_pass;81
pub mod voice_high_pass;@@ -84,7 +86,7 @@ pub use audio_io::AudioMode;84
pub use background::{BackgroundCache, BackgroundChoice, BackgroundPicture, DefaultBackground};86
pub use background::{BackgroundCache, BackgroundChoice, BackgroundPicture, DefaultBackground};85
pub use breakout::BreakoutMove;87
pub use breakout::BreakoutMove;86
pub use call::{AcceptMode, CallOptions, CallReport, CallSpec, run_test_call};88
pub use call::{AcceptMode, CallOptions, CallReport, CallSpec, run_test_call};87
pub use camera::{CameraDevice, camera_entries};89
pub use camera::{CameraCaptureStats, CameraDevice, camera_entries};88
pub use captions::{CaptionEntry, CaptionState, SPOKEN_LANGUAGES};90
pub use captions::{CaptionEntry, CaptionState, SPOKEN_LANGUAGES};89
pub use control::{CallCommand, CallControl, CallHandle, CallUpdate, Progress, call_channel};91
pub use control::{CallCommand, CallControl, CallHandle, CallUpdate, Progress, call_channel};90
pub use devices::{AudioDevice, DeviceChoice, DeviceEntry, DeviceLists};92
pub use devices::{AudioDevice, DeviceChoice, DeviceEntry, DeviceLists};@@ -106,12 +108,13 @@ pub use recording::{RecordingKind, StopScope};106
pub use renegotiation::MediaPath;108
pub use renegotiation::MediaPath;107
pub use ring::{RING_TIMEOUT, RingEnd, RingSignal, RingState};109
pub use ring::{RING_TIMEOUT, RingEnd, RingSignal, RingState};108
pub use roster::{AttendeeLimits, MeetingRole, PublishedState, RaisedHand, RosterEntry, Spotlight};110
pub use roster::{AttendeeLimits, MeetingRole, PublishedState, RaisedHand, RosterEntry, Spotlight};109
pub use screen::{ShareKind, ShareSource};111
pub use screen::{ShareKind, SharePicker, ShareSource};110
pub use signaling::{Callee, MeetingTarget};112
pub use signaling::{Callee, MeetingTarget};111
pub use sound_capture::LoopbackKind;113
pub use sound_capture::LoopbackKind;112
pub use state::{CallSignal, CallState, EndReason};114
pub use state::{CallSignal, CallState, EndReason};113
pub use transfer::Replacement;115
pub use transfer::Replacement;114
pub use video_frame::{VideoHub, VideoKey, VideoPicture};116
pub use video_frame::{VideoHub, VideoKey, VideoPicture};115
pub use video_layout::{TileDetail, VideoWant};117
pub use video_layout::{TileDetail, VideoWant};118
pub use video_quality::VideoQuality;116
pub use video_send::VideoMode;119
pub use video_send::VideoMode;117
pub use whiteboard::ContentShare;120
pub use whiteboard::ContentShare;@@ -0,0 +1,110 @@
1
//! Call notice payloads: i18n keys (and optional detail after [`NOTICE_DETAIL_SEP`]).
2
pub const NOTICE_DETAIL_SEP: char = '\u{1f}';
3
4
pub const CONSENT_FIRST_NOTICE: &str = "calls.notice.consent_first";
5
pub const ON_HOLD_NOTICE: &str = "calls.notice.on_hold";
6
pub const CHANGE_RUNNING_NOTICE: &str = "calls.notice.change_running";
7
pub const VIDEO_FAILED_NOTICE: &str = "calls.notice.video_failed";
8
pub const SHARE_QUEUED_NOTICE: &str = "calls.notice.share_queued";
9
pub const SHARE_REFUSED_NOTICE: &str = "calls.notice.share_refused";
10
pub const NOT_CONNECTED_FOR_VIDEO: &str = "calls.notice.video_starts_once_connected";
11
pub const PORTAL_UNAVAILABLE_NOTICE: &str = "calls.notice.portal_unavailable";
12
pub const CALL_TRANSFERRED_NOTICE: &str = "calls.notice.call_transferred";
13
pub const TRANSFER_FAILED_NOTICE: &str = "calls.notice.transfer_failed";
14
pub const RECORDING_JOIN_FAILED_NOTICE: &str = "calls.notice.recording_join_failed";
15
pub const CAPTIONS_JOIN_FAILED_NOTICE: &str = "calls.notice.captions_join_failed";
16
pub const CAPTION_LANGUAGE_FAILED_NOTICE: &str = "calls.notice.caption_language_failed";
17
pub const CAMERA_START_NOTICE: &str = "calls.notice.camera_start";
18
pub const CAMERA_RESTART_NOTICE: &str = "calls.notice.camera_restart";
19
pub const SHARING_START_NOTICE: &str = "calls.notice.sharing_start";
20
pub const RAISE_HAND_FAILED_NOTICE: &str = "calls.notice.raise_hand_failed";
21
pub const LOWER_HAND_FAILED_NOTICE: &str = "calls.notice.lower_hand_failed";
22
pub const LOWER_THAT_HAND_FAILED_NOTICE: &str = "calls.notice.lower_that_hand_failed";
23
pub const LOWER_ALL_HANDS_FAILED_NOTICE: &str = "calls.notice.lower_all_hands_failed";
24
pub const CONFIRM_RECORDING_FAILED_NOTICE: &str = "calls.notice.confirm_recording_failed";
25
pub const HOLD_FAILED_NOTICE: &str = "calls.notice.hold_failed";
26
pub const RESUME_FAILED_NOTICE: &str = "calls.notice.resume_failed";
27
pub const TRANSFER_NOT_ALLOWED_NOTICE: &str = "calls.notice.transfer_not_allowed";
28
pub const TRANSFER_CALL_FAILED_NOTICE: &str = "calls.notice.transfer_call_failed";
29
pub const TRANSFERRING_NOTICE: &str = "calls.notice.transferring";
30
pub const WHITEBOARDS_MEETINGS_ONLY_NOTICE: &str = "calls.notice.whiteboards_meetings_only";
31
pub const WHITEBOARD_OPEN_FAILED_NOTICE: &str = "calls.notice.whiteboard_open_failed";
32
pub const REACTION_FAILED_NOTICE: &str = "calls.notice.reaction_failed";
33
pub const RECORDING_NOT_STARTED_NOTICE: &str = "calls.notice.recording_not_started";
34
pub const RECORDING_START_FAILED_NOTICE: &str = "calls.notice.recording_start_failed";
35
pub const CAPTIONS_START_FAILED_NOTICE: &str = "calls.notice.captions_start_failed";
36
pub const HOLD_CHANGE_FAILED_NOTICE: &str = "calls.notice.hold_change_failed";
37
pub const RECORDING_STOP_FAILED_NOTICE: &str = "calls.notice.recording_stop_failed";
38
pub const BACKGROUND_IMAGE_FAILED_NOTICE: &str = "calls.notice.background_image_failed";
39
pub const CAMERA_STOPPED_NOTICE: &str = "calls.notice.camera_stopped";
40
pub const SCREEN_SHARE_STOPPED_NOTICE: &str = "calls.notice.screen_share_stopped";
41
pub const ADMIT_FAILED_NOTICE: &str = "calls.notice.admit_failed";
42
pub const ADMIT_ALL_FAILED_NOTICE: &str = "calls.notice.admit_all_failed";
43
pub const DENY_FAILED_NOTICE: &str = "calls.notice.deny_failed";
44
pub const REMOVE_PARTICIPANT_FAILED_NOTICE: &str = "calls.notice.remove_participant_failed";
45
pub const MUTE_PARTICIPANT_FAILED_NOTICE: &str = "calls.notice.mute_participant_failed";
46
pub const MUTE_ALL_FAILED_NOTICE: &str = "calls.notice.mute_all_failed";
47
pub const MEETING_LOCK_FAILED_NOTICE: &str = "calls.notice.meeting_lock_failed";
48
pub const CHANGE_ROLE_FAILED_NOTICE: &str = "calls.notice.change_role_failed";
49
pub const MIC_SETTING_FAILED_NOTICE: &str = "calls.notice.mic_setting_failed";
50
pub const CAMERA_SETTING_FAILED_NOTICE: &str = "calls.notice.camera_setting_failed";
51
pub const ATTENDEE_SETTINGS_FAILED_NOTICE: &str = "calls.notice.attendee_settings_failed";
52
pub const INVITE_PERSON_FAILED_NOTICE: &str = "calls.notice.invite_person_failed";
53
pub const SPOTLIGHT_FAILED_NOTICE: &str = "calls.notice.spotlight_failed";
54
pub const STOP_SPOTLIGHT_FAILED_NOTICE: &str = "calls.notice.stop_spotlight_failed";
55
56
pub fn notice_with_detail(key: &'static str, detail: impl std::fmt::Display) -> String {
57
format!("{key}{NOTICE_DETAIL_SEP}{detail}")
58
}
59
60
#[cfg(test)]
61
mod tests {
62
use super::*;
63
64
#[test]
65
fn notice_id_fixed_keys_match_catalog_paths() {
66
assert_eq!(CONSENT_FIRST_NOTICE, "calls.notice.consent_first");
67
assert_eq!(ON_HOLD_NOTICE, "calls.notice.on_hold");
68
assert_eq!(CHANGE_RUNNING_NOTICE, "calls.notice.change_running");
69
assert_eq!(VIDEO_FAILED_NOTICE, "calls.notice.video_failed");
70
assert_eq!(SHARE_QUEUED_NOTICE, "calls.notice.share_queued");
71
assert_eq!(SHARE_REFUSED_NOTICE, "calls.notice.share_refused");
72
assert_eq!(
73
NOT_CONNECTED_FOR_VIDEO,
74
"calls.notice.video_starts_once_connected"
75
);
76
assert_eq!(PORTAL_UNAVAILABLE_NOTICE, "calls.notice.portal_unavailable");
77
assert_eq!(CALL_TRANSFERRED_NOTICE, "calls.notice.call_transferred");
78
assert_eq!(TRANSFER_FAILED_NOTICE, "calls.notice.transfer_failed");
79
assert_eq!(
80
RECORDING_JOIN_FAILED_NOTICE,
81
"calls.notice.recording_join_failed"
82
);
83
assert_eq!(
84
CAPTIONS_JOIN_FAILED_NOTICE,
85
"calls.notice.captions_join_failed"
86
);
87
assert_eq!(
88
CAPTION_LANGUAGE_FAILED_NOTICE,
89
"calls.notice.caption_language_failed"
90
);
91
assert_eq!(CAMERA_START_NOTICE, "calls.notice.camera_start");
92
assert_eq!(CAMERA_RESTART_NOTICE, "calls.notice.camera_restart");
93
assert_eq!(SHARING_START_NOTICE, "calls.notice.sharing_start");
94
assert_eq!(RAISE_HAND_FAILED_NOTICE, "calls.notice.raise_hand_failed");
95
assert_eq!(TRANSFERRING_NOTICE, "calls.notice.transferring");
96
assert_eq!(ADMIT_FAILED_NOTICE, "calls.notice.admit_failed");
97
assert_eq!(
98
BACKGROUND_IMAGE_FAILED_NOTICE,
99
"calls.notice.background_image_failed"
100
);
101
}
102
103
#[test]
104
fn notice_id_camera_payload_uses_key_and_detail_sep() {
105
let payload = notice_with_detail(CAMERA_START_NOTICE, "device busy");
106
assert!(payload.starts_with("calls.notice.camera_start"));
107
assert!(payload.contains(NOTICE_DETAIL_SEP));
108
assert!(payload.ends_with("device busy"));
109
}
110
}
@@ -0,0 +1,110 @@1
//! Call notice payloads: i18n keys (and optional detail after [`NOTICE_DETAIL_SEP`]).2
pub const NOTICE_DETAIL_SEP: char = '\u{1f}';3
4
pub const CONSENT_FIRST_NOTICE: &str = "calls.notice.consent_first";5
pub const ON_HOLD_NOTICE: &str = "calls.notice.on_hold";6
pub const CHANGE_RUNNING_NOTICE: &str = "calls.notice.change_running";7
pub const VIDEO_FAILED_NOTICE: &str = "calls.notice.video_failed";8
pub const SHARE_QUEUED_NOTICE: &str = "calls.notice.share_queued";9
pub const SHARE_REFUSED_NOTICE: &str = "calls.notice.share_refused";10
pub const NOT_CONNECTED_FOR_VIDEO: &str = "calls.notice.video_starts_once_connected";11
pub const PORTAL_UNAVAILABLE_NOTICE: &str = "calls.notice.portal_unavailable";12
pub const CALL_TRANSFERRED_NOTICE: &str = "calls.notice.call_transferred";13
pub const TRANSFER_FAILED_NOTICE: &str = "calls.notice.transfer_failed";14
pub const RECORDING_JOIN_FAILED_NOTICE: &str = "calls.notice.recording_join_failed";15
pub const CAPTIONS_JOIN_FAILED_NOTICE: &str = "calls.notice.captions_join_failed";16
pub const CAPTION_LANGUAGE_FAILED_NOTICE: &str = "calls.notice.caption_language_failed";17
pub const CAMERA_START_NOTICE: &str = "calls.notice.camera_start";18
pub const CAMERA_RESTART_NOTICE: &str = "calls.notice.camera_restart";19
pub const SHARING_START_NOTICE: &str = "calls.notice.sharing_start";20
pub const RAISE_HAND_FAILED_NOTICE: &str = "calls.notice.raise_hand_failed";21
pub const LOWER_HAND_FAILED_NOTICE: &str = "calls.notice.lower_hand_failed";22
pub const LOWER_THAT_HAND_FAILED_NOTICE: &str = "calls.notice.lower_that_hand_failed";23
pub const LOWER_ALL_HANDS_FAILED_NOTICE: &str = "calls.notice.lower_all_hands_failed";24
pub const CONFIRM_RECORDING_FAILED_NOTICE: &str = "calls.notice.confirm_recording_failed";25
pub const HOLD_FAILED_NOTICE: &str = "calls.notice.hold_failed";26
pub const RESUME_FAILED_NOTICE: &str = "calls.notice.resume_failed";27
pub const TRANSFER_NOT_ALLOWED_NOTICE: &str = "calls.notice.transfer_not_allowed";28
pub const TRANSFER_CALL_FAILED_NOTICE: &str = "calls.notice.transfer_call_failed";29
pub const TRANSFERRING_NOTICE: &str = "calls.notice.transferring";30
pub const WHITEBOARDS_MEETINGS_ONLY_NOTICE: &str = "calls.notice.whiteboards_meetings_only";31
pub const WHITEBOARD_OPEN_FAILED_NOTICE: &str = "calls.notice.whiteboard_open_failed";32
pub const REACTION_FAILED_NOTICE: &str = "calls.notice.reaction_failed";33
pub const RECORDING_NOT_STARTED_NOTICE: &str = "calls.notice.recording_not_started";34
pub const RECORDING_START_FAILED_NOTICE: &str = "calls.notice.recording_start_failed";35
pub const CAPTIONS_START_FAILED_NOTICE: &str = "calls.notice.captions_start_failed";36
pub const HOLD_CHANGE_FAILED_NOTICE: &str = "calls.notice.hold_change_failed";37
pub const RECORDING_STOP_FAILED_NOTICE: &str = "calls.notice.recording_stop_failed";38
pub const BACKGROUND_IMAGE_FAILED_NOTICE: &str = "calls.notice.background_image_failed";39
pub const CAMERA_STOPPED_NOTICE: &str = "calls.notice.camera_stopped";40
pub const SCREEN_SHARE_STOPPED_NOTICE: &str = "calls.notice.screen_share_stopped";41
pub const ADMIT_FAILED_NOTICE: &str = "calls.notice.admit_failed";42
pub const ADMIT_ALL_FAILED_NOTICE: &str = "calls.notice.admit_all_failed";43
pub const DENY_FAILED_NOTICE: &str = "calls.notice.deny_failed";44
pub const REMOVE_PARTICIPANT_FAILED_NOTICE: &str = "calls.notice.remove_participant_failed";45
pub const MUTE_PARTICIPANT_FAILED_NOTICE: &str = "calls.notice.mute_participant_failed";46
pub const MUTE_ALL_FAILED_NOTICE: &str = "calls.notice.mute_all_failed";47
pub const MEETING_LOCK_FAILED_NOTICE: &str = "calls.notice.meeting_lock_failed";48
pub const CHANGE_ROLE_FAILED_NOTICE: &str = "calls.notice.change_role_failed";49
pub const MIC_SETTING_FAILED_NOTICE: &str = "calls.notice.mic_setting_failed";50
pub const CAMERA_SETTING_FAILED_NOTICE: &str = "calls.notice.camera_setting_failed";51
pub const ATTENDEE_SETTINGS_FAILED_NOTICE: &str = "calls.notice.attendee_settings_failed";52
pub const INVITE_PERSON_FAILED_NOTICE: &str = "calls.notice.invite_person_failed";53
pub const SPOTLIGHT_FAILED_NOTICE: &str = "calls.notice.spotlight_failed";54
pub const STOP_SPOTLIGHT_FAILED_NOTICE: &str = "calls.notice.stop_spotlight_failed";55
56
pub fn notice_with_detail(key: &'static str, detail: impl std::fmt::Display) -> String {57
format!("{key}{NOTICE_DETAIL_SEP}{detail}")58
}59
60
#[cfg(test)]61
mod tests {62
use super::*;63
64
#[test]65
fn notice_id_fixed_keys_match_catalog_paths() {66
assert_eq!(CONSENT_FIRST_NOTICE, "calls.notice.consent_first");67
assert_eq!(ON_HOLD_NOTICE, "calls.notice.on_hold");68
assert_eq!(CHANGE_RUNNING_NOTICE, "calls.notice.change_running");69
assert_eq!(VIDEO_FAILED_NOTICE, "calls.notice.video_failed");70
assert_eq!(SHARE_QUEUED_NOTICE, "calls.notice.share_queued");71
assert_eq!(SHARE_REFUSED_NOTICE, "calls.notice.share_refused");72
assert_eq!(73
NOT_CONNECTED_FOR_VIDEO,74
"calls.notice.video_starts_once_connected"75
);76
assert_eq!(PORTAL_UNAVAILABLE_NOTICE, "calls.notice.portal_unavailable");77
assert_eq!(CALL_TRANSFERRED_NOTICE, "calls.notice.call_transferred");78
assert_eq!(TRANSFER_FAILED_NOTICE, "calls.notice.transfer_failed");79
assert_eq!(80
RECORDING_JOIN_FAILED_NOTICE,81
"calls.notice.recording_join_failed"82
);83
assert_eq!(84
CAPTIONS_JOIN_FAILED_NOTICE,85
"calls.notice.captions_join_failed"86
);87
assert_eq!(88
CAPTION_LANGUAGE_FAILED_NOTICE,89
"calls.notice.caption_language_failed"90
);91
assert_eq!(CAMERA_START_NOTICE, "calls.notice.camera_start");92
assert_eq!(CAMERA_RESTART_NOTICE, "calls.notice.camera_restart");93
assert_eq!(SHARING_START_NOTICE, "calls.notice.sharing_start");94
assert_eq!(RAISE_HAND_FAILED_NOTICE, "calls.notice.raise_hand_failed");95
assert_eq!(TRANSFERRING_NOTICE, "calls.notice.transferring");96
assert_eq!(ADMIT_FAILED_NOTICE, "calls.notice.admit_failed");97
assert_eq!(98
BACKGROUND_IMAGE_FAILED_NOTICE,99
"calls.notice.background_image_failed"100
);101
}102
103
#[test]104
fn notice_id_camera_payload_uses_key_and_detail_sep() {105
let payload = notice_with_detail(CAMERA_START_NOTICE, "device busy");106
assert!(payload.starts_with("calls.notice.camera_start"));107
assert!(payload.contains(NOTICE_DETAIL_SEP));108
assert!(payload.ends_with("device busy"));109
}110
}@@ -1,9 +1,10 @@
1
use std::sync::atomic::{AtomicU32, Ordering};
1
use std::sync::atomic::{AtomicBool, AtomicU32, Ordering};
2
2
use std::sync::{Arc, Mutex};
3
3
use std::time::Duration;
4
4
5
5
use libwebrtc::desktop_capturer::{
6
6
CaptureSource, DesktopCaptureSourceType, DesktopCapturer, DesktopCapturerOptions,
7
PortalPickerEvent,
7
8
};
8
9
use libwebrtc::native::yuv_helper::argb_to_i420;
9
10
use libwebrtc::video_frame::I420Buffer;
@@ -199,6 +200,13 @@ pub fn start_screen_capture(
199
200
mut deliver: impl FnMut(I420Buffer) + Send + 'static,
200
201
failed: impl FnOnce(String) + Send + 'static,
201
202
) -> Result<Capture> {
203
if current_share_picker() == SharePicker::Portal {
204
return start_portal_capture(wanted.kind, fps, deliver, move |follow| {
205
if let PortalFollowUp::Notice(text) = follow {
206
failed(text.to_owned());
207
}
208
});
209
}
202
210
Capture::spawn_thread("screen-capture", move |stop| {
203
211
let Some(source) = sources_of(wanted.kind)
204
212
.into_iter()
@@ -226,6 +234,136 @@ pub fn start_screen_capture(
226
234
.map_err(|error| Error::Webrtc(format!("screen thread: {error}")))
227
235
}
228
236
237
/// Where the share menu gets its sources. Wayland and macOS use a system dialog.
238
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
239
pub enum SharePicker {
240
List,
241
Portal,
242
}
243
244
pub fn share_picker_for(wayland_display: Option<&str>) -> SharePicker {
245
share_picker_for_host(cfg!(target_os = "macos"), wayland_display)
246
}
247
248
pub fn share_picker_for_host(macos: bool, wayland_display: Option<&str>) -> SharePicker {
249
if macos {
250
return SharePicker::Portal;
251
}
252
match wayland_display {
253
Some(value) if !value.is_empty() => SharePicker::Portal,
254
_ => SharePicker::List,
255
}
256
}
257
258
pub fn current_share_picker() -> SharePicker {
259
share_picker_for(std::env::var("WAYLAND_DISPLAY").ok().as_deref())
260
}
261
262
/// Portal menus must not enumerate or thumbnail sources. That would open the dialog early.
263
pub fn share_sources_for_menu(picker: SharePicker, sources: Vec<ShareSource>) -> Vec<ShareSource> {
264
match picker {
265
SharePicker::Portal => Vec::new(),
266
SharePicker::List => sources,
267
}
268
}
269
270
pub use crate::notices::PORTAL_UNAVAILABLE_NOTICE;
271
272
#[derive(Debug, Clone, PartialEq, Eq)]
273
pub enum PortalFollowUp {
274
Share(ShareSource),
275
Quiet,
276
Notice(&'static str),
277
}
278
279
pub fn portal_follow_up(event: PortalPickerEvent, source: Option<ShareSource>) -> PortalFollowUp {
280
match event {
281
PortalPickerEvent::Selected => match source {
282
Some(source) => PortalFollowUp::Share(source),
283
None => PortalFollowUp::Notice(PORTAL_UNAVAILABLE_NOTICE),
284
},
285
PortalPickerEvent::Cancelled => PortalFollowUp::Quiet,
286
PortalPickerEvent::Failed => PortalFollowUp::Notice(PORTAL_UNAVAILABLE_NOTICE),
287
}
288
}
289
290
pub(crate) fn start_portal_capture(
291
kind: ShareKind,
292
fps: Arc<AtomicU32>,
293
mut deliver: impl FnMut(I420Buffer) + Send + 'static,
294
outcome: impl FnOnce(PortalFollowUp) + Send + 'static,
295
) -> Result<Capture> {
296
Capture::spawn_thread("portal-share", move |stop| {
297
libwebrtc::desktop_capturer::ensure_shared_glib_loop();
298
let Some(mut capturer) = capturer(kind) else {
299
outcome(PortalFollowUp::Notice(PORTAL_UNAVAILABLE_NOTICE));
300
return;
301
};
302
let selected = Arc::new(AtomicBool::new(false));
303
let gate = selected.clone();
304
capturer.start_capture(None, move |result| {
305
if !gate.load(Ordering::SeqCst) {
306
return;
307
}
308
let Ok(frame) = result else { return };
309
let (width, height) = (frame.width() as u32 & !1, frame.height() as u32 & !1);
310
if width >= 2 && height >= 2 {
311
deliver(i420_from_bgra(frame.data(), width, height, frame.stride()));
312
}
313
});
314
if !capturer.has_delegated_picker() {
315
outcome(PortalFollowUp::Notice(PORTAL_UNAVAILABLE_NOTICE));
316
return;
317
}
318
let (sender, receiver) = std::sync::mpsc::channel();
319
capturer.watch_picker(move |event| {
320
let _ = sender.send(event);
321
});
322
capturer.ensure_picker_visible();
323
let event = loop {
324
if stop.load(Ordering::SeqCst) {
325
return;
326
}
327
match receiver.recv_timeout(Duration::from_millis(40)) {
328
Ok(event) => break event,
329
Err(std::sync::mpsc::RecvTimeoutError::Timeout) => continue,
330
Err(std::sync::mpsc::RecvTimeoutError::Disconnected) => {
331
outcome(PortalFollowUp::Notice(PORTAL_UNAVAILABLE_NOTICE));
332
return;
333
}
334
}
335
};
336
if stop.load(Ordering::SeqCst) {
337
return;
338
}
339
// The portal already bound this stream. Looking the source up again, or
340
// selecting that id, is what used to tear the stream down and report
341
// "the shared source is gone".
342
let source = if event == PortalPickerEvent::Selected {
343
selected.store(true, Ordering::SeqCst);
344
Some(ShareSource {
345
id: 0,
346
kind,
347
title: String::new(),
348
})
349
} else {
350
None
351
};
352
let follow = portal_follow_up(event, source);
353
if !matches!(follow, PortalFollowUp::Share(_)) {
354
outcome(follow);
355
return;
356
}
357
capturer.capture_frame();
358
outcome(follow);
359
while !stop.load(Ordering::SeqCst) {
360
capturer.capture_frame();
361
std::thread::sleep(Duration::from_secs(1) / fps.load(Ordering::Relaxed).max(1));
362
}
363
})
364
.map_err(|error| Error::Webrtc(format!("portal thread: {error}")))
365
}
366
229
367
#[cfg(test)]
230
368
mod tests {
231
369
use super::*;
@@ -268,3 +406,123 @@ mod thumbnail_tests {
268
406
assert!(scaled_bgra(&bytes, width, height, 8, 4, 4).is_none());
269
407
}
270
408
}
409
410
#[cfg(test)]
411
mod portal_mode_tests {
412
use super::{
413
ShareKind, SharePicker, ShareSource, share_picker_for_host, share_sources_for_menu,
414
};
415
416
#[test]
417
fn portal_mode_follows_wayland_display_and_skips_the_menu_list() {
418
assert_eq!(share_picker_for_host(false, None), SharePicker::List);
419
assert_eq!(share_picker_for_host(false, Some("")), SharePicker::List);
420
assert_eq!(
421
share_picker_for_host(false, Some("wayland-1")),
422
SharePicker::Portal
423
);
424
assert_eq!(share_picker_for_host(true, None), SharePicker::Portal);
425
assert_eq!(share_picker_for_host(true, Some("")), SharePicker::Portal);
426
let sources = vec![ShareSource {
427
id: 1,
428
kind: ShareKind::Screen,
429
title: "Desk".into(),
430
}];
431
assert!(share_sources_for_menu(SharePicker::Portal, sources.clone()).is_empty());
432
assert_eq!(
433
share_sources_for_menu(SharePicker::List, sources.clone()),
434
sources
435
);
436
}
437
}
438
439
#[cfg(test)]
440
mod portal_share_tests {
441
use libwebrtc::desktop_capturer::PortalPickerEvent;
442
443
use super::{
444
PORTAL_UNAVAILABLE_NOTICE, PortalFollowUp, ShareKind, ShareSource, portal_follow_up,
445
};
446
447
#[test]
448
fn portal_share_cancel_is_quiet_and_failure_is_a_notice() {
449
let source = ShareSource {
450
id: 7,
451
kind: ShareKind::Screen,
452
title: "Desk".into(),
453
};
454
assert!(matches!(
455
portal_follow_up(PortalPickerEvent::Selected, Some(source.clone())),
456
PortalFollowUp::Share(chosen) if chosen == source
457
));
458
assert!(matches!(
459
portal_follow_up(PortalPickerEvent::Selected, None),
460
PortalFollowUp::Notice(PORTAL_UNAVAILABLE_NOTICE)
461
));
462
assert!(matches!(
463
portal_follow_up(PortalPickerEvent::Cancelled, Some(source.clone())),
464
PortalFollowUp::Quiet
465
));
466
assert!(matches!(
467
portal_follow_up(PortalPickerEvent::Failed, Some(source)),
468
PortalFollowUp::Notice(PORTAL_UNAVAILABLE_NOTICE)
469
));
470
}
471
}
472
473
#[cfg(all(test, target_os = "linux"))]
474
mod portal_loop_tests {
475
#[test]
476
fn portal_loop_stays_up_across_ensures() {
477
libwebrtc::desktop_capturer::ensure_shared_glib_loop();
478
let id = libwebrtc::desktop_capturer::shared_glib_loop_id();
479
assert_ne!(id, 0);
480
libwebrtc::desktop_capturer::ensure_shared_glib_loop();
481
assert_eq!(id, libwebrtc::desktop_capturer::shared_glib_loop_id());
482
}
483
}
484
485
#[cfg(all(test, target_os = "linux"))]
486
mod portal_smoke {
487
use std::sync::Arc;
488
use std::sync::atomic::{AtomicU32, Ordering};
489
use std::time::Duration;
490
491
use super::{PortalFollowUp, ShareKind, start_portal_capture};
492
493
#[test]
494
fn portal_smoke_captures_after_the_dialog() {
495
if std::env::var("PORTAL_SMOKE").ok().as_deref() != Some("1") {
496
return;
497
}
498
let frames = Arc::new(AtomicU32::new(0));
499
let counter = frames.clone();
500
let (sender, receiver) = std::sync::mpsc::channel();
501
let capture = start_portal_capture(
502
ShareKind::Screen,
503
Arc::new(AtomicU32::new(5)),
504
move |_| {
505
counter.fetch_add(1, Ordering::Relaxed);
506
},
507
move |follow| {
508
eprintln!("PORTAL_FOLLOW={follow:?}");
509
let _ = sender.send(follow);
510
},
511
)
512
.expect("portal thread");
513
let follow = receiver
514
.recv_timeout(Duration::from_secs(40))
515
.expect("no portal result in 40s");
516
std::thread::sleep(Duration::from_millis(700));
517
let count = frames.load(Ordering::Relaxed);
518
eprintln!("PORTAL_FRAMES={count}");
519
drop(capture);
520
match follow {
521
PortalFollowUp::Share(_) => {
522
assert!(count > 0, "the dialog confirmed, but no frame arrived")
523
}
524
PortalFollowUp::Quiet => panic!("the dialog was cancelled"),
525
PortalFollowUp::Notice(text) => panic!("portal notice: {text}"),
526
}
527
}
528
}
@@ -1,9 +1,10 @@1
use std::sync::atomic::{AtomicU32, Ordering};1
use std::sync::atomic::{AtomicBool, AtomicU32, Ordering};2
use std::sync::{Arc, Mutex};2
use std::sync::{Arc, Mutex};3
use std::time::Duration;3
use std::time::Duration;4
4
5
use libwebrtc::desktop_capturer::{5
use libwebrtc::desktop_capturer::{6
CaptureSource, DesktopCaptureSourceType, DesktopCapturer, DesktopCapturerOptions,6
CaptureSource, DesktopCaptureSourceType, DesktopCapturer, DesktopCapturerOptions,7
PortalPickerEvent,7
};8
};8
use libwebrtc::native::yuv_helper::argb_to_i420;9
use libwebrtc::native::yuv_helper::argb_to_i420;9
use libwebrtc::video_frame::I420Buffer;10
use libwebrtc::video_frame::I420Buffer;@@ -199,6 +200,13 @@ pub fn start_screen_capture(199
mut deliver: impl FnMut(I420Buffer) + Send + 'static,200
mut deliver: impl FnMut(I420Buffer) + Send + 'static,200
failed: impl FnOnce(String) + Send + 'static,201
failed: impl FnOnce(String) + Send + 'static,201
) -> Result<Capture> {202
) -> Result<Capture> {203
if current_share_picker() == SharePicker::Portal {204
return start_portal_capture(wanted.kind, fps, deliver, move |follow| {205
if let PortalFollowUp::Notice(text) = follow {206
failed(text.to_owned());207
}208
});209
}202
Capture::spawn_thread("screen-capture", move |stop| {210
Capture::spawn_thread("screen-capture", move |stop| {203
let Some(source) = sources_of(wanted.kind)211
let Some(source) = sources_of(wanted.kind)204
.into_iter()212
.into_iter()@@ -226,6 +234,136 @@ pub fn start_screen_capture(226
.map_err(|error| Error::Webrtc(format!("screen thread: {error}")))234
.map_err(|error| Error::Webrtc(format!("screen thread: {error}")))227
}235
}228
236
237
/// Where the share menu gets its sources. Wayland and macOS use a system dialog.238
#[derive(Debug, Clone, Copy, PartialEq, Eq)]239
pub enum SharePicker {240
List,241
Portal,242
}243
244
pub fn share_picker_for(wayland_display: Option<&str>) -> SharePicker {245
share_picker_for_host(cfg!(target_os = "macos"), wayland_display)246
}247
248
pub fn share_picker_for_host(macos: bool, wayland_display: Option<&str>) -> SharePicker {249
if macos {250
return SharePicker::Portal;251
}252
match wayland_display {253
Some(value) if !value.is_empty() => SharePicker::Portal,254
_ => SharePicker::List,255
}256
}257
258
pub fn current_share_picker() -> SharePicker {259
share_picker_for(std::env::var("WAYLAND_DISPLAY").ok().as_deref())260
}261
262
/// Portal menus must not enumerate or thumbnail sources. That would open the dialog early.263
pub fn share_sources_for_menu(picker: SharePicker, sources: Vec<ShareSource>) -> Vec<ShareSource> {264
match picker {265
SharePicker::Portal => Vec::new(),266
SharePicker::List => sources,267
}268
}269
270
pub use crate::notices::PORTAL_UNAVAILABLE_NOTICE;271
272
#[derive(Debug, Clone, PartialEq, Eq)]273
pub enum PortalFollowUp {274
Share(ShareSource),275
Quiet,276
Notice(&'static str),277
}278
279
pub fn portal_follow_up(event: PortalPickerEvent, source: Option<ShareSource>) -> PortalFollowUp {280
match event {281
PortalPickerEvent::Selected => match source {282
Some(source) => PortalFollowUp::Share(source),283
None => PortalFollowUp::Notice(PORTAL_UNAVAILABLE_NOTICE),284
},285
PortalPickerEvent::Cancelled => PortalFollowUp::Quiet,286
PortalPickerEvent::Failed => PortalFollowUp::Notice(PORTAL_UNAVAILABLE_NOTICE),287
}288
}289
290
pub(crate) fn start_portal_capture(291
kind: ShareKind,292
fps: Arc<AtomicU32>,293
mut deliver: impl FnMut(I420Buffer) + Send + 'static,294
outcome: impl FnOnce(PortalFollowUp) + Send + 'static,295
) -> Result<Capture> {296
Capture::spawn_thread("portal-share", move |stop| {297
libwebrtc::desktop_capturer::ensure_shared_glib_loop();298
let Some(mut capturer) = capturer(kind) else {299
outcome(PortalFollowUp::Notice(PORTAL_UNAVAILABLE_NOTICE));300
return;301
};302
let selected = Arc::new(AtomicBool::new(false));303
let gate = selected.clone();304
capturer.start_capture(None, move |result| {305
if !gate.load(Ordering::SeqCst) {306
return;307
}308
let Ok(frame) = result else { return };309
let (width, height) = (frame.width() as u32 & !1, frame.height() as u32 & !1);310
if width >= 2 && height >= 2 {311
deliver(i420_from_bgra(frame.data(), width, height, frame.stride()));312
}313
});314
if !capturer.has_delegated_picker() {315
outcome(PortalFollowUp::Notice(PORTAL_UNAVAILABLE_NOTICE));316
return;317
}318
let (sender, receiver) = std::sync::mpsc::channel();319
capturer.watch_picker(move |event| {320
let _ = sender.send(event);321
});322
capturer.ensure_picker_visible();323
let event = loop {324
if stop.load(Ordering::SeqCst) {325
return;326
}327
match receiver.recv_timeout(Duration::from_millis(40)) {328
Ok(event) => break event,329
Err(std::sync::mpsc::RecvTimeoutError::Timeout) => continue,330
Err(std::sync::mpsc::RecvTimeoutError::Disconnected) => {331
outcome(PortalFollowUp::Notice(PORTAL_UNAVAILABLE_NOTICE));332
return;333
}334
}335
};336
if stop.load(Ordering::SeqCst) {337
return;338
}339
// The portal already bound this stream. Looking the source up again, or340
// selecting that id, is what used to tear the stream down and report341
// "the shared source is gone".342
let source = if event == PortalPickerEvent::Selected {343
selected.store(true, Ordering::SeqCst);344
Some(ShareSource {345
id: 0,346
kind,347
title: String::new(),348
})349
} else {350
None351
};352
let follow = portal_follow_up(event, source);353
if !matches!(follow, PortalFollowUp::Share(_)) {354
outcome(follow);355
return;356
}357
capturer.capture_frame();358
outcome(follow);359
while !stop.load(Ordering::SeqCst) {360
capturer.capture_frame();361
std::thread::sleep(Duration::from_secs(1) / fps.load(Ordering::Relaxed).max(1));362
}363
})364
.map_err(|error| Error::Webrtc(format!("portal thread: {error}")))365
}366
229
#[cfg(test)]367
#[cfg(test)]230
mod tests {368
mod tests {231
use super::*;369
use super::*;@@ -268,3 +406,123 @@ mod thumbnail_tests {268
assert!(scaled_bgra(&bytes, width, height, 8, 4, 4).is_none());406
assert!(scaled_bgra(&bytes, width, height, 8, 4, 4).is_none());269
}407
}270
}408
}409
410
#[cfg(test)]411
mod portal_mode_tests {412
use super::{413
ShareKind, SharePicker, ShareSource, share_picker_for_host, share_sources_for_menu,414
};415
416
#[test]417
fn portal_mode_follows_wayland_display_and_skips_the_menu_list() {418
assert_eq!(share_picker_for_host(false, None), SharePicker::List);419
assert_eq!(share_picker_for_host(false, Some("")), SharePicker::List);420
assert_eq!(421
share_picker_for_host(false, Some("wayland-1")),422
SharePicker::Portal423
);424
assert_eq!(share_picker_for_host(true, None), SharePicker::Portal);425
assert_eq!(share_picker_for_host(true, Some("")), SharePicker::Portal);426
let sources = vec![ShareSource {427
id: 1,428
kind: ShareKind::Screen,429
title: "Desk".into(),430
}];431
assert!(share_sources_for_menu(SharePicker::Portal, sources.clone()).is_empty());432
assert_eq!(433
share_sources_for_menu(SharePicker::List, sources.clone()),434
sources435
);436
}437
}438
439
#[cfg(test)]440
mod portal_share_tests {441
use libwebrtc::desktop_capturer::PortalPickerEvent;442
443
use super::{444
PORTAL_UNAVAILABLE_NOTICE, PortalFollowUp, ShareKind, ShareSource, portal_follow_up,445
};446
447
#[test]448
fn portal_share_cancel_is_quiet_and_failure_is_a_notice() {449
let source = ShareSource {450
id: 7,451
kind: ShareKind::Screen,452
title: "Desk".into(),453
};454
assert!(matches!(455
portal_follow_up(PortalPickerEvent::Selected, Some(source.clone())),456
PortalFollowUp::Share(chosen) if chosen == source457
));458
assert!(matches!(459
portal_follow_up(PortalPickerEvent::Selected, None),460
PortalFollowUp::Notice(PORTAL_UNAVAILABLE_NOTICE)461
));462
assert!(matches!(463
portal_follow_up(PortalPickerEvent::Cancelled, Some(source.clone())),464
PortalFollowUp::Quiet465
));466
assert!(matches!(467
portal_follow_up(PortalPickerEvent::Failed, Some(source)),468
PortalFollowUp::Notice(PORTAL_UNAVAILABLE_NOTICE)469
));470
}471
}472
473
#[cfg(all(test, target_os = "linux"))]474
mod portal_loop_tests {475
#[test]476
fn portal_loop_stays_up_across_ensures() {477
libwebrtc::desktop_capturer::ensure_shared_glib_loop();478
let id = libwebrtc::desktop_capturer::shared_glib_loop_id();479
assert_ne!(id, 0);480
libwebrtc::desktop_capturer::ensure_shared_glib_loop();481
assert_eq!(id, libwebrtc::desktop_capturer::shared_glib_loop_id());482
}483
}484
485
#[cfg(all(test, target_os = "linux"))]486
mod portal_smoke {487
use std::sync::Arc;488
use std::sync::atomic::{AtomicU32, Ordering};489
use std::time::Duration;490
491
use super::{PortalFollowUp, ShareKind, start_portal_capture};492
493
#[test]494
fn portal_smoke_captures_after_the_dialog() {495
if std::env::var("PORTAL_SMOKE").ok().as_deref() != Some("1") {496
return;497
}498
let frames = Arc::new(AtomicU32::new(0));499
let counter = frames.clone();500
let (sender, receiver) = std::sync::mpsc::channel();501
let capture = start_portal_capture(502
ShareKind::Screen,503
Arc::new(AtomicU32::new(5)),504
move |_| {505
counter.fetch_add(1, Ordering::Relaxed);506
},507
move |follow| {508
eprintln!("PORTAL_FOLLOW={follow:?}");509
let _ = sender.send(follow);510
},511
)512
.expect("portal thread");513
let follow = receiver514
.recv_timeout(Duration::from_secs(40))515
.expect("no portal result in 40s");516
std::thread::sleep(Duration::from_millis(700));517
let count = frames.load(Ordering::Relaxed);518
eprintln!("PORTAL_FRAMES={count}");519
drop(capture);520
match follow {521
PortalFollowUp::Share(_) => {522
assert!(count > 0, "the dialog confirmed, but no frame arrived")523
}524
PortalFollowUp::Quiet => panic!("the dialog was cancelled"),525
PortalFollowUp::Notice(text) => panic!("portal notice: {text}"),526
}527
}528
}@@ -16,22 +16,27 @@ use tokio::sync::mpsc::UnboundedSender;
16
16
17
17
use crate::background::BackgroundPicture;
18
18
use crate::blur::BlurSettings;
19
use crate::camera::start_camera;
19
use crate::camera::{CameraCaptureStats, start_camera};
20
20
use crate::capture::Capture;
21
use crate::control::CallUpdate;
21
use crate::control::{CallCommand, CallUpdate};
22
22
use crate::devices::DeviceChoice;
23
23
use crate::effects::CameraEffects;
24
24
use crate::error::{Error, Result};
25
use crate::screen::{ShareSource, start_screen_capture};
25
use crate::notices::{CAMERA_STOPPED_NOTICE, SCREEN_SHARE_STOPPED_NOTICE, notice_with_detail};
26
use crate::screen::{
27
PortalFollowUp, ShareKind, ShareSource, start_portal_capture, start_screen_capture,
28
};
26
29
use crate::send_control::{
27
30
EncoderLimits, KEYFRAME_NUDGE, LayerPlan, SendLimit, encoder_limits, plan_layers,
28
31
};
29
32
use crate::standout::StandoutOverlay;
33
use crate::timeline::Timeline;
30
34
use crate::video_frame::{
31
35
FrameGate, PERSON_FPS, SCREEN_FPS, VideoHub, VideoKey, picture_from_i420,
32
36
};
33
37
use crate::video_layout::VideoLines;
34
38
use crate::video_pattern::{PatternKind, spawn_pattern};
39
use crate::video_quality::VideoQuality;
35
40
36
41
pub const VIDEO_MODE_ENV: &str = "CALLING_VIDEO";
37
42
const CAMERA_LABEL: &str = "camera";
@@ -198,6 +203,15 @@ pub struct LocalVideo {
198
203
motion: bool,
199
204
share_fps: Arc<AtomicU32>,
200
205
camera_preview: bool,
206
quality: VideoQuality,
207
camera_stats: Arc<CameraCaptureStats>,
208
timeline: Option<Timeline>,
209
portal_generation: u64,
210
portal_armed: bool,
211
portal_keep: bool,
212
/// The desktop dialog already bound the PipeWire stream. Later `StartShare`
213
/// commands must attach that capturer, not replace it.
214
portal_bound: bool,
201
215
}
202
216
203
217
impl LocalVideo {
@@ -218,9 +232,28 @@ impl LocalVideo {
218
232
motion: false,
219
233
share_fps: Arc::new(AtomicU32::new(SCREEN_SHARE_FPS)),
220
234
camera_preview: false,
235
quality: VideoQuality::default(),
236
camera_stats: CameraCaptureStats::new(),
237
timeline: None,
238
portal_generation: 0,
239
portal_armed: false,
240
portal_keep: false,
241
portal_bound: false,
221
242
}
222
243
}
223
244
245
pub fn attach_timeline(&mut self, timeline: Timeline) {
246
self.timeline = Some(timeline);
247
}
248
249
pub fn video_quality(&self) -> VideoQuality {
250
self.quality
251
}
252
253
pub fn set_video_quality(&mut self, quality: VideoQuality) {
254
self.quality = quality;
255
}
256
224
257
pub fn set_motion(&mut self, motion: bool) {
225
258
self.motion = motion;
226
259
self.share_fps.store(
@@ -468,6 +501,10 @@ impl LocalVideo {
468
501
self.screen.capture.is_some()
469
502
}
470
503
504
pub fn portal_is_open(&self) -> bool {
505
self.portal_armed
506
}
507
471
508
pub fn set_lines(&mut self, lines: VideoLines) -> Result<()> {
472
509
if self.camera_on() {
473
510
Self::begin_sending(&lines.camera.sender(), &self.camera.track)?;
@@ -507,10 +544,20 @@ impl LocalVideo {
507
544
.reporting_size(self.camera.frame_size.clone())
508
545
}
509
546
510
fn report_failure(&self, what: &'static str) -> impl FnOnce(String) + Send + 'static {
547
/// Local share frames go to the encoder and to the window in the chat.
548
fn screen_sink(&self) -> LocalSink {
549
LocalSink::new(
550
self.screen.source.clone(),
551
Some((self.hub.clone(), VideoKey::LocalScreen)),
552
)
553
.with_standout(self.blur.clone())
554
.reporting_size(self.screen.frame_size.clone())
555
}
556
557
fn report_failure(&self, notice_key: &'static str) -> impl FnOnce(String) + Send + 'static {
511
558
let updates = self.updates.clone();
512
559
move |reason| {
513
let _ = updates.send(CallUpdate::Notice(format!("{what} stopped: {reason}")));
560
let _ = updates.send(CallUpdate::Notice(notice_with_detail(notice_key, reason)));
514
561
}
515
562
}
516
563
@@ -542,6 +589,10 @@ impl LocalVideo {
542
589
Ok(())
543
590
}
544
591
592
pub fn camera_capture_summary(&self) -> Option<String> {
593
self.camera_stats.summary()
594
}
595
545
596
fn capture_camera(&self, choice: &DeviceChoice) -> Result<Capture> {
546
597
let mut sink = self.camera_sink();
547
598
Ok(match self.mode {
@@ -550,15 +601,44 @@ impl LocalVideo {
550
601
PatternKind::Camera,
551
602
Some(self.blur.clone()),
552
603
)),
553
_ => start_camera(
554
choice,
555
self.blur.clone(),
556
move |buffer| sink.push(buffer),
557
self.report_failure("Camera"),
558
)?,
604
_ => {
605
let timeline = self.timeline.clone();
606
start_camera(
607
choice,
608
self.quality,
609
self.blur.clone(),
610
self.camera_stats.clone(),
611
move |label| {
612
if let Some(timeline) = timeline {
613
timeline.record("camera capture", label);
614
} else {
615
eprintln!("calls: camera capture {label}");
616
}
617
},
618
move |buffer| sink.push(buffer),
619
self.report_failure(CAMERA_STOPPED_NOTICE),
620
)?
621
}
559
622
})
560
623
}
561
624
625
/// Restart capture with the current quality if the camera is already running.
626
pub fn refresh_camera_capture(&mut self, choice: &DeviceChoice) -> Result<()> {
627
if self.camera.capture.is_none() {
628
return Ok(());
629
}
630
let preview = self.camera_preview;
631
self.camera.capture = None;
632
self.camera.capture = Some(self.capture_camera(choice)?);
633
self.camera_preview = preview;
634
if !preview {
635
if let Some(lines) = self.lines.as_ref() {
636
Self::begin_sending(&lines.camera.sender(), &self.camera.track)?;
637
}
638
}
639
Ok(())
640
}
641
562
642
pub fn stop_camera(&mut self) {
563
643
self.camera_preview = false;
564
644
self.camera.capture = None;
@@ -569,6 +649,69 @@ impl LocalVideo {
569
649
self.hub.forget(&VideoKey::LocalCamera);
570
650
}
571
651
652
pub fn accept_portal(&mut self, generation: u64) -> bool {
653
if self.portal_armed && self.portal_generation == generation {
654
self.portal_armed = false;
655
self.portal_keep = true;
656
self.portal_bound = true;
657
true
658
} else {
659
false
660
}
661
}
662
663
pub fn open_portal(
664
&mut self,
665
kind: ShareKind,
666
commands: UnboundedSender<CallCommand>,
667
) -> Result<()> {
668
if !self.is_available() {
669
return Err(Error::Webrtc("video is switched off".into()));
670
}
671
if self.mode == VideoMode::Pattern {
672
let source = ShareSource {
673
id: if kind == ShareKind::Screen { 1 } else { 2 },
674
kind,
675
title: if kind == ShareKind::Screen {
676
"Test screen"
677
} else {
678
"Test window"
679
}
680
.into(),
681
};
682
let _ = commands.send(CallCommand::StartShare(source));
683
return Ok(());
684
}
685
self.portal_generation = self.portal_generation.wrapping_add(1);
686
let generation = self.portal_generation;
687
self.portal_armed = false;
688
self.portal_keep = false;
689
self.portal_bound = false;
690
self.screen.capture = None;
691
let mut sink = self.screen_sink();
692
let updates = self.updates.clone();
693
let capture = start_portal_capture(
694
kind,
695
self.share_fps.clone(),
696
move |buffer| sink.push(buffer),
697
move |follow| match follow {
698
PortalFollowUp::Share(source) => {
699
let _ = commands.send(CallCommand::FinishPortalShare { source, generation });
700
}
701
PortalFollowUp::Quiet => {
702
let _ = commands.send(CallCommand::AbandonPortalShare);
703
}
704
PortalFollowUp::Notice(text) => {
705
let _ = updates.send(CallUpdate::Notice(text.to_owned()));
706
let _ = commands.send(CallCommand::AbandonPortalShare);
707
}
708
},
709
)?;
710
self.portal_armed = true;
711
self.screen.capture = Some(capture);
712
Ok(())
713
}
714
572
715
pub fn start_share(&mut self, source: &ShareSource) -> Result<()> {
573
716
let lines = self
574
717
.lines
@@ -581,27 +724,35 @@ impl LocalVideo {
581
724
if !self.is_available() {
582
725
return Err(Error::Webrtc("video is switched off".into()));
583
726
}
584
self.screen.capture = None;
585
let mut sink = LocalSink::new(self.screen.source.clone(), None)
586
.with_standout(self.blur.clone())
587
.reporting_size(self.screen.frame_size.clone());
588
let capture = match self.mode {
589
VideoMode::Pattern => Capture::Task(spawn_pattern(sink, PatternKind::Screen, None)),
590
_ => start_screen_capture(
591
source.clone(),
592
self.share_fps.clone(),
593
move |buffer| sink.push(buffer),
594
self.report_failure("Screen share"),
595
)?,
596
};
727
let keep = std::mem::take(&mut self.portal_keep) || self.portal_bound;
728
if !keep {
729
self.portal_armed = false;
730
self.portal_generation = self.portal_generation.wrapping_add(1);
731
self.screen.capture = None;
732
let mut sink = self.screen_sink();
733
let capture = match self.mode {
734
VideoMode::Pattern => Capture::Task(spawn_pattern(sink, PatternKind::Screen, None)),
735
_ => start_screen_capture(
736
source.clone(),
737
self.share_fps.clone(),
738
move |buffer| sink.push(buffer),
739
self.report_failure(SCREEN_SHARE_STOPPED_NOTICE),
740
)?,
741
};
742
self.screen.capture = Some(capture);
743
}
597
744
Self::begin_sending(&share.sender(), &self.screen.track)?;
598
745
let _ = self.tune_share(&share.sender());
599
self.screen.capture = Some(capture);
600
746
Ok(())
601
747
}
602
748
603
749
pub fn stop_share(&mut self) {
750
self.portal_generation = self.portal_generation.wrapping_add(1);
751
self.portal_armed = false;
752
self.portal_keep = false;
753
self.portal_bound = false;
604
754
self.screen.capture = None;
755
self.hub.forget(&VideoKey::LocalScreen);
605
756
if let Some(share) = self.lines.as_ref().and_then(|lines| lines.share.as_ref()) {
606
757
let _ = Self::set_active(&share.sender(), false);
607
758
}
@@ -16,22 +16,27 @@ use tokio::sync::mpsc::UnboundedSender;16
16
17
use crate::background::BackgroundPicture;17
use crate::background::BackgroundPicture;18
use crate::blur::BlurSettings;18
use crate::blur::BlurSettings;19
use crate::camera::start_camera;19
use crate::camera::{CameraCaptureStats, start_camera};20
use crate::capture::Capture;20
use crate::capture::Capture;21
use crate::control::CallUpdate;21
use crate::control::{CallCommand, CallUpdate};22
use crate::devices::DeviceChoice;22
use crate::devices::DeviceChoice;23
use crate::effects::CameraEffects;23
use crate::effects::CameraEffects;24
use crate::error::{Error, Result};24
use crate::error::{Error, Result};25
use crate::screen::{ShareSource, start_screen_capture};25
use crate::notices::{CAMERA_STOPPED_NOTICE, SCREEN_SHARE_STOPPED_NOTICE, notice_with_detail};26
use crate::screen::{27
PortalFollowUp, ShareKind, ShareSource, start_portal_capture, start_screen_capture,28
};26
use crate::send_control::{29
use crate::send_control::{27
EncoderLimits, KEYFRAME_NUDGE, LayerPlan, SendLimit, encoder_limits, plan_layers,30
EncoderLimits, KEYFRAME_NUDGE, LayerPlan, SendLimit, encoder_limits, plan_layers,28
};31
};29
use crate::standout::StandoutOverlay;32
use crate::standout::StandoutOverlay;33
use crate::timeline::Timeline;30
use crate::video_frame::{34
use crate::video_frame::{31
FrameGate, PERSON_FPS, SCREEN_FPS, VideoHub, VideoKey, picture_from_i420,35
FrameGate, PERSON_FPS, SCREEN_FPS, VideoHub, VideoKey, picture_from_i420,32
};36
};33
use crate::video_layout::VideoLines;37
use crate::video_layout::VideoLines;34
use crate::video_pattern::{PatternKind, spawn_pattern};38
use crate::video_pattern::{PatternKind, spawn_pattern};39
use crate::video_quality::VideoQuality;35
40
36
pub const VIDEO_MODE_ENV: &str = "CALLING_VIDEO";41
pub const VIDEO_MODE_ENV: &str = "CALLING_VIDEO";37
const CAMERA_LABEL: &str = "camera";42
const CAMERA_LABEL: &str = "camera";@@ -198,6 +203,15 @@ pub struct LocalVideo {198
motion: bool,203
motion: bool,199
share_fps: Arc<AtomicU32>,204
share_fps: Arc<AtomicU32>,200
camera_preview: bool,205
camera_preview: bool,206
quality: VideoQuality,207
camera_stats: Arc<CameraCaptureStats>,208
timeline: Option<Timeline>,209
portal_generation: u64,210
portal_armed: bool,211
portal_keep: bool,212
/// The desktop dialog already bound the PipeWire stream. Later `StartShare`213
/// commands must attach that capturer, not replace it.214
portal_bound: bool,201
}215
}202
216
203
impl LocalVideo {217
impl LocalVideo {@@ -218,9 +232,28 @@ impl LocalVideo {218
motion: false,232
motion: false,219
share_fps: Arc::new(AtomicU32::new(SCREEN_SHARE_FPS)),233
share_fps: Arc::new(AtomicU32::new(SCREEN_SHARE_FPS)),220
camera_preview: false,234
camera_preview: false,235
quality: VideoQuality::default(),236
camera_stats: CameraCaptureStats::new(),237
timeline: None,238
portal_generation: 0,239
portal_armed: false,240
portal_keep: false,241
portal_bound: false,221
}242
}222
}243
}223
244
245
pub fn attach_timeline(&mut self, timeline: Timeline) {246
self.timeline = Some(timeline);247
}248
249
pub fn video_quality(&self) -> VideoQuality {250
self.quality251
}252
253
pub fn set_video_quality(&mut self, quality: VideoQuality) {254
self.quality = quality;255
}256
224
pub fn set_motion(&mut self, motion: bool) {257
pub fn set_motion(&mut self, motion: bool) {225
self.motion = motion;258
self.motion = motion;226
self.share_fps.store(259
self.share_fps.store(@@ -468,6 +501,10 @@ impl LocalVideo {468
self.screen.capture.is_some()501
self.screen.capture.is_some()469
}502
}470
503
504
pub fn portal_is_open(&self) -> bool {505
self.portal_armed506
}507
471
pub fn set_lines(&mut self, lines: VideoLines) -> Result<()> {508
pub fn set_lines(&mut self, lines: VideoLines) -> Result<()> {472
if self.camera_on() {509
if self.camera_on() {473
Self::begin_sending(&lines.camera.sender(), &self.camera.track)?;510
Self::begin_sending(&lines.camera.sender(), &self.camera.track)?;@@ -507,10 +544,20 @@ impl LocalVideo {507
.reporting_size(self.camera.frame_size.clone())544
.reporting_size(self.camera.frame_size.clone())508
}545
}509
546
510
fn report_failure(&self, what: &'static str) -> impl FnOnce(String) + Send + 'static {547
/// Local share frames go to the encoder and to the window in the chat.548
fn screen_sink(&self) -> LocalSink {549
LocalSink::new(550
self.screen.source.clone(),551
Some((self.hub.clone(), VideoKey::LocalScreen)),552
)553
.with_standout(self.blur.clone())554
.reporting_size(self.screen.frame_size.clone())555
}556
557
fn report_failure(&self, notice_key: &'static str) -> impl FnOnce(String) + Send + 'static {511
let updates = self.updates.clone();558
let updates = self.updates.clone();512
move |reason| {559
move |reason| {513
let _ = updates.send(CallUpdate::Notice(format!("{what} stopped: {reason}")));560
let _ = updates.send(CallUpdate::Notice(notice_with_detail(notice_key, reason)));514
}561
}515
}562
}516
563
@@ -542,6 +589,10 @@ impl LocalVideo {542
Ok(())589
Ok(())543
}590
}544
591
592
pub fn camera_capture_summary(&self) -> Option<String> {593
self.camera_stats.summary()594
}595
545
fn capture_camera(&self, choice: &DeviceChoice) -> Result<Capture> {596
fn capture_camera(&self, choice: &DeviceChoice) -> Result<Capture> {546
let mut sink = self.camera_sink();597
let mut sink = self.camera_sink();547
Ok(match self.mode {598
Ok(match self.mode {@@ -550,15 +601,44 @@ impl LocalVideo {550
PatternKind::Camera,601
PatternKind::Camera,551
Some(self.blur.clone()),602
Some(self.blur.clone()),552
)),603
)),553
_ => start_camera(604
_ => {554
choice,605
let timeline = self.timeline.clone();555
self.blur.clone(),606
start_camera(556
move |buffer| sink.push(buffer),607
choice,557
self.report_failure("Camera"),608
self.quality,558
)?,609
self.blur.clone(),610
self.camera_stats.clone(),611
move |label| {612
if let Some(timeline) = timeline {613
timeline.record("camera capture", label);614
} else {615
eprintln!("calls: camera capture {label}");616
}617
},618
move |buffer| sink.push(buffer),619
self.report_failure(CAMERA_STOPPED_NOTICE),620
)?621
}559
})622
})560
}623
}561
624
625
/// Restart capture with the current quality if the camera is already running.626
pub fn refresh_camera_capture(&mut self, choice: &DeviceChoice) -> Result<()> {627
if self.camera.capture.is_none() {628
return Ok(());629
}630
let preview = self.camera_preview;631
self.camera.capture = None;632
self.camera.capture = Some(self.capture_camera(choice)?);633
self.camera_preview = preview;634
if !preview {635
if let Some(lines) = self.lines.as_ref() {636
Self::begin_sending(&lines.camera.sender(), &self.camera.track)?;637
}638
}639
Ok(())640
}641
562
pub fn stop_camera(&mut self) {642
pub fn stop_camera(&mut self) {563
self.camera_preview = false;643
self.camera_preview = false;564
self.camera.capture = None;644
self.camera.capture = None;@@ -569,6 +649,69 @@ impl LocalVideo {569
self.hub.forget(&VideoKey::LocalCamera);649
self.hub.forget(&VideoKey::LocalCamera);570
}650
}571
651
652
pub fn accept_portal(&mut self, generation: u64) -> bool {653
if self.portal_armed && self.portal_generation == generation {654
self.portal_armed = false;655
self.portal_keep = true;656
self.portal_bound = true;657
true658
} else {659
false660
}661
}662
663
pub fn open_portal(664
&mut self,665
kind: ShareKind,666
commands: UnboundedSender<CallCommand>,667
) -> Result<()> {668
if !self.is_available() {669
return Err(Error::Webrtc("video is switched off".into()));670
}671
if self.mode == VideoMode::Pattern {672
let source = ShareSource {673
id: if kind == ShareKind::Screen { 1 } else { 2 },674
kind,675
title: if kind == ShareKind::Screen {676
"Test screen"677
} else {678
"Test window"679
}680
.into(),681
};682
let _ = commands.send(CallCommand::StartShare(source));683
return Ok(());684
}685
self.portal_generation = self.portal_generation.wrapping_add(1);686
let generation = self.portal_generation;687
self.portal_armed = false;688
self.portal_keep = false;689
self.portal_bound = false;690
self.screen.capture = None;691
let mut sink = self.screen_sink();692
let updates = self.updates.clone();693
let capture = start_portal_capture(694
kind,695
self.share_fps.clone(),696
move |buffer| sink.push(buffer),697
move |follow| match follow {698
PortalFollowUp::Share(source) => {699
let _ = commands.send(CallCommand::FinishPortalShare { source, generation });700
}701
PortalFollowUp::Quiet => {702
let _ = commands.send(CallCommand::AbandonPortalShare);703
}704
PortalFollowUp::Notice(text) => {705
let _ = updates.send(CallUpdate::Notice(text.to_owned()));706
let _ = commands.send(CallCommand::AbandonPortalShare);707
}708
},709
)?;710
self.portal_armed = true;711
self.screen.capture = Some(capture);712
Ok(())713
}714
572
pub fn start_share(&mut self, source: &ShareSource) -> Result<()> {715
pub fn start_share(&mut self, source: &ShareSource) -> Result<()> {573
let lines = self716
let lines = self574
.lines717
.lines@@ -581,27 +724,35 @@ impl LocalVideo {581
if !self.is_available() {724
if !self.is_available() {582
return Err(Error::Webrtc("video is switched off".into()));725
return Err(Error::Webrtc("video is switched off".into()));583
}726
}584
self.screen.capture = None;727
let keep = std::mem::take(&mut self.portal_keep) || self.portal_bound;585
let mut sink = LocalSink::new(self.screen.source.clone(), None)728
if !keep {586
.with_standout(self.blur.clone())729
self.portal_armed = false;587
.reporting_size(self.screen.frame_size.clone());730
self.portal_generation = self.portal_generation.wrapping_add(1);588
let capture = match self.mode {731
self.screen.capture = None;589
VideoMode::Pattern => Capture::Task(spawn_pattern(sink, PatternKind::Screen, None)),732
let mut sink = self.screen_sink();590
_ => start_screen_capture(733
let capture = match self.mode {591
source.clone(),734
VideoMode::Pattern => Capture::Task(spawn_pattern(sink, PatternKind::Screen, None)),592
self.share_fps.clone(),735
_ => start_screen_capture(593
move |buffer| sink.push(buffer),736
source.clone(),594
self.report_failure("Screen share"),737
self.share_fps.clone(),595
)?,738
move |buffer| sink.push(buffer),596
};739
self.report_failure(SCREEN_SHARE_STOPPED_NOTICE),740
)?,741
};742
self.screen.capture = Some(capture);743
}597
Self::begin_sending(&share.sender(), &self.screen.track)?;744
Self::begin_sending(&share.sender(), &self.screen.track)?;598
let _ = self.tune_share(&share.sender());745
let _ = self.tune_share(&share.sender());599
self.screen.capture = Some(capture);600
Ok(())746
Ok(())601
}747
}602
748
603
pub fn stop_share(&mut self) {749
pub fn stop_share(&mut self) {750
self.portal_generation = self.portal_generation.wrapping_add(1);751
self.portal_armed = false;752
self.portal_keep = false;753
self.portal_bound = false;604
self.screen.capture = None;754
self.screen.capture = None;755
self.hub.forget(&VideoKey::LocalScreen);605
if let Some(share) = self.lines.as_ref().and_then(|lines| lines.share.as_ref()) {756
if let Some(share) = self.lines.as_ref().and_then(|lines| lines.share.as_ref()) {606
let _ = Self::set_active(&share.sender(), false);757
let _ = Self::set_active(&share.sender(), false);607
}758
}@@ -14,6 +14,19 @@
14
14
15
15
use crate::imp::desktop_capturer as imp_dc;
16
16
17
/// Starts one GLib main loop for the process, on the default context.
18
///
19
/// Wayland's screen-cast portal needs this loop before a capturer starts or shows its picker.
20
/// Dropping a capturer does not stop the loop.
21
pub fn ensure_shared_glib_loop() {
22
imp_dc::ensure_shared_glib_loop();
23
}
24
25
/// Identity of the process-wide GLib loop. `0` when the loop is not built into this target.
26
pub fn shared_glib_loop_id() -> usize {
27
imp_dc::shared_glib_loop_id()
28
}
29
17
30
/// Configuration options for creating a desktop capturer.
18
31
///
19
32
/// It contains a subset of libwebrtc's DesktopCaptureOptions.
@@ -148,6 +161,42 @@ impl DesktopCapturer {
148
161
let source_list = self.handle.get_source_list();
149
162
source_list.into_iter().map(|source| CaptureSource { sys_handle: source }).collect()
150
163
}
164
165
/// Selects one source after a delegated picker has already chosen it.
166
pub fn select_source(&self, id: u64) -> bool {
167
self.handle.select_source(id)
168
}
169
170
/// Whether this capturer shows its own source picker (Wayland portal, macOS system picker).
171
pub fn has_delegated_picker(&self) -> bool {
172
self.handle.has_delegated_picker()
173
}
174
175
/// Receives selection, cancel, and failure from the delegated picker.
176
///
177
/// Call this after [`start_capture`](Self::start_capture) and before [`ensure_picker_visible`](Self::ensure_picker_visible).
178
pub fn watch_picker<T>(&mut self, mut callback: T)
179
where
180
T: FnMut(PortalPickerEvent) + Send + 'static,
181
{
182
self.handle.observe_picker(move |event| {
183
callback(match event {
184
imp_dc::PickerEvent::Selected => PortalPickerEvent::Selected,
185
imp_dc::PickerEvent::Cancelled => PortalPickerEvent::Cancelled,
186
imp_dc::PickerEvent::Failed => PortalPickerEvent::Failed,
187
});
188
});
189
}
190
191
/// Shows the delegated picker. No-op when [`has_delegated_picker`](Self::has_delegated_picker) is false.
192
pub fn ensure_picker_visible(&mut self) {
193
self.handle.ensure_picker_visible();
194
}
195
196
/// Hides the delegated picker. No-op when there is none.
197
pub fn ensure_picker_hidden(&mut self) {
198
self.handle.ensure_picker_hidden();
199
}
151
200
}
152
201
153
202
pub struct DesktopFrame {
@@ -217,6 +266,14 @@ pub enum CaptureError {
217
266
Permanent,
218
267
}
219
268
269
/// Outcome of a desktop-owned source picker.
270
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
271
pub enum PortalPickerEvent {
272
Selected,
273
Cancelled,
274
Failed,
275
}
276
220
277
fn capture_result_from_sys(
221
278
result: Result<imp_dc::DesktopFrame, imp_dc::CaptureError>,
222
279
) -> Result<DesktopFrame, CaptureError> {
@@ -14,6 +14,19 @@14
14
15
use crate::imp::desktop_capturer as imp_dc;15
use crate::imp::desktop_capturer as imp_dc;16
16
17
/// Starts one GLib main loop for the process, on the default context.18
///19
/// Wayland's screen-cast portal needs this loop before a capturer starts or shows its picker.20
/// Dropping a capturer does not stop the loop.21
pub fn ensure_shared_glib_loop() {22
imp_dc::ensure_shared_glib_loop();23
}24
25
/// Identity of the process-wide GLib loop. `0` when the loop is not built into this target.26
pub fn shared_glib_loop_id() -> usize {27
imp_dc::shared_glib_loop_id()28
}29
17
/// Configuration options for creating a desktop capturer.30
/// Configuration options for creating a desktop capturer.18
///31
///19
/// It contains a subset of libwebrtc's DesktopCaptureOptions.32
/// It contains a subset of libwebrtc's DesktopCaptureOptions.@@ -148,6 +161,42 @@ impl DesktopCapturer {148
let source_list = self.handle.get_source_list();161
let source_list = self.handle.get_source_list();149
source_list.into_iter().map(|source| CaptureSource { sys_handle: source }).collect()162
source_list.into_iter().map(|source| CaptureSource { sys_handle: source }).collect()150
}163
}164
165
/// Selects one source after a delegated picker has already chosen it.166
pub fn select_source(&self, id: u64) -> bool {167
self.handle.select_source(id)168
}169
170
/// Whether this capturer shows its own source picker (Wayland portal, macOS system picker).171
pub fn has_delegated_picker(&self) -> bool {172
self.handle.has_delegated_picker()173
}174
175
/// Receives selection, cancel, and failure from the delegated picker.176
///177
/// Call this after [`start_capture`](Self::start_capture) and before [`ensure_picker_visible`](Self::ensure_picker_visible).178
pub fn watch_picker<T>(&mut self, mut callback: T)179
where180
T: FnMut(PortalPickerEvent) + Send + 'static,181
{182
self.handle.observe_picker(move |event| {183
callback(match event {184
imp_dc::PickerEvent::Selected => PortalPickerEvent::Selected,185
imp_dc::PickerEvent::Cancelled => PortalPickerEvent::Cancelled,186
imp_dc::PickerEvent::Failed => PortalPickerEvent::Failed,187
});188
});189
}190
191
/// Shows the delegated picker. No-op when [`has_delegated_picker`](Self::has_delegated_picker) is false.192
pub fn ensure_picker_visible(&mut self) {193
self.handle.ensure_picker_visible();194
}195
196
/// Hides the delegated picker. No-op when there is none.197
pub fn ensure_picker_hidden(&mut self) {198
self.handle.ensure_picker_hidden();199
}151
}200
}152
201
153
pub struct DesktopFrame {202
pub struct DesktopFrame {@@ -217,6 +266,14 @@ pub enum CaptureError {217
Permanent,266
Permanent,218
}267
}219
268
269
/// Outcome of a desktop-owned source picker.270
#[derive(Debug, Clone, Copy, PartialEq, Eq)]271
pub enum PortalPickerEvent {272
Selected,273
Cancelled,274
Failed,275
}276
220
fn capture_result_from_sys(277
fn capture_result_from_sys(221
result: Result<imp_dc::DesktopFrame, imp_dc::CaptureError>,278
result: Result<imp_dc::DesktopFrame, imp_dc::CaptureError>,222
) -> Result<DesktopFrame, CaptureError> {279
) -> Result<DesktopFrame, CaptureError> {@@ -15,6 +15,8 @@
15
15
use cxx::UniquePtr;
16
16
use webrtc_sys::desktop_capturer::{self as sys_dc, ffi::new_desktop_capturer};
17
17
18
pub(crate) use sys_dc::PickerEvent;
19
18
20
#[derive(Debug, Copy, Clone, PartialEq)]
19
21
pub(crate) enum SourceType {
20
22
Screen,
@@ -84,10 +86,48 @@ impl DesktopCapturerOptions {
84
86
}
85
87
}
86
88
89
#[cfg(all(any(target_os = "linux", target_os = "freebsd"), feature = "glib-main-loop"))]
90
mod shared_glib {
91
use std::sync::OnceLock;
92
93
static LOOP: OnceLock<glib::MainLoop> = OnceLock::new();
94
95
pub(super) fn ensure() {
96
LOOP.get_or_init(|| {
97
let main_loop = glib::MainLoop::new(None, false);
98
let running = main_loop.clone();
99
std::thread::Builder::new()
100
.name("glib-portal".into())
101
.spawn(move || running.run())
102
.expect("glib portal loop");
103
main_loop
104
});
105
}
106
107
pub(super) fn id() -> usize {
108
ensure();
109
LOOP.get().map(|main_loop| main_loop as *const glib::MainLoop as usize).unwrap_or(0)
110
}
111
}
112
113
pub(crate) fn ensure_shared_glib_loop() {
114
#[cfg(all(any(target_os = "linux", target_os = "freebsd"), feature = "glib-main-loop"))]
115
shared_glib::ensure();
116
}
117
118
pub(crate) fn shared_glib_loop_id() -> usize {
119
#[cfg(all(any(target_os = "linux", target_os = "freebsd"), feature = "glib-main-loop"))]
120
{
121
return shared_glib::id();
122
}
123
#[cfg(not(all(any(target_os = "linux", target_os = "freebsd"), feature = "glib-main-loop")))]
124
{
125
0
126
}
127
}
128
87
129
pub(crate) struct DesktopCapturer {
88
130
sys_handle: UniquePtr<sys_dc::ffi::DesktopCapturer>,
89
#[cfg(all(any(target_os = "linux", target_os = "freebsd"), feature = "glib-main-loop"))]
90
glib_loop: Option<glib::MainLoop>,
91
131
}
92
132
93
133
impl DesktopCapturer {
@@ -96,14 +136,7 @@ impl DesktopCapturer {
96
136
if sys_handle.is_null() {
97
137
None
98
138
} else {
99
Some(Self {
100
sys_handle,
101
#[cfg(all(
102
any(target_os = "linux", target_os = "freebsd"),
103
feature = "glib-main-loop"
104
))]
105
glib_loop: None,
106
})
139
Some(Self { sys_handle })
107
140
}
108
141
}
109
142
@@ -117,11 +150,7 @@ impl DesktopCapturer {
117
150
{
118
151
#[cfg(all(any(target_os = "linux", target_os = "freebsd"), feature = "glib-main-loop"))]
119
152
if std::env::var("WAYLAND_DISPLAY").is_ok() {
120
let main_loop = glib::MainLoop::new(None, false);
121
self.glib_loop = Some(main_loop.clone());
122
let _handle = std::thread::spawn(move || {
123
main_loop.run();
124
});
153
ensure_shared_glib_loop();
125
154
}
126
155
let pin_handle = self.sys_handle.pin_mut();
127
156
let callback = DesktopCallback::new(callback);
@@ -141,14 +170,26 @@ impl DesktopCapturer {
141
170
}
142
171
sources
143
172
}
144
}
145
173
146
#[cfg(all(any(target_os = "linux", target_os = "freebsd"), feature = "glib-main-loop"))]
147
impl Drop for DesktopCapturer {
148
fn drop(&mut self) {
149
if let Some(glib_loop) = &self.glib_loop {
150
glib_loop.quit();
174
pub(crate) fn has_delegated_picker(&self) -> bool {
175
self.sys_handle.has_delegated_picker()
176
}
177
178
pub(crate) fn observe_picker(&mut self, callback: impl FnMut(sys_dc::PickerEvent) + Send + 'static) {
179
let wrapper = sys_dc::PortalPickerCallbackWrapper::new(Box::new(callback));
180
self.sys_handle.pin_mut().observe_picker(Box::new(wrapper));
181
}
182
183
pub(crate) fn ensure_picker_visible(&mut self) {
184
#[cfg(all(any(target_os = "linux", target_os = "freebsd"), feature = "glib-main-loop"))]
185
if std::env::var("WAYLAND_DISPLAY").is_ok() {
186
ensure_shared_glib_loop();
151
187
}
188
self.sys_handle.pin_mut().ensure_picker_visible();
189
}
190
191
pub(crate) fn ensure_picker_hidden(&mut self) {
192
self.sys_handle.pin_mut().ensure_picker_hidden();
152
193
}
153
194
}
154
195
@@ -15,6 +15,8 @@15
use cxx::UniquePtr;15
use cxx::UniquePtr;16
use webrtc_sys::desktop_capturer::{self as sys_dc, ffi::new_desktop_capturer};16
use webrtc_sys::desktop_capturer::{self as sys_dc, ffi::new_desktop_capturer};17
17
18
pub(crate) use sys_dc::PickerEvent;19
18
#[derive(Debug, Copy, Clone, PartialEq)]20
#[derive(Debug, Copy, Clone, PartialEq)]19
pub(crate) enum SourceType {21
pub(crate) enum SourceType {20
Screen,22
Screen,@@ -84,10 +86,48 @@ impl DesktopCapturerOptions {84
}86
}85
}87
}86
88
89
#[cfg(all(any(target_os = "linux", target_os = "freebsd"), feature = "glib-main-loop"))]90
mod shared_glib {91
use std::sync::OnceLock;92
93
static LOOP: OnceLock<glib::MainLoop> = OnceLock::new();94
95
pub(super) fn ensure() {96
LOOP.get_or_init(|| {97
let main_loop = glib::MainLoop::new(None, false);98
let running = main_loop.clone();99
std::thread::Builder::new()100
.name("glib-portal".into())101
.spawn(move || running.run())102
.expect("glib portal loop");103
main_loop104
});105
}106
107
pub(super) fn id() -> usize {108
ensure();109
LOOP.get().map(|main_loop| main_loop as *const glib::MainLoop as usize).unwrap_or(0)110
}111
}112
113
pub(crate) fn ensure_shared_glib_loop() {114
#[cfg(all(any(target_os = "linux", target_os = "freebsd"), feature = "glib-main-loop"))]115
shared_glib::ensure();116
}117
118
pub(crate) fn shared_glib_loop_id() -> usize {119
#[cfg(all(any(target_os = "linux", target_os = "freebsd"), feature = "glib-main-loop"))]120
{121
return shared_glib::id();122
}123
#[cfg(not(all(any(target_os = "linux", target_os = "freebsd"), feature = "glib-main-loop")))]124
{125
0126
}127
}128
87
pub(crate) struct DesktopCapturer {129
pub(crate) struct DesktopCapturer {88
sys_handle: UniquePtr<sys_dc::ffi::DesktopCapturer>,130
sys_handle: UniquePtr<sys_dc::ffi::DesktopCapturer>,89
#[cfg(all(any(target_os = "linux", target_os = "freebsd"), feature = "glib-main-loop"))]90
glib_loop: Option<glib::MainLoop>,91
}131
}92
132
93
impl DesktopCapturer {133
impl DesktopCapturer {@@ -96,14 +136,7 @@ impl DesktopCapturer {96
if sys_handle.is_null() {136
if sys_handle.is_null() {97
None137
None98
} else {138
} else {99
Some(Self {139
Some(Self { sys_handle })100
sys_handle,101
#[cfg(all(102
any(target_os = "linux", target_os = "freebsd"),103
feature = "glib-main-loop"104
))]105
glib_loop: None,106
})107
}140
}108
}141
}109
142
@@ -117,11 +150,7 @@ impl DesktopCapturer {117
{150
{118
#[cfg(all(any(target_os = "linux", target_os = "freebsd"), feature = "glib-main-loop"))]151
#[cfg(all(any(target_os = "linux", target_os = "freebsd"), feature = "glib-main-loop"))]119
if std::env::var("WAYLAND_DISPLAY").is_ok() {152
if std::env::var("WAYLAND_DISPLAY").is_ok() {120
let main_loop = glib::MainLoop::new(None, false);153
ensure_shared_glib_loop();121
self.glib_loop = Some(main_loop.clone());122
let _handle = std::thread::spawn(move || {123
main_loop.run();124
});125
}154
}126
let pin_handle = self.sys_handle.pin_mut();155
let pin_handle = self.sys_handle.pin_mut();127
let callback = DesktopCallback::new(callback);156
let callback = DesktopCallback::new(callback);@@ -141,14 +170,26 @@ impl DesktopCapturer {141
}170
}142
sources171
sources143
}172
}144
}145
173
146
#[cfg(all(any(target_os = "linux", target_os = "freebsd"), feature = "glib-main-loop"))]174
pub(crate) fn has_delegated_picker(&self) -> bool {147
impl Drop for DesktopCapturer {175
self.sys_handle.has_delegated_picker()148
fn drop(&mut self) {176
}149
if let Some(glib_loop) = &self.glib_loop {177
150
glib_loop.quit();178
pub(crate) fn observe_picker(&mut self, callback: impl FnMut(sys_dc::PickerEvent) + Send + 'static) {179
let wrapper = sys_dc::PortalPickerCallbackWrapper::new(Box::new(callback));180
self.sys_handle.pin_mut().observe_picker(Box::new(wrapper));181
}182
183
pub(crate) fn ensure_picker_visible(&mut self) {184
#[cfg(all(any(target_os = "linux", target_os = "freebsd"), feature = "glib-main-loop"))]185
if std::env::var("WAYLAND_DISPLAY").is_ok() {186
ensure_shared_glib_loop();151
}187
}188
self.sys_handle.pin_mut().ensure_picker_visible();189
}190
191
pub(crate) fn ensure_picker_hidden(&mut self) {192
self.sys_handle.pin_mut().ensure_picker_hidden();152
}193
}153
}194
}154
195
@@ -24,6 +24,7 @@ namespace livekit_ffi {
24
24
class DesktopFrame;
25
25
class DesktopCapturer;
26
26
class DesktopCapturerOptions;
27
class PortalPickerCallbackWrapper;
27
28
class Source;
28
29
} // namespace livekit_ffi
29
30
@@ -31,22 +32,34 @@ class Source;
31
32
32
33
namespace livekit_ffi {
33
34
34
class DesktopCapturer : public webrtc::DesktopCapturer::Callback {
35
class DesktopCapturer : public webrtc::DesktopCapturer::Callback,
36
public webrtc::DelegatedSourceListController::Observer {
35
37
public:
36
38
explicit DesktopCapturer(std::unique_ptr<webrtc::DesktopCapturer> capturer)
37
39
: capturer(std::move(capturer)), callback(std::nullopt) {}
40
~DesktopCapturer() override;
38
41
39
42
void OnCaptureResult(webrtc::DesktopCapturer::Result result,
40
43
std::unique_ptr<webrtc::DesktopFrame> frame) final;
44
void OnSelection() override;
45
void OnCancelled() override;
46
void OnError() override;
41
47
42
48
rust::Vec<Source> get_source_list() const;
43
49
bool select_source(uint64_t id) const { return capturer->SelectSource(id); }
44
50
void start(rust::Box<DesktopCapturerCallbackWrapper> callback);
45
51
void capture_frame() const { capturer->CaptureFrame(); }
52
bool has_delegated_picker() const;
53
void observe_picker(rust::Box<PortalPickerCallbackWrapper> callback);
54
void ensure_picker_visible();
55
void ensure_picker_hidden();
46
56
47
57
private:
58
webrtc::DelegatedSourceListController* picker_controller() const;
59
48
60
std::unique_ptr<webrtc::DesktopCapturer> capturer;
49
61
std::optional<rust::Box<DesktopCapturerCallbackWrapper>> callback;
62
std::optional<rust::Box<PortalPickerCallbackWrapper>> picker;
50
63
};
51
64
52
65
class DesktopFrame {
@@ -24,6 +24,7 @@ namespace livekit_ffi {24
class DesktopFrame;24
class DesktopFrame;25
class DesktopCapturer;25
class DesktopCapturer;26
class DesktopCapturerOptions;26
class DesktopCapturerOptions;27
class PortalPickerCallbackWrapper;27
class Source;28
class Source;28
} // namespace livekit_ffi29
} // namespace livekit_ffi29
30
@@ -31,22 +32,34 @@ class Source;31
32
32
namespace livekit_ffi {33
namespace livekit_ffi {33
34
34
class DesktopCapturer : public webrtc::DesktopCapturer::Callback {35
class DesktopCapturer : public webrtc::DesktopCapturer::Callback,36
public webrtc::DelegatedSourceListController::Observer {35
public:37
public:36
explicit DesktopCapturer(std::unique_ptr<webrtc::DesktopCapturer> capturer)38
explicit DesktopCapturer(std::unique_ptr<webrtc::DesktopCapturer> capturer)37
: capturer(std::move(capturer)), callback(std::nullopt) {}39
: capturer(std::move(capturer)), callback(std::nullopt) {}40
~DesktopCapturer() override;38
41
39
void OnCaptureResult(webrtc::DesktopCapturer::Result result,42
void OnCaptureResult(webrtc::DesktopCapturer::Result result,40
std::unique_ptr<webrtc::DesktopFrame> frame) final;43
std::unique_ptr<webrtc::DesktopFrame> frame) final;44
void OnSelection() override;45
void OnCancelled() override;46
void OnError() override;41
47
42
rust::Vec<Source> get_source_list() const;48
rust::Vec<Source> get_source_list() const;43
bool select_source(uint64_t id) const { return capturer->SelectSource(id); }49
bool select_source(uint64_t id) const { return capturer->SelectSource(id); }44
void start(rust::Box<DesktopCapturerCallbackWrapper> callback);50
void start(rust::Box<DesktopCapturerCallbackWrapper> callback);45
void capture_frame() const { capturer->CaptureFrame(); }51
void capture_frame() const { capturer->CaptureFrame(); }52
bool has_delegated_picker() const;53
void observe_picker(rust::Box<PortalPickerCallbackWrapper> callback);54
void ensure_picker_visible();55
void ensure_picker_hidden();46
56
47
private:57
private:58
webrtc::DelegatedSourceListController* picker_controller() const;59
48
std::unique_ptr<webrtc::DesktopCapturer> capturer;60
std::unique_ptr<webrtc::DesktopCapturer> capturer;49
std::optional<rust::Box<DesktopCapturerCallbackWrapper>> callback;61
std::optional<rust::Box<DesktopCapturerCallbackWrapper>> callback;62
std::optional<rust::Box<PortalPickerCallbackWrapper>> picker;50
};63
};51
64
52
class DesktopFrame {65
class DesktopFrame {@@ -74,6 +74,62 @@ std::unique_ptr<DesktopCapturer> new_desktop_capturer(
74
74
return std::make_unique<DesktopCapturer>(std::move(capturer));
75
75
}
76
76
77
DesktopCapturer::~DesktopCapturer() {
78
if (auto* controller = picker_controller()) {
79
controller->Observe(nullptr);
80
}
81
}
82
83
webrtc::DelegatedSourceListController* DesktopCapturer::picker_controller()
84
const {
85
if (!capturer) {
86
return nullptr;
87
}
88
return capturer->GetDelegatedSourceListController();
89
}
90
91
bool DesktopCapturer::has_delegated_picker() const {
92
return picker_controller() != nullptr;
93
}
94
95
void DesktopCapturer::observe_picker(
96
rust::Box<PortalPickerCallbackWrapper> callback) {
97
picker = std::move(callback);
98
if (auto* controller = picker_controller()) {
99
controller->Observe(this);
100
}
101
}
102
103
void DesktopCapturer::ensure_picker_visible() {
104
if (auto* controller = picker_controller()) {
105
controller->EnsureVisible();
106
}
107
}
108
109
void DesktopCapturer::ensure_picker_hidden() {
110
if (auto* controller = picker_controller()) {
111
controller->EnsureHidden();
112
}
113
}
114
115
void DesktopCapturer::OnSelection() {
116
if (picker) {
117
(*picker)->on_selection();
118
}
119
}
120
121
void DesktopCapturer::OnCancelled() {
122
if (picker) {
123
(*picker)->on_cancelled();
124
}
125
}
126
127
void DesktopCapturer::OnError() {
128
if (picker) {
129
(*picker)->on_error();
130
}
131
}
132
77
133
void DesktopCapturer::start(
78
134
rust::Box<DesktopCapturerCallbackWrapper> callback) {
79
135
this->callback = std::move(callback);
@@ -74,6 +74,62 @@ std::unique_ptr<DesktopCapturer> new_desktop_capturer(74
return std::make_unique<DesktopCapturer>(std::move(capturer));74
return std::make_unique<DesktopCapturer>(std::move(capturer));75
}75
}76
76
77
DesktopCapturer::~DesktopCapturer() {78
if (auto* controller = picker_controller()) {79
controller->Observe(nullptr);80
}81
}82
83
webrtc::DelegatedSourceListController* DesktopCapturer::picker_controller()84
const {85
if (!capturer) {86
return nullptr;87
}88
return capturer->GetDelegatedSourceListController();89
}90
91
bool DesktopCapturer::has_delegated_picker() const {92
return picker_controller() != nullptr;93
}94
95
void DesktopCapturer::observe_picker(96
rust::Box<PortalPickerCallbackWrapper> callback) {97
picker = std::move(callback);98
if (auto* controller = picker_controller()) {99
controller->Observe(this);100
}101
}102
103
void DesktopCapturer::ensure_picker_visible() {104
if (auto* controller = picker_controller()) {105
controller->EnsureVisible();106
}107
}108
109
void DesktopCapturer::ensure_picker_hidden() {110
if (auto* controller = picker_controller()) {111
controller->EnsureHidden();112
}113
}114
115
void DesktopCapturer::OnSelection() {116
if (picker) {117
(*picker)->on_selection();118
}119
}120
121
void DesktopCapturer::OnCancelled() {122
if (picker) {123
(*picker)->on_cancelled();124
}125
}126
127
void DesktopCapturer::OnError() {128
if (picker) {129
(*picker)->on_error();130
}131
}132
77
void DesktopCapturer::start(133
void DesktopCapturer::start(78
rust::Box<DesktopCapturerCallbackWrapper> callback) {134
rust::Box<DesktopCapturerCallbackWrapper> callback) {79
this->callback = std::move(callback);135
this->callback = std::move(callback);@@ -57,6 +57,13 @@ pub mod ffi {
57
57
fn get_source_list(self: &DesktopCapturer) -> Vec<Source>;
58
58
fn select_source(self: &DesktopCapturer, id: u64) -> bool;
59
59
fn start(self: Pin<&mut DesktopCapturer>, callback: Box<DesktopCapturerCallbackWrapper>);
60
fn has_delegated_picker(self: &DesktopCapturer) -> bool;
61
fn observe_picker(
62
self: Pin<&mut DesktopCapturer>,
63
callback: Box<PortalPickerCallbackWrapper>,
64
);
65
fn ensure_picker_visible(self: Pin<&mut DesktopCapturer>);
66
fn ensure_picker_hidden(self: Pin<&mut DesktopCapturer>);
60
67
61
68
fn width(self: &DesktopFrame) -> i32;
62
69
fn height(self: &DesktopFrame) -> i32;
@@ -74,6 +81,12 @@ pub mod ffi {
74
81
result: CaptureResult,
75
82
frame: UniquePtr<DesktopFrame>,
76
83
);
84
85
type PortalPickerCallbackWrapper;
86
87
fn on_selection(self: &mut PortalPickerCallbackWrapper);
88
fn on_cancelled(self: &mut PortalPickerCallbackWrapper);
89
fn on_error(self: &mut PortalPickerCallbackWrapper);
77
90
}
78
91
}
79
92
@@ -111,3 +124,32 @@ impl DesktopCapturerCallbackWrapper {
111
124
}
112
125
}
113
126
}
127
128
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
129
pub enum PickerEvent {
130
Selected,
131
Cancelled,
132
Failed,
133
}
134
135
pub struct PortalPickerCallbackWrapper {
136
callback: Box<dyn FnMut(PickerEvent) + Send>,
137
}
138
139
impl PortalPickerCallbackWrapper {
140
pub fn new(callback: Box<dyn FnMut(PickerEvent) + Send>) -> Self {
141
Self { callback }
142
}
143
144
fn on_selection(&mut self) {
145
(self.callback)(PickerEvent::Selected);
146
}
147
148
fn on_cancelled(&mut self) {
149
(self.callback)(PickerEvent::Cancelled);
150
}
151
152
fn on_error(&mut self) {
153
(self.callback)(PickerEvent::Failed);
154
}
155
}
@@ -57,6 +57,13 @@ pub mod ffi {57
fn get_source_list(self: &DesktopCapturer) -> Vec<Source>;57
fn get_source_list(self: &DesktopCapturer) -> Vec<Source>;58
fn select_source(self: &DesktopCapturer, id: u64) -> bool;58
fn select_source(self: &DesktopCapturer, id: u64) -> bool;59
fn start(self: Pin<&mut DesktopCapturer>, callback: Box<DesktopCapturerCallbackWrapper>);59
fn start(self: Pin<&mut DesktopCapturer>, callback: Box<DesktopCapturerCallbackWrapper>);60
fn has_delegated_picker(self: &DesktopCapturer) -> bool;61
fn observe_picker(62
self: Pin<&mut DesktopCapturer>,63
callback: Box<PortalPickerCallbackWrapper>,64
);65
fn ensure_picker_visible(self: Pin<&mut DesktopCapturer>);66
fn ensure_picker_hidden(self: Pin<&mut DesktopCapturer>);60
67
61
fn width(self: &DesktopFrame) -> i32;68
fn width(self: &DesktopFrame) -> i32;62
fn height(self: &DesktopFrame) -> i32;69
fn height(self: &DesktopFrame) -> i32;@@ -74,6 +81,12 @@ pub mod ffi {74
result: CaptureResult,81
result: CaptureResult,75
frame: UniquePtr<DesktopFrame>,82
frame: UniquePtr<DesktopFrame>,76
);83
);84
85
type PortalPickerCallbackWrapper;86
87
fn on_selection(self: &mut PortalPickerCallbackWrapper);88
fn on_cancelled(self: &mut PortalPickerCallbackWrapper);89
fn on_error(self: &mut PortalPickerCallbackWrapper);77
}90
}78
}91
}79
92
@@ -111,3 +124,32 @@ impl DesktopCapturerCallbackWrapper {111
}124
}112
}125
}113
}126
}127
128
#[derive(Debug, Clone, Copy, PartialEq, Eq)]129
pub enum PickerEvent {130
Selected,131
Cancelled,132
Failed,133
}134
135
pub struct PortalPickerCallbackWrapper {136
callback: Box<dyn FnMut(PickerEvent) + Send>,137
}138
139
impl PortalPickerCallbackWrapper {140
pub fn new(callback: Box<dyn FnMut(PickerEvent) + Send>) -> Self {141
Self { callback }142
}143
144
fn on_selection(&mut self) {145
(self.callback)(PickerEvent::Selected);146
}147
148
fn on_cancelled(&mut self) {149
(self.callback)(PickerEvent::Cancelled);150
}151
152
fn on_error(&mut self) {153
(self.callback)(PickerEvent::Failed);154
}155
}