feat(server): protocol v2 with signed handshake, secure voice relay, media broadcast and channel authorization
Revoke voice access on channel delete, kick and permission change, and acknowledge the sender's own chat messages.
This commit is contained in:
parent
bc5157046e
commit
3e7f5b22dc
44 changed files with 2825 additions and 386 deletions
|
|
@ -8,7 +8,7 @@ use crate::{
|
|||
proto::SessionCrypto,
|
||||
};
|
||||
|
||||
use super::{broadcast_leave, set_channel};
|
||||
use super::{broadcast_leave, set_channel, set_voice_channel};
|
||||
|
||||
pub async fn leave(
|
||||
_stream: &mut (impl AsyncRead + AsyncWrite + Unpin),
|
||||
|
|
@ -18,17 +18,25 @@ pub async fn leave(
|
|||
_crypto: &SessionCrypto,
|
||||
state: &State,
|
||||
) -> Result<()> {
|
||||
let user_id = session::get(&state.sessions, session_id)
|
||||
.await
|
||||
.map(|s| s.user_id);
|
||||
|
||||
let is_voice = channels::get_channel(&state.channels, channel_id)
|
||||
.await
|
||||
.is_some_and(|c| c.kind == channels::ChannelKind::Voice);
|
||||
let Some(sess) = session::get(&state.sessions, session_id).await else {
|
||||
return Ok(());
|
||||
};
|
||||
let is_voice = sess.voice_channel_id.as_deref() == Some(channel_id);
|
||||
if !is_voice && sess.channel_id.as_deref() != Some(channel_id) {
|
||||
return Ok(());
|
||||
}
|
||||
let user_id = Some(sess.user_id);
|
||||
|
||||
channels::leave(&state.channels, channel_id, session_id).await;
|
||||
set_channel(state, session_id, None).await;
|
||||
if is_voice {
|
||||
set_voice_channel(state, session_id, None).await;
|
||||
} else {
|
||||
set_channel(state, session_id, None).await;
|
||||
}
|
||||
broadcast_leave(state, channel_id, session_id).await;
|
||||
if is_voice {
|
||||
state.media.revoke(state, session_id).await;
|
||||
}
|
||||
|
||||
if is_voice
|
||||
&& let Some(tx) = &state.voice_member_tx
|
||||
|
|
@ -36,6 +44,7 @@ pub async fn leave(
|
|||
{
|
||||
let event = serde_json::json!({
|
||||
"type": "leave",
|
||||
"session_id": session_id,
|
||||
"channel_id": channel_id,
|
||||
"user_id": uid,
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue