"Fossies" - the Fresh Open Source Software Archive

Member "jitsi-meet-7561/react/features/authentication/reducer.ts" (29 Sep 2023, 2759 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 PersistenceRegistry from '../base/redux/PersistenceRegistry';
    2 import ReducerRegistry from '../base/redux/ReducerRegistry';
    3 import { assign } from '../base/redux/functions';
    4 
    5 import {
    6     CANCEL_LOGIN,
    7     SET_TOKEN_AUTH_URL_SUCCESS,
    8     STOP_WAIT_FOR_OWNER,
    9     UPGRADE_ROLE_FINISHED,
   10     UPGRADE_ROLE_STARTED,
   11     WAIT_FOR_OWNER
   12 } from './actionTypes';
   13 
   14 export interface IAuthenticationState {
   15     error?: Object | undefined;
   16     progress?: number | undefined;
   17     thenableWithCancel?: {
   18         cancel: Function;
   19     };
   20     tokenAuthUrlSuccessful?: boolean;
   21     waitForOwnerTimeoutID?: number;
   22 }
   23 
   24 /**
   25  * Sets up the persistence of the feature {@code authentication}.
   26  */
   27 PersistenceRegistry.register('features/authentication', {
   28     tokenAuthUrlSuccessful: true
   29 });
   30 
   31 /**
   32  * Listens for actions which change the state of the authentication feature.
   33  *
   34  * @param {Object} state - The Redux state of the authentication feature.
   35  * @param {Object} action - Action object.
   36  * @param {string} action.type - Type of action.
   37  * @returns {Object}
   38  */
   39 ReducerRegistry.register<IAuthenticationState>('features/authentication',
   40 (state = {}, action): IAuthenticationState => {
   41     switch (action.type) {
   42     case CANCEL_LOGIN:
   43         return assign(state, {
   44             error: undefined,
   45             progress: undefined,
   46             thenableWithCancel: undefined
   47         });
   48     case SET_TOKEN_AUTH_URL_SUCCESS:
   49         return assign(state, {
   50             tokenAuthUrlSuccessful: action.value
   51         });
   52 
   53     case STOP_WAIT_FOR_OWNER:
   54         return assign(state, {
   55             error: undefined,
   56             waitForOwnerTimeoutID: undefined
   57         });
   58 
   59     case UPGRADE_ROLE_FINISHED: {
   60         let { thenableWithCancel } = action;
   61 
   62         if (state.thenableWithCancel === thenableWithCancel) {
   63             const { error, progress } = action;
   64 
   65             // An error interrupts the process of authenticating and upgrading
   66             // the role of the local participant/user i.e. the process is no
   67             // more. Obviously, the process seizes to exist also when it does
   68             // its whole job.
   69             if (error || progress === 1) {
   70                 thenableWithCancel = undefined;
   71             }
   72 
   73             return assign(state, {
   74                 error,
   75                 progress: progress || undefined,
   76                 thenableWithCancel
   77             });
   78         }
   79         break;
   80     }
   81 
   82     case UPGRADE_ROLE_STARTED:
   83         return assign(state, {
   84             error: undefined,
   85             progress: undefined,
   86             thenableWithCancel: action.thenableWithCancel
   87         });
   88 
   89     case WAIT_FOR_OWNER:
   90         return assign(state, {
   91             waitForOwnerTimeoutID: action.waitForOwnerTimeoutID
   92         });
   93     }
   94 
   95     return state;
   96 });