From f85d40d8c6cc2f3b58d1e0ea7f0382db88fffd4e Mon Sep 17 00:00:00 2001 From: metamuffin Date: Tue, 17 Jan 2023 22:28:35 +0100 Subject: refer to room name as secret instead --- client-web/source/preferences/mod.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'client-web/source/preferences') diff --git a/client-web/source/preferences/mod.ts b/client-web/source/preferences/mod.ts index 5de73eb..04fae2c 100644 --- a/client-web/source/preferences/mod.ts +++ b/client-web/source/preferences/mod.ts @@ -85,19 +85,19 @@ export function generate_section(): string { PREFS_EXPLICIT[key as unknown as keyof typeof PREFS_EXPLICIT] ))) } - return load_params().rname + "?" + section.join("&") + return load_params().rsecret + "?" + section.join("&") } -export function load_params(): { raw_params: { [key: string]: string }, rname: string } { +export function load_params(): { raw_params: { [key: string]: string }, rsecret: string } { const raw_params: Record = {} - const [rname, param_str] = window.location.hash.substring(1).split("?") - if (!param_str) return { rname, raw_params: {} } + const [rsecret, param_str] = window.location.hash.substring(1).split("?") + if (!param_str) return { rsecret, raw_params: {} } for (const kv of param_str.split("&")) { const [key, value] = kv.split("=") if (key == "prototype") continue raw_params[decodeURIComponent(key)] = decodeURIComponent(value) } - return { raw_params, rname } + return { raw_params, rsecret } } function get_param(ty: string, key: string): T | undefined { -- cgit v1.2.3-70-g09d2 From 630cd2b82887da49cacb2deb032c6a51b3c2faf7 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Tue, 21 Feb 2023 15:12:38 +0100 Subject: server-side client configuration --- .gitignore | 2 ++ Cargo.lock | 48 +++++++++++++++++++++++++++++++++-- client-web/source/index.ts | 38 +++++++++++++++++---------- client-web/source/preferences/decl.ts | 6 +++++ client-web/source/preferences/mod.ts | 1 + client-web/source/room.ts | 2 +- client-web/source/user/remote.ts | 4 +-- server/Cargo.toml | 3 ++- server/src/assets.rs | 4 +-- server/src/config.rs | 20 +++++++++++++++ server/src/main.rs | 14 ++++++++++ 11 files changed, 120 insertions(+), 22 deletions(-) create mode 100644 server/src/config.rs (limited to 'client-web/source/preferences') 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]] @@ -3421,6 +3422,15 @@ dependencies = [ "syn", ] +[[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" @@ -3887,12 +3897,33 @@ dependencies = [ "tracing", ] +[[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" @@ -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 { 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, + turn_user: Option, + turn_cred: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ClientAppearanceConfig { + accent: Option, +} 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 */ 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) -- cgit v1.2.3-70-g09d2 From e31c48f5a9cfe6fd8988b83b17e00538fa69d6d3 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Tue, 21 Feb 2023 15:52:06 +0100 Subject: server-side appearance config --- client-web/source/index.ts | 16 +++++++++++++++- client-web/source/preferences/decl.ts | 6 ------ client-web/source/protocol/mod.ts | 1 - config/client.example.toml | 16 ++++++++++++++++ server/src/config.rs | 8 ++++++-- 5 files changed, 37 insertions(+), 10 deletions(-) create mode 100644 config/client.example.toml (limited to 'client-web/source/preferences') diff --git a/client-web/source/index.ts b/client-web/source/index.ts index 4590625..83f1dfc 100644 --- a/client-web/source/index.ts +++ b/client-web/source/index.ts @@ -18,7 +18,13 @@ export const VERSION = "0.1.12" export const ROOM_CONTAINER = esection({ class: "room", aria_label: "user list" }) export interface ClientConfig { - appearance: { accent: string } + appearance?: { + accent: string + accent_dark: string + accent_light: string + background: string + background_dark: string + } webrtc: { stun: string, turn?: string, @@ -73,6 +79,14 @@ export async function main() { username: config.webrtc.turn_user, }] } + if (config.appearance) { + document.body.style.setProperty("--ac", config.appearance.accent) + document.body.style.setProperty("--ac-dark", config.appearance.accent_dark) + document.body.style.setProperty("--ac-light", config.appearance.accent_light) + document.body.style.setProperty("--bg", config.appearance.background) + document.body.style.setProperty("--bg-dark", config.appearance.background_dark) + + } r = new Room(conn, rtc_config) diff --git a/client-web/source/preferences/decl.ts b/client-web/source/preferences/decl.ts index 68cb9ee..f3f8e84 100644 --- a/client-web/source/preferences/decl.ts +++ b/client-web/source/preferences/decl.ts @@ -18,13 +18,7 @@ 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/protocol/mod.ts b/client-web/source/protocol/mod.ts index 3674c08..6d49a17 100644 --- a/client-web/source/protocol/mod.ts +++ b/client-web/source/protocol/mod.ts @@ -33,7 +33,6 @@ export class SignalingConnection { this.on_open() r() }) - log("ws", "connection opened") return this } diff --git a/config/client.example.toml b/config/client.example.toml new file mode 100644 index 0000000..39e942a --- /dev/null +++ b/config/client.example.toml @@ -0,0 +1,16 @@ + +[appearance] +accent = "#5e3f84" +accent_dark = "#2d0d52" +accent_light = "#7c43bd" +background = "#151315" +background_dark = "#070707" + +# If you decide to host your own TURN server, adjust this. +[webrtc] +stun = "stun:meet.metamuffin.org:16900" +# turn = "turn:meet.metamuffin.org:16900" +## Set the default turn credentials. +## If not provided, TURN is disabled by default and requires manual activation via password (TODO). +# turn_user = "keksmeet" +# turn_cred = "thatsmypassword" diff --git a/server/src/config.rs b/server/src/config.rs index 9d6213c..6dd380f 100644 --- a/server/src/config.rs +++ b/server/src/config.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct ClientConfig { webrtc: ClientWebrtcConfig, - appearance: ClientAppearanceConfig, + appearance: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -16,5 +16,9 @@ pub struct ClientWebrtcConfig { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct ClientAppearanceConfig { - accent: Option, + accent: String, + accent_light: String, + accent_dark: String, + background: String, + background_dark: String, } -- cgit v1.2.3-70-g09d2