basic mute,unmute,change channel

This commit is contained in:
2024-11-08 21:18:35 -07:00
parent 6c808694db
commit 326b9eee63
3 changed files with 98 additions and 7 deletions
+58 -2
View File
@@ -25,6 +25,16 @@ pub enum Command {
markdown: String, markdown: String,
channels: Vec<ChannelId>, channels: Vec<ChannelId>,
}, },
SetMute {
mute: bool,
},
SetDeaf {
deaf: bool,
},
EnterChannel {
channel: ChannelId,
user: UserId,
},
Disconnect, Disconnect,
} }
@@ -43,6 +53,10 @@ pub struct ChannelState {
pub struct UserState { pub struct UserState {
pub name: String, pub name: String,
pub channel: ChannelId, pub channel: ChannelId,
pub deaf: bool,
pub mute: bool,
pub self_deaf: bool,
pub self_mute: bool,
} }
pub struct Chat { pub struct Chat {
@@ -105,7 +119,9 @@ pub fn User(id: UserId) -> Element {
#[component] #[component]
pub fn Channel(id: ChannelId) -> Element { pub fn Channel(id: ChannelId) -> Element {
let net: Coroutine<Command> = use_coroutine_handle();
let server = STATE.server.read(); let server = STATE.server.read();
let user = server.session?;
let state = server.channels.get(&id)?; let state = server.channels.get(&id)?;
let channel_details = css!( let channel_details = css!(
@@ -129,7 +145,10 @@ pub fn Channel(id: ChannelId) -> Element {
details { details {
class: "{channel_details}", class: "{channel_details}",
open: true, open: true,
summary { "{state.name}" } summary {
ondoubleclick: move |_| net.send(EnterChannel { channel: id, user }),
"{state.name}"
}
div { div {
class: "{channel_children}", class: "{channel_children}",
for id in state.users.iter() { for id in state.users.iter() {
@@ -229,6 +248,13 @@ pub fn ChatView() -> Element {
pub fn ServerView() -> Element { pub fn ServerView() -> Element {
let net: Coroutine<Command> = use_coroutine_handle(); let net: Coroutine<Command> = use_coroutine_handle();
let server = STATE.server.read(); let server = STATE.server.read();
let &UserState {
deaf,
self_deaf,
mute,
self_mute,
..
} = server.this_user()?;
let grid = css!( let grid = css!(
r#" r#"
@@ -280,6 +306,11 @@ pub fn ServerView() -> Element {
border: solid black 1px; border: solid black 1px;
grid-area: bar; grid-area: bar;
display: flex;
flex-direction: row;
gap: 16px;
align-items: center;
button { button {
padding: 8px; padding: 8px;
} }
@@ -295,7 +326,32 @@ pub fn ServerView() -> Element {
onclick: move |_| net.send(Disconnect), onclick: move |_| net.send(Disconnect),
"Disconnect" "Disconnect"
} }
span {
input {
r#type: "checkbox",
id: "mute",
checked: mute || self_mute,
disabled: mute,
onchange: move |_| net.send(SetMute { mute: !self_mute }),
}
label {
r#for: "mute",
"Mute"
}
}
span {
input {
r#type: "checkbox",
id: "deaf",
checked: deaf || self_deaf,
disabled: deaf,
onchange: move |_| net.send(SetDeaf { deaf: !self_deaf }),
}
label {
r#for: "deaf",
"Deafen"
}
}
} }
div { div {
class: "{channel_box}", class: "{channel_box}",
+3 -3
View File
@@ -67,12 +67,12 @@ pub struct AudioSystem();
impl AudioSystem { impl AudioSystem {
pub fn new(sender: UnboundedSender<ControlPacket<Serverbound>>) -> Result<Self, Error> { pub fn new(sender: UnboundedSender<ControlPacket<Serverbound>>) -> Result<Self, Error> {
dbg!("todo"); // dbg!("todo");
Ok(AudioSystem()) Ok(AudioSystem())
} }
pub fn create_player(&mut self) -> Result<AudioPlayer, Error> { pub fn create_player(&mut self) -> Result<AudioPlayer, Error> {
dbg!("todo"); // dbg!("todo");
Ok(AudioPlayer()) Ok(AudioPlayer())
} }
} }
@@ -81,7 +81,7 @@ pub struct AudioPlayer();
impl AudioPlayer { impl AudioPlayer {
pub fn play_opus(&mut self, payload: &[u8]) { pub fn play_opus(&mut self, payload: &[u8]) {
dbg!("todo"); // dbg!("todo");
} }
} }
+37 -2
View File
@@ -164,8 +164,13 @@ fn accept_command(
command: Command, command: Command,
send_chan: &mut UnboundedSender<ControlPacket<mumble_protocol::Serverbound>>, send_chan: &mut UnboundedSender<ControlPacket<mumble_protocol::Serverbound>>,
) -> Result<(), Error> { ) -> Result<(), Error> {
use Command::*;
let Some(session) = STATE.server.read().session else {
bail!("no session id")
};
match command { match command {
Command::SendChat { markdown, channels } => { SendChat { markdown, channels } => {
use markdown::*; use markdown::*;
let blocks = tokenize(&markdown); let blocks = tokenize(&markdown);
let html_text = match blocks.as_slice() { let html_text = match blocks.as_slice() {
@@ -199,7 +204,25 @@ fn accept_command(
u.set_channel_id(channels); u.set_channel_id(channels);
let _ = send_chan.unbounded_send(u.into()); let _ = send_chan.unbounded_send(u.into());
} }
_ => (), SetMute { mute } => {
let mut u = msgs::UserState::new();
u.set_session(session);
u.set_self_mute(mute);
let _ = send_chan.unbounded_send(u.into());
}
SetDeaf { deaf } => {
let mut u = msgs::UserState::new();
u.set_session(session);
u.set_self_deaf(deaf);
let _ = send_chan.unbounded_send(u.into());
}
EnterChannel { channel, user } => {
let mut u = msgs::UserState::new();
u.set_session(user);
u.set_channel_id(channel);
let _ = send_chan.unbounded_send(u.into());
}
Connect { .. } | Disconnect => (),
} }
Ok(()) Ok(())
@@ -306,6 +329,18 @@ fn accept_packet(
if u.has_name() { if u.has_name() {
state.name = u.get_name().to_string(); state.name = u.get_name().to_string();
} }
if u.has_mute() {
state.mute = u.get_mute();
}
if u.has_deaf() {
state.deaf = u.get_deaf();
}
if u.has_self_mute() {
state.self_mute = u.get_self_mute();
}
if u.has_self_deaf() {
state.self_deaf = u.get_self_deaf();
}
} }
ControlPacket::UserRemove(u) => { ControlPacket::UserRemove(u) => {
let mut server = STATE.server.write(); let mut server = STATE.server.write();