forked from jmug/stoatchat
Merge remote-tracking branch 'origin/main' into livekit
This commit is contained in:
1
crates/daemons/voice-ingress/.gitignore
vendored
Normal file
1
crates/daemons/voice-ingress/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/target
|
||||
45
crates/daemons/voice-ingress/Cargo.toml
Normal file
45
crates/daemons/voice-ingress/Cargo.toml
Normal file
@@ -0,0 +1,45 @@
|
||||
[package]
|
||||
name = "revolt-voice-ingress"
|
||||
version = "0.7.1"
|
||||
license = "AGPL-3.0-or-later"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
# util
|
||||
log = "*"
|
||||
sentry = "0.31.5"
|
||||
lru = "0.7.6"
|
||||
ulid = "0.5.0"
|
||||
redis-kiss = "0.1.4"
|
||||
|
||||
# serde
|
||||
serde_json = "1.0.79"
|
||||
rmp-serde = "1.0.0"
|
||||
serde = "1.0.136"
|
||||
|
||||
# http
|
||||
rocket = { version = "0.5.0-rc.2", features = ["json"] }
|
||||
rocket_empty = "0.1.1"
|
||||
|
||||
# async
|
||||
futures = "0.3.21"
|
||||
async-std = { version = "1.8.0", features = [
|
||||
"tokio1",
|
||||
"tokio02",
|
||||
"attributes",
|
||||
] }
|
||||
|
||||
# core
|
||||
revolt-result = { path = "../../core/result" }
|
||||
revolt-models = { path = "../../core/models" }
|
||||
revolt-config = { path = "../../core/config" }
|
||||
revolt-database = { path = "../../core/database" }
|
||||
revolt-permissions = { path = "../../core/permissions" }
|
||||
revolt-voice = { path = "../../core/voice" }
|
||||
|
||||
# voice
|
||||
livekit-api = "0.4.1"
|
||||
livekit-protocol = "0.3.6"
|
||||
livekit-runtime = { version = "0.3.1", features = ["tokio"] }
|
||||
11
crates/daemons/voice-ingress/Dockerfile
Normal file
11
crates/daemons/voice-ingress/Dockerfile
Normal file
@@ -0,0 +1,11 @@
|
||||
# Build Stage
|
||||
FROM ghcr.io/revoltchat/base:latest AS builder
|
||||
|
||||
# Bundle Stage
|
||||
FROM debian:bullseye-slim
|
||||
RUN apt-get update && \
|
||||
apt-get install -y ca-certificates && \
|
||||
apt-get clean
|
||||
COPY --from=builder /home/rust/src/target/release/revolt-voice-ingress ./
|
||||
EXPOSE 9000
|
||||
CMD ["./revolt-voice-ingress"]
|
||||
108
crates/daemons/voice-ingress/src/main.rs
Normal file
108
crates/daemons/voice-ingress/src/main.rs
Normal file
@@ -0,0 +1,108 @@
|
||||
use std::env;
|
||||
|
||||
|
||||
use livekit_protocol::WebhookEvent;
|
||||
use revolt_database::{
|
||||
events::client::EventV1, util::reference::Reference, Database, DatabaseInfo,
|
||||
};
|
||||
use revolt_voice::{create_voice_state, delete_voice_state, update_voice_state_tracks, VoiceClient};
|
||||
use rocket::{build, post, routes, serde::json::Json, Config, State};
|
||||
use rocket_empty::EmptyResponse;
|
||||
|
||||
use revolt_result::{Result, ToRevoltError};
|
||||
|
||||
#[rocket::main]
|
||||
async fn main() -> Result<(), rocket::Error> {
|
||||
revolt_config::configure!(voice_ingress);
|
||||
|
||||
let database = DatabaseInfo::Auto.connect().await.unwrap();
|
||||
let voice_client = VoiceClient::from_revolt_config().await;
|
||||
|
||||
let _rocket = build()
|
||||
.manage(database)
|
||||
.manage(voice_client)
|
||||
.mount("/", routes![ingress])
|
||||
.configure(Config {
|
||||
port: 8500,
|
||||
..Default::default()
|
||||
})
|
||||
.ignite()
|
||||
.await?
|
||||
.launch()
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[post("/", data = "<body>")]
|
||||
async fn ingress(db: &State<Database>, voice_client: &State<VoiceClient>, body: Json<WebhookEvent>) -> Result<EmptyResponse> {
|
||||
log::debug!("received event: {body:?}");
|
||||
|
||||
let channel_id = body.room.as_ref().map(|r| &r.name);
|
||||
let user_id = body.participant.as_ref().map(|r| &r.identity);
|
||||
|
||||
match body.event.as_str() {
|
||||
"participant_joined" => {
|
||||
let channel_id = channel_id.to_internal_error()?;
|
||||
let user_id = user_id.to_internal_error()?;
|
||||
|
||||
let channel = Reference::from_unchecked(channel_id.clone())
|
||||
.as_channel(db)
|
||||
.await?;
|
||||
|
||||
let voice_state = create_voice_state(channel_id, channel.server().as_deref(), user_id).await?;
|
||||
|
||||
EventV1::VoiceChannelJoin {
|
||||
id: channel_id.clone(),
|
||||
state: voice_state,
|
||||
}
|
||||
.p(channel_id.clone())
|
||||
.await
|
||||
}
|
||||
"participant_left" => {
|
||||
let channel_id = channel_id.to_internal_error()?;
|
||||
let user_id = user_id.to_internal_error()?;
|
||||
|
||||
let channel = Reference::from_unchecked(channel_id.clone())
|
||||
.as_channel(db)
|
||||
.await?;
|
||||
|
||||
delete_voice_state(channel_id, channel.server().as_deref(), user_id).await?;
|
||||
|
||||
EventV1::VoiceChannelLeave {
|
||||
id: channel_id.clone(),
|
||||
user: user_id.clone(),
|
||||
}
|
||||
.p(channel_id.clone())
|
||||
.await
|
||||
}
|
||||
"track_published" | "track_unpublished" => {
|
||||
let channel_id = channel_id.to_internal_error()?;
|
||||
let user_id = user_id.to_internal_error()?;
|
||||
let track = body.track.as_ref().to_internal_error()?;
|
||||
|
||||
let channel = Reference::from_unchecked(channel_id.clone())
|
||||
.as_channel(db)
|
||||
.await?;
|
||||
|
||||
let partial = update_voice_state_tracks(
|
||||
channel_id,
|
||||
channel.server().as_deref(),
|
||||
user_id,
|
||||
body.event == "track_published", // to avoid duplicating this entire case twice
|
||||
track.source
|
||||
).await?;
|
||||
|
||||
EventV1::UserVoiceStateUpdate {
|
||||
id: user_id.clone(),
|
||||
channel_id: channel_id.clone(),
|
||||
data: partial
|
||||
}
|
||||
.p(channel_id.clone())
|
||||
.await;
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
|
||||
Ok(EmptyResponse)
|
||||
}
|
||||
Reference in New Issue
Block a user