"Fossies" - the Fresh Open Source Software Archive

Member "jitsi-meet-7561/react/features/base/user-interaction/middleware.ts" (29 Sep 2023, 2268 Bytes) of package /linux/misc/jitsi-meet-7561.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) TypeScript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 import { IStore } from '../../app/types';
    2 import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../app/actionTypes';
    3 import MiddlewareRegistry from '../redux/MiddlewareRegistry';
    4 
    5 import { USER_INTERACTION_RECEIVED } from './actionTypes';
    6 
    7 /**
    8  * Reference to any callback that has been created to be invoked on user
    9  * interaction.
   10  *
   11  * @type {Function|null}
   12  */
   13 let userInteractionListener: Function | null = null;
   14 
   15 /**
   16  * Implements the entry point of the middleware of the feature base/user-interaction.
   17  *
   18  * @param {Store} store - The redux store.
   19  * @returns {Function}
   20  */
   21 MiddlewareRegistry.register(store => next => action => {
   22     switch (action.type) {
   23     case APP_WILL_MOUNT:
   24         _startListeningForUserInteraction(store);
   25         break;
   26 
   27     case APP_WILL_UNMOUNT:
   28         _stopListeningForUserInteraction();
   29         break;
   30     }
   31 
   32     return next(action);
   33 });
   34 
   35 /**
   36  * Callback invoked when the user interacts with the page.
   37  *
   38  * @param {Function} dispatch - The redux dispatch function.
   39  * @param {Object} event - The DOM event for a user interacting with the page.
   40  * @private
   41  * @returns {void}
   42  */
   43 function _onUserInteractionReceived(dispatch: IStore['dispatch'], event: any) {
   44     if (event.isTrusted) {
   45         dispatch({
   46             type: USER_INTERACTION_RECEIVED
   47         });
   48 
   49         _stopListeningForUserInteraction();
   50     }
   51 }
   52 
   53 /**
   54  * Registers listeners to notify redux of any user interaction with the page.
   55  *
   56  * @param {Object} store - The redux store.
   57  * @private
   58  * @returns {void}
   59  */
   60 function _startListeningForUserInteraction({ dispatch }: { dispatch: IStore['dispatch']; }) {
   61     _stopListeningForUserInteraction();
   62 
   63     userInteractionListener = _onUserInteractionReceived.bind(null, dispatch);
   64 
   65     // @ts-ignore
   66     window.addEventListener('mousedown', userInteractionListener);
   67 
   68     // @ts-ignore
   69     window.addEventListener('keydown', userInteractionListener);
   70 }
   71 
   72 /**
   73  * De-registers listeners for user interaction with the page.
   74  *
   75  * @private
   76  * @returns {void}
   77  */
   78 function _stopListeningForUserInteraction() {
   79     // @ts-ignore
   80     window.removeEventListener('mousedown', userInteractionListener);
   81 
   82     // @ts-ignore
   83     window.removeEventListener('keydown', userInteractionListener);
   84 
   85     userInteractionListener = null;
   86 }