Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

fix(keyboard-shortcuts) fix PTT on keyboards which send repeated keys

Saúl Ibarra Corretgé74b02af31890
diff --git a/react/features/keyboard-shortcuts/actions.web.ts b/react/features/keyboard-shortcuts/actions.web.ts
index d34a9c78bd..50a05b4339 100644
--- a/react/features/keyboard-shortcuts/actions.web.ts
+++ b/react/features/keyboard-shortcuts/actions.web.ts
@@ -41,9 +41,7 @@ const initGlobalKeyboardShortcuts = () =>
helpCharacter: 'SPACE',
helpDescription: 'keyboardShortcuts.pushToTalk',
handler: () => {
- sendAnalytics(createShortcutEvent('push.to.talk', ACTION_SHORTCUT_RELEASED));
- logger.log('Talk shortcut released');
- APP.conference.muteAudio(true);
+ // Handled directly on the global handler.
}
}));
@@ -82,7 +80,10 @@ export const initKeyboardShortcuts = () =>
(dispatch: IStore['dispatch'], getState: IStore['getState']) => {
dispatch(initGlobalKeyboardShortcuts());
- window.onkeyup = (e: KeyboardEvent) => {
+ const pttDelay = 50;
+ let pttTimeout: number | undefined;
+
+ window.addEventListener('keyup', (e: KeyboardEvent) => {
const state = getState();
const enabled = areKeyboardShortcutsEnabled(state);
const shortcuts = getKeyboardShortcuts(state);
@@ -93,12 +94,21 @@ export const initKeyboardShortcuts = () =>
const key = getKeyboardKey(e).toUpperCase();
+ if (key === ' ') {
+ clearTimeout(pttTimeout);
+ pttTimeout = window.setTimeout(() => {
+ sendAnalytics(createShortcutEvent('push.to.talk', ACTION_SHORTCUT_RELEASED));
+ logger.log('Talk shortcut released');
+ APP.conference.muteAudio(true);
+ }, pttDelay);
+ }
+
if (shortcuts.has(key)) {
shortcuts.get(key)?.handler(e);
}
- };
+ });
- window.onkeydown = (e: KeyboardEvent) => {
+ window.addEventListener('keydown', (e: KeyboardEvent) => {
const state = getState();
const enabled = areKeyboardShortcutsEnabled(state);
@@ -110,11 +120,12 @@ export const initKeyboardShortcuts = () =>
const key = getKeyboardKey(e).toUpperCase();
if (key === ' ' && !focusedElement) {
+ clearTimeout(pttTimeout);
sendAnalytics(createShortcutEvent('push.to.talk', ACTION_SHORTCUT_PRESSED));
logger.log('Talk shortcut pressed');
APP.conference.muteAudio(false);
} else if (key === 'ESCAPE') {
focusedElement?.blur();
}
- };
+ });
};