aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client-web/source/preferences/decl.ts4
-rw-r--r--client-web/source/preferences/mod.ts54
-rw-r--r--client-web/source/preferences/ui.ts10
-rw-r--r--client-web/source/protocol/crypto.ts1
-rw-r--r--readme.md8
5 files changed, 45 insertions, 32 deletions
diff --git a/client-web/source/preferences/decl.ts b/client-web/source/preferences/decl.ts
index cb46f3f..d641915 100644
--- a/client-web/source/preferences/decl.ts
+++ b/client-web/source/preferences/decl.ts
@@ -10,8 +10,8 @@ const string = "", bool = false, number = 0; // example types for ts
const optional = <T>(a: T): T | undefined => a
export const PREF_DECLS = {
- username: { type: string, default: "guest-" + hex_id(), description: "Username" },
- warn_redirect: { type: bool, hidden: true, default: false, description: "Internal option that is set by a server redirect." },
+ 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" },
/* MEDIA */
diff --git a/client-web/source/preferences/mod.ts b/client-web/source/preferences/mod.ts
index 4a2d8b9..08ecaea 100644
--- a/client-web/source/preferences/mod.ts
+++ b/client-web/source/preferences/mod.ts
@@ -9,6 +9,7 @@ export interface PrefDecl<T> {
possible_values?: T[]
optional?: boolean,
hidden?: boolean
+ allow_url?: boolean
}
type Type = "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
@@ -36,7 +37,15 @@ export function register_prefs<T extends Record<string, PrefDecl<unknown>>>(ds:
for (const key in ds) {
const d = ds[key];
const type = typeof d.type;
+
let value = get_param(type, key)
+ if (value !== undefined && !d.allow_url) setTimeout(() => { // defer log call because this is executed early
+ log({ scope: "*", warn: true }, `pref key ${JSON.stringify(key)} is not allowed in url`)
+ })
+ if (!d.allow_url) value = undefined
+ const j = localStorage.getItem(key)
+ if (j) value ??= JSON.parse(j)
+
if (value !== undefined) explicit[key] = value
value ??= d.default;
if (d.possible_values) if (!d.possible_values.includes(value)) value = d.default
@@ -45,6 +54,7 @@ export function register_prefs<T extends Record<string, PrefDecl<unknown>>>(ds:
return { prefs, explicit }
}
+window["change_pref" as "onbeforeprint"] = change_pref as () => void // TODO ugly
export function change_pref<T extends keyof typeof PREFS>(key: T, value: typeof PREFS[T]) {
log("*", `pref changed: ${key}`)
PREFS[key] = value
@@ -52,8 +62,17 @@ export function change_pref<T extends keyof typeof PREFS>(key: T, value: typeof
PREFS_EXPLICIT[key] = value
else delete PREFS_EXPLICIT[key]
pref_change_handlers.get(key)?.forEach(h => h())
- window.location.hash = "#" + generate_section()
+ // window.location.hash = "#" + generate_section()
+ localStorage.setItem(key, JSON.stringify(value))
+}
+
+function param_to_string<T>(p: T): string {
+ if (typeof p == "string") return p
+ else if (typeof p == "boolean") return JSON.stringify(p)
+ else if (typeof p == "number") return JSON.stringify(p)
+ throw new Error("impossible");
}
+
export function generate_section(): string {
const section = []
for (const key in PREFS_EXPLICIT) {
@@ -76,27 +95,20 @@ export function load_params(): { raw_params: { [key: string]: string }, rname: s
return { raw_params, rname }
}
-function param_to_string<T>(p: T): string {
- if (typeof p == "string") return p
- else if (typeof p == "boolean") return JSON.stringify(p)
- else if (typeof p == "number") return JSON.stringify(p)
- throw new Error("impossible");
-}
-
function get_param<T>(ty: string, key: string): T | undefined {
const v = load_params().raw_params[key]
- if (v == undefined) return undefined
- if (ty == "string") return v as unknown as T
- else if (ty == "number") {
- const n = parseInt(v)
- if (!Number.isNaN(n)) return n as unknown as T
- console.warn("invalid number parameter");
- } else if (ty == "boolean") {
- if (v == "0" || v == "false" || v == "no") return false as unknown as T
- if (v == "1" || v == "true" || v == "yes") return true as unknown as T
- console.warn("invalid boolean parameter");
- } else {
- throw new Error("invalid param type");
+ if (v !== undefined) {
+ if (ty == "string") return v as unknown as T
+ else if (ty == "number") {
+ const n = parseInt(v)
+ if (!Number.isNaN(n)) return n as unknown as T
+ console.warn("invalid number parameter");
+ } else if (ty == "boolean") {
+ if (v == "0" || v == "false" || v == "no") return false as unknown as T
+ if (v == "1" || v == "true" || v == "yes") return true as unknown as T
+ console.warn("invalid boolean parameter");
+ } else {
+ throw new Error("invalid param type");
+ }
}
- return undefined
}
diff --git a/client-web/source/preferences/ui.ts b/client-web/source/preferences/ui.ts
index 72d7792..634d945 100644
--- a/client-web/source/preferences/ui.ts
+++ b/client-web/source/preferences/ui.ts
@@ -4,8 +4,6 @@ import { change_pref, on_pref_changed, PrefDecl, PREFS } from "./mod.ts";
export class PrefUi extends OverlayUi {
constructor() {
- console.log(PREFS);
-
const rows = Object.entries(PREF_DECLS as Record<string, PrefDecl<unknown>>).filter(e => !e[1].hidden).map(([key_, decl]) => {
const key = key_ as keyof typeof PREF_DECLS
const id = `pref-${key}`
@@ -77,14 +75,20 @@ export class PrefUi extends OverlayUi {
const label = elabel(decl.description ?? `[${key}]`, { id })
return etr({ class: "pref" }, etd({}, label), etd({}, use_opt_ ?? ""), etd({}, prim_control ?? ""))
})
+
const notification_perm = Notification.permission == "granted" ? ediv() : ediv({},
espan("For keks-meet to send notifications, it needs you to grant permission: "),
ebutton("Grant", { onclick: () => Notification.requestPermission() }),
)
+ const reset = ediv({},
+ espan("Want to clear all settings? Use this:"),
+ ebutton("RESET", { onclick: () => { if (confirm("really clear all preferences?")) { localStorage.clear(); window.location.reload() } } }),
+ )
+
const table = document.createElement("table")
table.append(...rows)
- super(ediv({ class: "prefs-overlay" }, notification_perm, ebr(), table))
+ super(ediv({ class: "prefs-overlay" }, notification_perm, reset, ebr(), table))
}
}
diff --git a/client-web/source/protocol/crypto.ts b/client-web/source/protocol/crypto.ts
index 76f48c0..da4590b 100644
--- a/client-web/source/protocol/crypto.ts
+++ b/client-web/source/protocol/crypto.ts
@@ -29,7 +29,6 @@ export async function crypto_seeded_key(seed: string): Promise<CryptoKey> {
false,
["encrypt", "decrypt"]
)
- console.log(key);
log("crypto", "ready")
return key
}
diff --git a/readme.md b/readme.md
index c634259..943b9a6 100644
--- a/readme.md
+++ b/readme.md
@@ -48,14 +48,14 @@ Because of a current compiler bug, the nightly rustc crashes during codegen - us
## Parameters
-Configuration parameters are added like query params but **after** the section. (e.g `/room#mymeeting?username=alice`)
+Some configuration parameters can be added like query params but **after** the section. (e.g `/room#mymeeting?username=alice`)
The page will not automatically reload if the section changes.
-Booleans can be either `1`, `true`, `yes` or their opposites.
+Booleans can be either `1`, `true`, `yes` or their opposites. I convenience function for changing params is also exported: `window.change_pref(key, value)`
| Option name | Type | Default | Description |
| -------------------------- | ------- | ----------- | -------------------------------------------------------------------- |
| `username` | string | `"guest-…"` | Username |
-| `warn_redirect` | boolean | `false` | Interal option that is set by a server redirect. |
+| `warn_redirect` | boolean | `false` | Internal option that is set by a server redirect. |
| `image_view_popup` | boolean | `true` | Open image in popup instead of new tab |
| `microphone_enabled` | boolean | `false` | Add one microphone track on startup |
| `screencast_enabled` | boolean | `false` | Add one screencast track on startup |
@@ -75,7 +75,6 @@ Booleans can be either `1`, `true`, `yes` or their opposites.
## Todo-List
- Optionally enable video streams
-- Settings menu
- Native client
- Prevent server from changing message sender
- Have a security professional look at the code
@@ -83,7 +82,6 @@ Booleans can be either `1`, `true`, `yes` or their opposites.
- Signing key for each user
- Built-in storage for known keys
- Relay RTC when there are a lot of clients
-- Mitigate security issues caused by `*_enabled` params
- Save permissions to locale storage
- Prevent join notification bypass by not identifying
- Dont use websocket to send images to not block anything else