[Add] Call admins are now in call metadata and not user metadata

This commit is contained in:
Alex Emmet 2026-05-01 01:35:40 +02:00
commit ed8f482e5a
5 changed files with 109 additions and 15 deletions

59
Cargo.lock generated
View file

@ -14,7 +14,8 @@ dependencies = [
"futures", "futures",
"hex", "hex",
"hickory-resolver", "hickory-resolver",
"hkdf", "hkdf 0.13.0",
"json",
"livekit-api", "livekit-api",
"livekit-protocol", "livekit-protocol",
"log", "log",
@ -22,7 +23,9 @@ dependencies = [
"rand 0.8.6", "rand 0.8.6",
"rand_core 0.6.4", "rand_core 0.6.4",
"rustls", "rustls",
"sha2 0.10.9", "serde",
"serde_json",
"sha2 0.11.0",
"strum", "strum",
"strum_macros", "strum_macros",
"thiserror 2.0.18", "thiserror 2.0.18",
@ -472,6 +475,12 @@ dependencies = [
"cc", "cc",
] ]
[[package]]
name = "cmov"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f88a43d011fc4a6876cb7344703e297c71dda42494fee094d5f7c76bf13f746"
[[package]] [[package]]
name = "combine" name = "combine"
version = "4.6.7" version = "4.6.7"
@ -608,6 +617,15 @@ dependencies = [
"cipher", "cipher",
] ]
[[package]]
name = "ctutils"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d5515a3834141de9eafb9717ad39eea8247b5674e6066c404e8c4b365d2a29e"
dependencies = [
"cmov",
]
[[package]] [[package]]
name = "curve25519-dalek" name = "curve25519-dalek"
version = "4.1.3" version = "4.1.3"
@ -725,6 +743,7 @@ dependencies = [
"block-buffer 0.12.0", "block-buffer 0.12.0",
"const-oid 0.10.2", "const-oid 0.10.2",
"crypto-common 0.2.1", "crypto-common 0.2.1",
"ctutils",
] ]
[[package]] [[package]]
@ -827,7 +846,7 @@ dependencies = [
"ff", "ff",
"generic-array", "generic-array",
"group", "group",
"hkdf", "hkdf 0.12.4",
"pem-rfc7468", "pem-rfc7468",
"pkcs8", "pkcs8",
"rand_core 0.6.4", "rand_core 0.6.4",
@ -1255,7 +1274,16 @@ version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7"
dependencies = [ dependencies = [
"hmac", "hmac 0.12.1",
]
[[package]]
name = "hkdf"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4aaa26c720c68b866f2c96ef5c1264b3e6f473fe5d4ce61cd44bbe913e553018"
dependencies = [
"hmac 0.13.0",
] ]
[[package]] [[package]]
@ -1267,6 +1295,15 @@ dependencies = [
"digest 0.10.7", "digest 0.10.7",
] ]
[[package]]
name = "hmac"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6303bc9732ae41b04cb554b844a762b4115a61bfaa81e3e83050991eeb56863f"
dependencies = [
"digest 0.11.2",
]
[[package]] [[package]]
name = "httlib-huffman" name = "httlib-huffman"
version = "0.3.4" version = "0.3.4"
@ -1640,6 +1677,12 @@ dependencies = [
"wasm-bindgen", "wasm-bindgen",
] ]
[[package]]
name = "json"
version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "078e285eafdfb6c4b434e0d31e8cfcb5115b651496faca5749b88fafd4f23bfd"
[[package]] [[package]]
name = "jsonwebtoken" name = "jsonwebtoken"
version = "10.3.0" version = "10.3.0"
@ -1649,7 +1692,7 @@ dependencies = [
"base64 0.22.1", "base64 0.22.1",
"ed25519-dalek", "ed25519-dalek",
"getrandom 0.2.17", "getrandom 0.2.17",
"hmac", "hmac 0.12.1",
"js-sys", "js-sys",
"p256", "p256",
"p384", "p384",
@ -2738,7 +2781,7 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2"
dependencies = [ dependencies = [
"hmac", "hmac 0.12.1",
"subtle", "subtle",
] ]
@ -3418,7 +3461,7 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
[[package]] [[package]]
name = "ttp-core" name = "ttp-core"
version = "0.1.0" version = "0.1.0"
source = "git+https://git.methanium.net/Tensamin/TTP.git#dfa664cab77f188be001937ba9ca05061a67c691" source = "git+https://git.methanium.net/Tensamin/TTP.git#9677eb6c6040e4e8d85ba8b6232aa954b5a9438d"
dependencies = [ dependencies = [
"base64 0.22.1", "base64 0.22.1",
"byteorder", "byteorder",
@ -3431,7 +3474,7 @@ dependencies = [
[[package]] [[package]]
name = "ttp-native" name = "ttp-native"
version = "0.1.0" version = "0.1.0"
source = "git+https://git.methanium.net/Tensamin/TTP.git#dfa664cab77f188be001937ba9ca05061a67c691" source = "git+https://git.methanium.net/Tensamin/TTP.git#9677eb6c6040e4e8d85ba8b6232aa954b5a9438d"
dependencies = [ dependencies = [
"quinn", "quinn",
"rustls", "rustls",

View file

@ -9,30 +9,32 @@ ttp-native = { git = "https://git.methanium.net/Tensamin/TTP.git", package = "tt
ansi_term = "*" ansi_term = "*"
uuid = { version = "*", features = ["v4"] } uuid = { version = "*", features = ["v4"] }
base64 = "0.22.1" base64 = "0.22.1"
dashmap = "*" dashmap = "*"
futures = "*" futures = "*"
hex = "*" hex = "*"
once_cell = "1.21.3" once_cell = "1.21.4"
rand = "0.8" rand = "0.8"
rand_core = { version = "0.6", features = ["getrandom", "std"] } rand_core = { version = "0.6", features = ["getrandom", "std"] }
rustls = { version = "0.23.37", default-features = false, features = [ rustls = { version = "0.23.40", default-features = false, features = [
"std", "std",
"tls12", "tls12",
"aws-lc-rs", "aws-lc-rs",
"prefer-post-quantum", "prefer-post-quantum",
] } ] }
aes-gcm = "0.10.3" aes-gcm = "0.10.3"
sha2 = "0.10.9" sha2 = "0.11.0"
tokio = { version = "*", features = ["full"] } tokio = { version = "*", features = ["full"] }
x448 = { version = "*" } x448 = { version = "*" }
log = "0.4" log = "0.4"
dotenv = "0.15.0" dotenv = "0.15.0"
hkdf = "0.12.4" hkdf = "0.13"
strum = "0.28.0" strum = "0.28.0"
strum_macros = "0.28.0" strum_macros = "0.28.0"
livekit-api = { version = "0.4.14", features = ["native-tls"] } livekit-api = { version = "0.4.14", features = ["native-tls"] }
livekit-protocol = "0.7.1" livekit-protocol = "0.7.1"
thiserror = "2.0.18" thiserror = "2.0.18"
hickory-resolver = "0.25.2" hickory-resolver = "0.25.2"
serde = "1.0.228"
serde_json = "1.0.149"
json = "0.12.4"

54
src/calls/call_group.rs Normal file → Executable file
View file

@ -1,3 +1,4 @@
use serde_json::Map;
use ttp_core::{CommunicationType, CommunicationValue, DataTypes, DataValue}; use ttp_core::{CommunicationType, CommunicationValue, DataTypes, DataValue};
use std::{collections::BTreeMap, env, sync::Arc, time::Duration}; use std::{collections::BTreeMap, env, sync::Arc, time::Duration};
@ -43,12 +44,59 @@ impl CallGroup {
*self.anonymous_joining.read().await *self.anonymous_joining.read().await
} }
pub async fn set_anonymous_joining(&self, enable: bool) { pub async fn update_admins(&self) {
*self.anonymous_joining.write().await = enable; let call_metadata = match call_util::get_room_metadata(self.call_id).await {
Ok(metadata) => metadata,
Err(_) => "{}".to_string(),
};
let call_metadata: serde_json::Value = match serde_json::from_str(&call_metadata) {
Ok(json) => json,
Err(_) => serde_json::Value::Object(Map::new()),
};
let mut call_metadata = match call_metadata.as_object() {
Some(metadata) => metadata.clone(),
None => Map::new(),
};
let admin_ids = self
.members
.read()
.await
.iter()
.filter(|member| member.has_admin)
.map(|admin| admin.user_id)
.collect::<Vec<_>>();
call_metadata.insert("admins".to_string(), serde_json::json!(admin_ids));
let _ = call_util::set_room_metadata( let _ = call_util::set_room_metadata(
self.call_id, self.call_id,
format!("{{\"anonymous_joining\": \"{}\"}}", enable), serde_json::Value::Object(call_metadata).to_string(),
)
.await;
}
pub async fn set_anonymous_joining(&self, enable: bool) {
*self.anonymous_joining.write().await = enable;
let call_metadata = match call_util::get_room_metadata(self.call_id).await {
Ok(metadata) => metadata,
Err(_) => "{}".to_string(),
};
let call_metadata: serde_json::Value = match serde_json::from_str(&call_metadata) {
Ok(json) => json,
Err(_) => serde_json::Value::Object(Map::new()),
};
let mut call_metadata = match call_metadata.as_object() {
Some(metadata) => metadata.clone(),
None => Map::new(),
};
call_metadata.insert("anonymous_joining".to_string(), serde_json::json!(enable));
let _ = call_util::set_room_metadata(
self.call_id,
serde_json::Value::Object(call_metadata).to_string(),
) )
.await; .await;

View file

@ -74,6 +74,7 @@ pub async fn get_call_token(user_id: u64, call_id: Uuid) -> Option<String> {
let caller = Arc::new(Caller::new(user_id, call_id, true)); let caller = Arc::new(Caller::new(user_id, call_id, true));
let call_group = CallGroup::new(call_id, caller.clone()); let call_group = CallGroup::new(call_id, caller.clone());
call_group.update_admins().await;
CALL_GROUPS.insert(call_id, Arc::new(call_group)); CALL_GROUPS.insert(call_id, Arc::new(call_group));

View file

@ -42,11 +42,11 @@ pub fn create_token(user_id: u64, call_id: Uuid, has_admin: bool) -> Result<Stri
.with_identity(&user_id.to_string()) .with_identity(&user_id.to_string())
.with_grants(access_token::VideoGrants { .with_grants(access_token::VideoGrants {
room_join: true, room_join: true,
can_update_own_metadata: true,
room_admin: has_admin, room_admin: has_admin,
room: call_id.to_string(), room: call_id.to_string(),
..Default::default() ..Default::default()
}) })
.with_metadata(&format!("{{\"isAdmin\":{}}}", has_admin))
.to_jwt(); .to_jwt();
if let Ok(token) = token { if let Ok(token) = token {
Ok(token) Ok(token)