diff options
author | metamuffin <metamuffin@disroot.org> | 2022-10-15 16:11:53 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2022-10-15 16:11:53 +0200 |
commit | 23c7be33dbb46ce35d53f94a8c6e48aabb7e983c (patch) | |
tree | 2735b5e56692ec80cf9634bdca65a2339893d31d /client-native-gui | |
parent | 3c84ae796df7755742c1210ef1a84478c4e65e23 (diff) | |
download | keks-meet-23c7be33dbb46ce35d53f94a8c6e48aabb7e983c.tar keks-meet-23c7be33dbb46ce35d53f94a8c6e48aabb7e983c.tar.bz2 keks-meet-23c7be33dbb46ce35d53f94a8c6e48aabb7e983c.tar.zst |
add some native gui code
Diffstat (limited to 'client-native-gui')
-rw-r--r-- | client-native-gui/Cargo.toml | 2 | ||||
-rw-r--r-- | client-native-gui/src/main.rs | 162 |
2 files changed, 161 insertions, 3 deletions
diff --git a/client-native-gui/Cargo.toml b/client-native-gui/Cargo.toml index b801af6..3912bc9 100644 --- a/client-native-gui/Cargo.toml +++ b/client-native-gui/Cargo.toml @@ -6,6 +6,8 @@ edition = "2021" [dependencies] client-native-lib = { path = "../client-native-lib" } +async-std = "1.12.0" +tokio = { version = "1.21.2", features = ["full"] } env_logger = "0.8" log = "0.4" diff --git a/client-native-gui/src/main.rs b/client-native-gui/src/main.rs index db87ed6..e376d14 100644 --- a/client-native-gui/src/main.rs +++ b/client-native-gui/src/main.rs @@ -1,4 +1,160 @@ -fn main() { - - +#![feature(box_syntax)] + +use std::{ + future::Future, + ops::Deref, + pin::Pin, + sync::{Arc, RwLock}, +}; + +use async_std::task::block_on; +use client_native_lib::{instance::Instance, peer::Peer, Config, EventHandler}; +use eframe::{egui, epaint::ahash::HashMap}; +use egui::{Ui, Visuals}; +use tokio::task::{block_in_place, JoinHandle}; + +#[tokio::main] +async fn main() { + env_logger::builder() + .filter_module("keks_meet", log::LevelFilter::Info) + .filter_module("client_native_lib", log::LevelFilter::Info) + .parse_env("LOG") + .init(); + + let options = eframe::NativeOptions::default(); + eframe::run_native( + "keks-meet", + options, + Box::new(|cc| { + cc.egui_ctx.set_visuals(Visuals { + dark_mode: true, + ..Default::default() + }); + Box::new(App::new()) + }), + ); +} + +enum App { + Prejoin(String), + Joining(Option<JoinHandle<Ingame>>), + Ingame(Ingame), +} + +impl App { + pub fn new() -> Self { + Self::Prejoin("longtest".to_string()) + } +} + +impl eframe::App for App { + fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { + egui::CentralPanel::default().show(ctx, |ui| match self { + App::Prejoin(secret) => { + ui.heading("Join a meeting"); + ui.label("Room secret:"); + ui.text_edit_singleline(secret); + if ui.button("Join").clicked() { + let secret = secret.clone(); + *self = Self::Joining(Some(tokio::spawn(async move { + Ingame::new(Config { + secret, + username: "blub".to_string(), + signaling_uri: "wss://meet.metamuffin.org".to_string(), + }) + .await + }))) + } + } + App::Joining(fut) => { + ui.spinner(); + if fut.as_ref().map(|f| f.is_finished()).unwrap_or(false) { + *self = Self::Ingame(block_on(fut.take().unwrap()).unwrap()); + } + } + App::Ingame(x) => x.ui(ui), + }); + } +} + +struct Ingame { + instance: Arc<Instance>, + handler: Arc<Handler>, +} +impl Ingame { + pub async fn new(config: Config) -> Self { + let handler = Arc::new(Handler::new()); + Self { + instance: Instance::new(config, handler.clone()).await, + handler, + } + } + + pub fn ui(&self, ui: &mut Ui) { + for (pid, peer) in self.handler.peers.read().unwrap().deref() { + ui.heading(format!("{}", pid)); + } + } +} + +struct Handler { + peers: std::sync::RwLock<HashMap<usize, GuiPeer>>, +} + +struct GuiPeer { + peer: Arc<Peer>, +} + +impl Handler { + pub fn new() -> Self { + Self { + peers: Default::default(), + } + } +} + +impl EventHandler for Handler { + fn peer_join( + &self, + peer: std::sync::Arc<client_native_lib::peer::Peer>, + ) -> client_native_lib::DynFut<()> { + self.peers + .write() + .unwrap() + .insert(peer.id, GuiPeer { peer: peer.clone() }); + Box::pin(async move {}) + } + + fn peer_leave( + &self, + peer: std::sync::Arc<client_native_lib::peer::Peer>, + ) -> client_native_lib::DynFut<()> { + self.peers.write().unwrap().remove(&peer.id); + Box::pin(async move {}) + } + + fn resource_added( + &self, + peer: std::sync::Arc<client_native_lib::peer::Peer>, + info: client_native_lib::protocol::ProvideInfo, + ) -> client_native_lib::DynFut<()> { + Box::pin(async move {}) + } + + fn resource_removed( + &self, + peer: std::sync::Arc<client_native_lib::peer::Peer>, + id: String, + ) -> client_native_lib::DynFut<()> { + Box::pin(async move {}) + } + + fn resource_connected( + &self, + peer: std::sync::Arc<client_native_lib::peer::Peer>, + resource: &client_native_lib::protocol::ProvideInfo, + channel: client_native_lib::peer::TransportChannel, + ) -> client_native_lib::DynFut<()> { + Box::pin(async move {}) + } } |