initial livekit support
fix up code undo changes to compose file add back .env.example
This commit is contained in:
1
crates/voice-ingress/.gitignore
vendored
Normal file
1
crates/voice-ingress/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/target
|
||||
44
crates/voice-ingress/Cargo.toml
Normal file
44
crates/voice-ingress/Cargo.toml
Normal file
@@ -0,0 +1,44 @@
|
||||
[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 = { version = "0.7.1", path = "../core/permissions" }
|
||||
revolt-presence = { path = "../core/presence", features = ["redis-is-patched"] }
|
||||
|
||||
# voice
|
||||
livekit-api = "0.3.2"
|
||||
livekit-protocol = "0.3.2"
|
||||
11
crates/voice-ingress/Dockerfile
Normal file
11
crates/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"]
|
||||
75
crates/voice-ingress/src/main.rs
Normal file
75
crates/voice-ingress/src/main.rs
Normal file
@@ -0,0 +1,75 @@
|
||||
use std::env;
|
||||
|
||||
use redis_kiss::{get_connection, AsyncCommands};
|
||||
|
||||
use revolt_database::events::client::EventV1;
|
||||
use rocket::{build, post, routes, serde::json::Json, Config};
|
||||
use rocket_empty::EmptyResponse;
|
||||
use livekit_protocol::WebhookEvent;
|
||||
|
||||
use revolt_config::Database;
|
||||
use revolt_result::Result;
|
||||
|
||||
#[async_std::main]
|
||||
async fn main() {
|
||||
revolt_config::configure!(voice_ingress);
|
||||
|
||||
let rocket = build()
|
||||
.manage(get_connection().await.unwrap())
|
||||
.mount("/", routes![ingress])
|
||||
.configure(Config { port: 8500, ..Default::default() })
|
||||
.launch()
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[post("/", data="<body>")]
|
||||
async fn ingress(body: Json<WebhookEvent>) -> Result<EmptyResponse> {
|
||||
let mut redis = get_connection().await.unwrap();
|
||||
|
||||
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.unwrap();
|
||||
let user_id = user_id.unwrap();
|
||||
|
||||
redis.sadd::<_, _, u64>(format!("vc-members-{}", channel_id), user_id).await.unwrap();
|
||||
redis.set::<_, _, String>(format!("vc-{}", user_id), &channel_id).await.unwrap();
|
||||
|
||||
EventV1::VoiceChannelJoin {
|
||||
id: channel_id.clone(),
|
||||
user: user_id.clone()
|
||||
}
|
||||
.p(channel_id.clone())
|
||||
.await
|
||||
},
|
||||
"participant_left" => {
|
||||
let channel_id = channel_id.unwrap();
|
||||
let user_id = user_id.unwrap();
|
||||
|
||||
redis.srem::<_, _, u64>(format!("vc-members-{}", channel_id), user_id).await.unwrap();
|
||||
redis.del::<_, u64>(format!("vc-{}", user_id)).await.unwrap();
|
||||
|
||||
EventV1::VoiceChannelLeave {
|
||||
id: channel_id.clone(),
|
||||
user: user_id.clone()
|
||||
}
|
||||
.p(channel_id.clone())
|
||||
.await
|
||||
},
|
||||
_ => {}
|
||||
};
|
||||
|
||||
Ok(EmptyResponse)
|
||||
}
|
||||
Reference in New Issue
Block a user