Files
jitsi-meet/react/features/keyboard-shortcuts/middleware.ts
Hristo Terezov d9a0423687 fix(KbShortcuts): remove listeners on leave.
Currently we add keyboard listeners on conference join but never remove them. In the cases where we have multiple join events during a call (visitors promotion, breakout rooms), there are multiple keyboard handlers added and the shortcuts are executed multiple times on a single press.
2024-10-05 08:43:51 -05:00

53 lines
1.5 KiB
TypeScript

import { AnyAction } from 'redux';
import { IStore } from '../app/types';
import { CONFERENCE_JOINED, CONFERENCE_LEFT } from '../base/conference/actionTypes';
import { SET_CONFIG } from '../base/config/actionTypes';
import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
import { CAPTURE_EVENTS } from '../remote-control/actionTypes';
import {
disableKeyboardShortcuts,
disposeKeyboardShortcuts,
enableKeyboardShortcuts,
initKeyboardShortcuts
} from './actions';
MiddlewareRegistry.register((store: IStore) => (next: Function) => (action: AnyAction) => {
const { dispatch } = store;
switch (action.type) {
case CAPTURE_EVENTS:
if (action.isCapturingEvents) {
dispatch(disableKeyboardShortcuts());
} else {
dispatch(enableKeyboardShortcuts());
}
return next(action);
case SET_CONFIG: {
const result = next(action);
const state = store.getState();
const { disableShortcuts } = state['features/base/config'];
if (disableShortcuts !== undefined) {
if (disableShortcuts) {
dispatch(disableKeyboardShortcuts());
} else {
dispatch(enableKeyboardShortcuts());
}
}
return result;
}
case CONFERENCE_JOINED:
dispatch(initKeyboardShortcuts());
break;
case CONFERENCE_LEFT:
dispatch(disposeKeyboardShortcuts());
}
return next(action);
});