"Fossies" - the Fresh Open Source Software Archive

Member "jitsi-meet-7555/react/features/base/tracks/reducer.ts" (28 Sep 2023, 4310 Bytes) of package /linux/misc/jitsi-meet-7555.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 { AnyAction } from 'redux';
    2 
    3 import { PARTICIPANT_ID_CHANGED } from '../participants/actionTypes';
    4 import ReducerRegistry from '../redux/ReducerRegistry';
    5 import { set } from '../redux/functions';
    6 
    7 import {
    8     SET_NO_SRC_DATA_NOTIFICATION_UID,
    9     TRACK_ADDED,
   10     TRACK_CREATE_CANCELED,
   11     TRACK_CREATE_ERROR,
   12     TRACK_NO_DATA_FROM_SOURCE,
   13     TRACK_OWNER_CHANGED,
   14     TRACK_REMOVED,
   15     TRACK_UPDATED,
   16     TRACK_WILL_CREATE
   17 } from './actionTypes';
   18 import { ITrack } from './types';
   19 
   20 /**
   21  * Reducer function for a single track.
   22  *
   23  * @param {Track|undefined} state - Track to be modified.
   24  * @param {Object} action - Action object.
   25  * @param {string} action.type - Type of action.
   26  * @param {string} action.name - Name of last media event.
   27  * @param {string} action.newValue - New participant ID value (in this
   28  * particular case).
   29  * @param {string} action.oldValue - Old participant ID value (in this
   30  * particular case).
   31  * @param {Track} action.track - Information about track to be changed.
   32  * @param {Participant} action.participant - Information about participant.
   33  * @returns {Track|undefined}
   34  */
   35 function track(state: ITrack, action: AnyAction) {
   36     switch (action.type) {
   37     case PARTICIPANT_ID_CHANGED:
   38         if (state.participantId === action.oldValue) {
   39             return {
   40                 ...state,
   41                 participantId: action.newValue
   42             };
   43         }
   44         break;
   45 
   46     case TRACK_OWNER_CHANGED: {
   47         const t = action.track;
   48 
   49         if (state.jitsiTrack === t.jitsiTrack) {
   50             return {
   51                 ...state,
   52                 participantId: t.participantId
   53             };
   54         }
   55         break;
   56     }
   57 
   58     case TRACK_UPDATED: {
   59         const t = action.track;
   60 
   61         if (state.jitsiTrack === t.jitsiTrack) {
   62             // Make sure that there's an actual update in order to reduce the
   63             // risk of unnecessary React Component renders.
   64             for (const p in t) {
   65                 // @ts-ignore
   66                 if (state[p] !== t[p]) {
   67                     // There's an actual update.
   68                     return {
   69                         ...state,
   70                         ...t
   71                     };
   72                 }
   73             }
   74         }
   75         break;
   76     }
   77 
   78     case TRACK_NO_DATA_FROM_SOURCE: {
   79         const t = action.track;
   80 
   81         if (state.jitsiTrack === t.jitsiTrack) {
   82             const isReceivingData = t.jitsiTrack.isReceivingData();
   83 
   84             if (state.isReceivingData !== isReceivingData) {
   85                 return {
   86                     ...state,
   87                     isReceivingData
   88                 };
   89             }
   90         }
   91         break;
   92     }
   93     }
   94 
   95     return state;
   96 }
   97 
   98 export type ITracksState = ITrack[];
   99 
  100 /**
  101  * Listen for actions that mutate (e.g. Add, remove) local and remote tracks.
  102  */
  103 ReducerRegistry.register<ITracksState>('features/base/tracks', (state = [], action): ITracksState => {
  104     switch (action.type) {
  105     case PARTICIPANT_ID_CHANGED:
  106     case TRACK_NO_DATA_FROM_SOURCE:
  107     case TRACK_OWNER_CHANGED:
  108     case TRACK_UPDATED:
  109         return state.map((t: ITrack) => track(t, action));
  110     case TRACK_ADDED: {
  111         let withoutTrackStub = state;
  112 
  113         if (action.track.local) {
  114             withoutTrackStub
  115                 = state.filter(
  116                     (t: ITrack) => !t.local || t.mediaType !== action.track.mediaType);
  117         }
  118 
  119         return [ ...withoutTrackStub, action.track ];
  120     }
  121 
  122     case TRACK_CREATE_CANCELED:
  123     case TRACK_CREATE_ERROR: {
  124         return state.filter((t: ITrack) => !t.local || t.mediaType !== action.trackType);
  125     }
  126 
  127     case TRACK_REMOVED:
  128         return state.filter((t: ITrack) => t.jitsiTrack !== action.track.jitsiTrack);
  129 
  130     case TRACK_WILL_CREATE:
  131         return [ ...state, action.track ];
  132 
  133     default:
  134         return state;
  135     }
  136 });
  137 
  138 export interface INoSrcDataState {
  139     noSrcDataNotificationUid?: string | number;
  140 }
  141 
  142 /**
  143  * Listen for actions that mutate the no-src-data state, like the current notification id.
  144  */
  145 ReducerRegistry.register<INoSrcDataState>('features/base/no-src-data', (state = {}, action): INoSrcDataState => {
  146     switch (action.type) {
  147     case SET_NO_SRC_DATA_NOTIFICATION_UID:
  148         return set(state, 'noSrcDataNotificationUid', action.uid);
  149 
  150     default:
  151         return state;
  152     }
  153 });
  154