summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2023-02-21 15:12:38 +0100
committermetamuffin <metamuffin@disroot.org>2023-02-21 15:12:38 +0100
commit630cd2b82887da49cacb2deb032c6a51b3c2faf7 (patch)
tree6a5eef8e1190d7e85a57d2bbe90663b71d56cabe
parent70e1090e7c5e5aa6ed0a621ad71924b7931ef05d (diff)
downloadkeks-meet-630cd2b82887da49cacb2deb032c6a51b3c2faf7.tar
keks-meet-630cd2b82887da49cacb2deb032c6a51b3c2faf7.tar.bz2
keks-meet-630cd2b82887da49cacb2deb032c6a51b3c2faf7.tar.zst
server-side client configuration
-rw-r--r--.gitignore2
-rw-r--r--Cargo.lock48
-rw-r--r--client-web/source/index.ts38
-rw-r--r--client-web/source/preferences/decl.ts6
-rw-r--r--client-web/source/preferences/mod.ts1
-rw-r--r--client-web/source/room.ts2
-rw-r--r--client-web/source/user/remote.ts4
-rw-r--r--server/Cargo.toml3
-rw-r--r--server/src/assets.rs4
-rw-r--r--server/src/config.rs20
-rw-r--r--server/src/main.rs14
11 files changed, 120 insertions, 22 deletions
diff --git a/.gitignore b/.gitignore
index ea8c4bf..a37f649 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,3 @@
/target
+/config/client.toml
+
diff --git a/Cargo.lock b/Cargo.lock
index 036d078..5f13e86 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2275,6 +2275,7 @@ dependencies = [
"serde",
"serde_json",
"tokio",
+ "toml",
"warp",
]
@@ -2964,7 +2965,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "66618389e4ec1c7afe67d51a9bf34ff9236480f8d51e7489b7d5ab0303c13f34"
dependencies = [
"once_cell",
- "toml_edit",
+ "toml_edit 0.18.1",
]
[[package]]
@@ -3422,6 +3423,15 @@ dependencies = [
]
[[package]]
+name = "serde_spanned"
+version = "0.6.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0efd8caf556a6cebd3b285caf480045fcc1ac04f6bd786b09a6f11af30c4fcf4"
+dependencies = [
+ "serde",
+]
+
+[[package]]
name = "serde_urlencoded"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -3888,12 +3898,33 @@ dependencies = [
]
[[package]]
+name = "toml"
+version = "0.7.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f7afcae9e3f0fe2c370fd4657108972cbb2fa9db1b9f84849cefd80741b01cb6"
+dependencies = [
+ "serde",
+ "serde_spanned",
+ "toml_datetime 0.6.1",
+ "toml_edit 0.19.3",
+]
+
+[[package]]
name = "toml_datetime"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4553f467ac8e3d374bc9a177a26801e5d0f9b211aa1673fb137a403afd1c9cf5"
[[package]]
+name = "toml_datetime"
+version = "0.6.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3ab8ed2edee10b50132aed5f331333428b011c99402b5a534154ed15746f9622"
+dependencies = [
+ "serde",
+]
+
+[[package]]
name = "toml_edit"
version = "0.18.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -3901,7 +3932,20 @@ checksum = "56c59d8dd7d0dcbc6428bf7aa2f0e823e26e43b3c9aca15bbc9475d23e5fa12b"
dependencies = [
"indexmap",
"nom8",
- "toml_datetime",
+ "toml_datetime 0.5.1",
+]
+
+[[package]]
+name = "toml_edit"
+version = "0.19.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5e6a7712b49e1775fb9a7b998de6635b299237f48b404dde71704f2e0e7f37e5"
+dependencies = [
+ "indexmap",
+ "nom8",
+ "serde",
+ "serde_spanned",
+ "toml_datetime 0.6.1",
]
[[package]]
diff --git a/client-web/source/index.ts b/client-web/source/index.ts
index 4772f94..4590625 100644
--- a/client-web/source/index.ts
+++ b/client-web/source/index.ts
@@ -17,18 +17,14 @@ import { Room } from "./room.ts"
export const VERSION = "0.1.12"
export const ROOM_CONTAINER = esection({ class: "room", aria_label: "user list" })
-export const RTC_CONFIG: RTCConfiguration = {
- iceServers: [
- {
- urls: [
- "turn:meet.metamuffin.org:16900",
- "stun:meet.metamuffin.org:16900"
- ],
- username: "keksmeet",
- credential: "ujCmetg6bm0"
- },
- ],
- iceCandidatePoolSize: 10,
+export interface ClientConfig {
+ appearance: { accent: string }
+ webrtc: {
+ stun: string,
+ turn?: string,
+ turn_user?: string,
+ turn_cred?: string
+ }
}
export interface User {
@@ -51,7 +47,12 @@ window.onbeforeunload = ev => {
let r: Room;
export async function main() {
document.body.append(LOGGER_CONTAINER)
- log("*", "starting up")
+ log("*", "loading client config")
+ const config_res = await fetch("/config.json")
+ if (!config_res.ok) return log({ scope: "*", error: true }, "cannot load config")
+ const config: ClientConfig = await config_res.json()
+ log("*", "config loaded. starting")
+
document.body.querySelectorAll("p").forEach(e => e.remove())
const room_secret = load_params().rsecret
@@ -64,7 +65,16 @@ export async function main() {
if (PREFS.warn_redirect) log({ scope: "crypto", warn: true }, "You were redirected from the old URL format. The server knows the room secret now - e2ee is insecure!")
const conn = await (new SignalingConnection().connect(room_secret))
- r = new Room(conn)
+ const rtc_config: RTCConfiguration = {
+ iceCandidatePoolSize: 10,
+ iceServers: [{
+ urls: [config.webrtc.stun, ...(config.webrtc.turn ? [config.webrtc.turn] : [])],
+ credential: config.webrtc.turn_cred,
+ username: config.webrtc.turn_user,
+ }]
+ }
+
+ r = new Room(conn, rtc_config)
setup_keybinds(r)
r.on_ready = () => {
diff --git a/client-web/source/preferences/decl.ts b/client-web/source/preferences/decl.ts
index f3f8e84..68cb9ee 100644
--- a/client-web/source/preferences/decl.ts
+++ b/client-web/source/preferences/decl.ts
@@ -18,7 +18,13 @@ export const PREF_DECLS = {
username: { type: string, default: "guest-" + hex_id(), description: "Username", allow_url: true },
warn_redirect: { type: bool, hidden: true, default: false, description: "Internal option that is set by a server redirect.", allow_url: true },
image_view_popup: { type: bool, default: true, description: "Open image in popup instead of new tab" },
+
+ // TODO!
+ /* WEBRTC */
webrtc_debug: { type: bool, default: false, description: "Show additional information for WebRTC related stuff" },
+ webrtc_stun: { type: string, default: "stun:meet.metamuffin.org:16900", description: "Custom STUN server (all participants must use the same server)" },
+ webrtc_turn: { type: optional(string), default: "turn:meet.metamuffin.org:16900", description: "Custom TURN server (all participants must use the same server)" },
+ webrtc_turn_cred: { type: optional(string), description: "TURN server credentials" },
/* MEDIA */
microphone_enabled: { type: bool, default: false, description: "Add one microphone track on startup" },
diff --git a/client-web/source/preferences/mod.ts b/client-web/source/preferences/mod.ts
index 04fae2c..8aefb0f 100644
--- a/client-web/source/preferences/mod.ts
+++ b/client-web/source/preferences/mod.ts
@@ -15,6 +15,7 @@ export interface PrefDecl<T> {
optional?: boolean,
hidden?: boolean
allow_url?: boolean
+ require_reload?: boolean,
}
type Type = "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
diff --git a/client-web/source/room.ts b/client-web/source/room.ts
index a685f1d..27d2327 100644
--- a/client-web/source/room.ts
+++ b/client-web/source/room.ts
@@ -20,7 +20,7 @@ export class Room {
public on_ready = () => { };
- constructor(public signaling: SignalingConnection) {
+ constructor(public signaling: SignalingConnection, public rtc_config: RTCConfiguration) {
this.signaling.control_handler = (a) => this.control_handler(a)
this.signaling.relay_handler = (a, b) => this.relay_handler(a, b)
}
diff --git a/client-web/source/user/remote.ts b/client-web/source/user/remote.ts
index bd89e0e..5e81cf7 100644
--- a/client-web/source/user/remote.ts
+++ b/client-web/source/user/remote.ts
@@ -7,7 +7,7 @@
import { RelayMessage } from "../../../common/packets.d.ts";
import { notify } from "../helper.ts";
-import { ROOM_CONTAINER, RTC_CONFIG } from "../index.ts"
+import { ROOM_CONTAINER } from "../index.ts"
import { log } from "../logger.ts"
import { PREFS } from "../preferences/mod.ts";
import { new_remote_resource, RemoteResource } from "../resource/mod.ts";
@@ -28,7 +28,7 @@ export class RemoteUser extends User {
room.remote_users.set(id, this)
log("usermodel", `added remote user: ${this.display_name}`)
- this.pc = new RTCPeerConnection(RTC_CONFIG)
+ this.pc = new RTCPeerConnection(room.rtc_config)
this.pc.onicecandidate = ev => {
if (!ev.candidate) return
room.signaling.send_relay({ ice_candidate: ev.candidate.toJSON() }, this.id)
diff --git a/server/Cargo.toml b/server/Cargo.toml
index 4a61294..22413a2 100644
--- a/server/Cargo.toml
+++ b/server/Cargo.toml
@@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"
[dependencies]
-warp = "0.3"
+warp = "0.3.3"
tokio = { version = "1.25", features = ["full"] }
log = "0.4"
env_logger = "0.10"
@@ -14,6 +14,7 @@ hyper = "0.14.24"
serde = { version = "1.0.152", features = ["derive"] }
serde_json = "1.0.93"
include_dir = "0.7.3"
+toml = "0.7.2"
[features]
default = []
diff --git a/server/src/assets.rs b/server/src/assets.rs
index 320a4e4..51b0025 100644
--- a/server/src/assets.rs
+++ b/server/src/assets.rs
@@ -2,7 +2,7 @@
#[macro_export]
macro_rules! s_file {
($path: literal, $content_type: literal) => {
- warp::fs::file($path)
+ warp::fs::file(concat!("../", $path))
};
}
@@ -10,7 +10,7 @@ macro_rules! s_file {
#[macro_export]
macro_rules! s_asset_dir {
() => {
- warp::fs::dir("client-web/public/assets")
+ warp::fs::dir("../client-web/public/assets")
};
}
diff --git a/server/src/config.rs b/server/src/config.rs
new file mode 100644
index 0000000..9d6213c
--- /dev/null
+++ b/server/src/config.rs
@@ -0,0 +1,20 @@
+use serde::{Deserialize, Serialize};
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub struct ClientConfig {
+ webrtc: ClientWebrtcConfig,
+ appearance: ClientAppearanceConfig,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub struct ClientWebrtcConfig {
+ stun: String,
+ turn: Option<String>,
+ turn_user: Option<String>,
+ turn_cred: Option<String>,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub struct ClientAppearanceConfig {
+ accent: Option<String>,
+}
diff --git a/server/src/main.rs b/server/src/main.rs
index 61c9ad1..8a0e342 100644
--- a/server/src/main.rs
+++ b/server/src/main.rs
@@ -4,9 +4,11 @@
Copyright (C) 2022 metamuffin <metamuffin@disroot.org>
*/
pub mod assets;
+pub mod config;
pub mod protocol;
pub mod room;
+use config::ClientConfig;
use hyper::{header, StatusCode};
use listenfd::ListenFd;
use log::{debug, error};
@@ -34,6 +36,10 @@ fn main() {
async fn run() {
env_logger::init_from_env("LOG");
+ let client_config: ClientConfig = toml::from_str(include_str!("../../config/client.toml"))
+ .expect("client configuration invalid");
+ let client_config_json = serde_json::to_string(&client_config).unwrap();
+
let rooms: _ = Rooms::default();
let rooms: _ = warp::any().map(move || rooms.clone());
@@ -51,6 +57,13 @@ async fn run() {
"client-web/public/assets/sw.js",
"application/javascript"
));
+ let client_config: _ = warp::path!("config.json").map(move || {
+ warp::reply::with_header(
+ client_config_json.clone(),
+ "content-type",
+ "application/json",
+ )
+ });
let favicon: _ = warp::path!("favicon.ico").map(|| "");
let old_format_redirect: _ = warp::path!("room" / String).map(|rsecret| {
reply::with_header(
@@ -65,6 +78,7 @@ async fn run() {
.or(room)
.or(index)
.or(signaling)
+ .or(client_config)
.or(favicon)
.or(sw_script)
.or(old_format_redirect)