summaryrefslogtreecommitdiff
path: root/client-web/source/keybinds.ts
blob: ad20d37625746c7324872ed6c7bf3376d0425d23 (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
import { Room } from "./room.ts"


export function setup_keybinds(room: Room) {
    let command_mode = false
    document.body.addEventListener("keydown", ev => {
        // TODO is there a proper solution?
        if (ev.target instanceof HTMLInputElement && !(ev.target.type == "button")) return
        if (ev.repeat) return
        if (ev.code == "Enter") {
            room.chat.shown = !room.chat.shown
            if (room.chat.shown) room.chat.focus()
            ev.preventDefault() // so focused buttons dont trigger
        }
        if (ev.code == "Space") {
            command_mode = true
            ev.preventDefault() // so focused buttons dont trigger
            return
        }
        if (command_mode) {
            if (ev.code == "KeyM" || ev.code == "KeyR") room.local_user.publish_track(room.local_user.create_mic_track())
            if (ev.code == "KeyS") room.local_user.publish_track(room.local_user.create_screencast_track())
            if (ev.code == "KeyC" && !ev.ctrlKey) room.local_user.publish_track(room.local_user.create_camera_track())
            if (ev.code == "KeyC" && ev.ctrlKey) room.local_user.tracks.forEach(t => t.end())
        }
        command_mode = false
    })
}