summaryrefslogtreecommitdiff
path: root/client-web/source/keybinds.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client-web/source/keybinds.ts')
-rw-r--r--client-web/source/keybinds.ts27
1 files changed, 27 insertions, 0 deletions
diff --git a/client-web/source/keybinds.ts b/client-web/source/keybinds.ts
new file mode 100644
index 0000000..311b55a
--- /dev/null
+++ b/client-web/source/keybinds.ts
@@ -0,0 +1,27 @@
+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") room.local_user.publish_track(room.local_user.create_mic_track())
+ if (ev.code == "KeyC") room.local_user.publish_track(room.local_user.create_camera_track())
+ if (ev.code == "KeyS") room.local_user.publish_track(room.local_user.create_screencast_track())
+ }
+ command_mode = false
+ })
+}