1mod live_kit_token;
2
3use gpui::{
4 actions,
5 elements::{Canvas, *},
6 keymap::Binding,
7 platform::current::Surface,
8 Menu, MenuItem, ViewContext,
9};
10use live_kit::{LocalVideoTrack, Room};
11use log::LevelFilter;
12use media::core_video::CVImageBuffer;
13use simplelog::SimpleLogger;
14
15actions!(capture, [Quit]);
16
17fn main() {
18 SimpleLogger::init(LevelFilter::Info, Default::default()).expect("could not initialize logger");
19
20 gpui::App::new(()).unwrap().run(|cx| {
21 cx.platform().activate(true);
22 cx.add_global_action(quit);
23
24 cx.add_bindings([Binding::new("cmd-q", Quit, None)]);
25 cx.set_menus(vec![Menu {
26 name: "Zed",
27 items: vec![MenuItem::Action {
28 name: "Quit",
29 action: Box::new(Quit),
30 }],
31 }]);
32
33 let live_kit_key = std::env::var("LIVE_KIT_KEY").unwrap();
34 let live_kit_secret = std::env::var("LIVE_KIT_SECRET").unwrap();
35
36 let token = live_kit_token::create_token(
37 &live_kit_key,
38 &live_kit_secret,
39 "test-room",
40 "test-participant",
41 )
42 .unwrap();
43
44 let room = live_kit::Room::new();
45 cx.foreground()
46 .spawn(async move {
47 println!("connecting...");
48 room.connect("wss://zed.livekit.cloud", &token).await;
49 let windows = live_kit::list_windows();
50 println!("connected! {:?}", windows);
51
52 let window_id = windows.iter().next().unwrap().id;
53 let track = LocalVideoTrack::screen_share_for_window(window_id);
54 })
55 .detach();
56
57 // cx.add_window(Default::default(), |cx| ScreenCaptureView::new(cx));
58 });
59}
60
61struct ScreenCaptureView {
62 image_buffer: Option<CVImageBuffer>,
63}
64
65impl gpui::Entity for ScreenCaptureView {
66 type Event = ();
67}
68
69impl ScreenCaptureView {
70 pub fn new(_: &mut ViewContext<Self>) -> Self {
71 Self { image_buffer: None }
72 }
73}
74
75impl gpui::View for ScreenCaptureView {
76 fn ui_name() -> &'static str {
77 "View"
78 }
79
80 fn render(&mut self, _: &mut gpui::RenderContext<Self>) -> gpui::ElementBox {
81 let image_buffer = self.image_buffer.clone();
82 Canvas::new(move |bounds, _, cx| {
83 if let Some(image_buffer) = image_buffer.clone() {
84 cx.scene.push_surface(Surface {
85 bounds,
86 image_buffer,
87 });
88 }
89 })
90 .boxed()
91 }
92}
93
94fn quit(_: &Quit, cx: &mut gpui::MutableAppContext) {
95 cx.platform().quit();
96}