aboutsummaryrefslogtreecommitdiff
path: root/client-web/source/menu.ts
blob: 583f28b22491366a0b0356b9b418552ac38d6de9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
    This file is part of keks-meet (https://codeberg.org/metamuffin/keks-meet)
    which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
    Copyright (C) 2023 metamuffin <metamuffin@disroot.org>
*/
/// <reference lib="dom" />

import { e } from "./helper.ts"
import { VERSION } from "./index.ts"
import { ui_preferences } from "./preferences/ui.ts"
import { create_file_res } from "./resource/file.ts";
import { create_camera_res, create_mic_res, create_screencast_res } from "./resource/track.ts";
import { Room } from "./room.ts"
import { ui_room_watches } from "./room_watches.ts";

export function info_br() {
    const item = (name: string, cb: (() => void) | string) => {
        const p = document.createElement("p")
        const a = document.createElement("a")
        a.classList.add("menu-item")
        a.target = "_blank" // dont unload this meeting
        a.textContent = name
        if (typeof cb == "string") a.href = cb
        else a.addEventListener("click", cb), a.href = "#"
        p.append(a)
        return p
    }

    return e("footer", { class: "info-br" },
        e("p", { class: "version" }, `keks-meet ${VERSION}`),
        item("License", "https://codeberg.org/metamuffin/keks-meet/raw/branch/master/COPYING"),
        item("Source code", "https://codeberg.org/metamuffin/keks-meet"),
        item("Documentation", "https://codeberg.org/metamuffin/keks-meet/src/branch/master/readme.md"),
    )
}

export let chat_control: (s?: boolean) => void;

export function control_bar(room: Room, side_ui_container: HTMLElement): HTMLElement {
    const leave = e("button", { class: "leave", onclick() { window.location.href = "/" } }, "Leave")
    const chat = side_ui(side_ui_container, room.chat.element, "Chat")
    const prefs = side_ui(side_ui_container, ui_preferences(), "Settings")
    const rwatches = side_ui(side_ui_container, ui_room_watches(), "Known Rooms")
    const local_controls = [ //ediv({ class: "local-controls", aria_label: "local resources" },
        e("button", { onclick: () => room.local_user.await_add_resource(create_mic_res()) }, "Microphone"),
        e("button", { onclick: () => room.local_user.await_add_resource(create_camera_res()) }, "Camera"),
        e("button", { onclick: () => room.local_user.await_add_resource(create_screencast_res()) }, "Screen"),
        e("button", { onclick: () => room.local_user.await_add_resource(create_file_res()) }, "File"),
    ]
    chat_control = chat.set_state;
    return e("nav", { class: "control-bar" }, leave, chat.el, prefs.el, rwatches.el, ...local_controls)
}

export interface SideUI { el: HTMLElement, set_state: (s?: boolean) => void }
export function side_ui(container: HTMLElement, content: HTMLElement, label: string): SideUI {
    // TODO: close other side uis
    const tray = e("div", { class: "side-tray" }, content)
    const checkbox = e("input", {
        type: "checkbox",
        onchange: () => {
            if (checkbox.checked) {
                tray.classList.add("animate-in")
                container.appendChild(tray)
            } else {
                tray.classList.remove("animate-in")
                tray.classList.add("animate-out")
                setTimeout(() => { // TODO breaks if ui is being enabled while timeout is active 
                    tray.classList.remove("animate-out")
                    container.removeChild(tray)
                }, 400)
            }
        }
    })
    return {
        el: e("label", { class: "side-ui-control" }, label, checkbox),
        set_state(s) { checkbox.checked = s ?? !checkbox.checked; if (checkbox.onchange) checkbox.onchange(undefined as unknown as Event) }
    }
}