"Fossies" - the Fresh Open Source Software Archive 
Member "jitsi-meet-7561/react/features/speaker-stats/reducer.ts" (29 Sep 2023, 5368 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 _ from 'lodash';
2
3 import ReducerRegistry from '../base/redux/ReducerRegistry';
4 import { FaceLandmarks } from '../face-landmarks/types';
5
6 import {
7 ADD_TO_OFFSET,
8 ADD_TO_OFFSET_LEFT,
9 ADD_TO_OFFSET_RIGHT,
10 INIT_REORDER_STATS,
11 INIT_SEARCH,
12 RESET_SEARCH_CRITERIA,
13 SET_PANNING,
14 SET_TIMELINE_BOUNDARY,
15 TOGGLE_FACE_EXPRESSIONS,
16 UPDATE_SORTED_SPEAKER_STATS_IDS,
17 UPDATE_STATS
18 } from './actionTypes';
19
20 /**
21 * The initial state of the feature speaker-stats.
22 *
23 * @type {Object}
24 */
25 const INITIAL_STATE = {
26 stats: {},
27 isOpen: false,
28 pendingReorder: true,
29 criteria: null,
30 showFaceExpressions: false,
31 sortedSpeakerStatsIds: [],
32 timelineBoundary: null,
33 offsetLeft: 0,
34 offsetRight: 0,
35 timelinePanning: {
36 active: false,
37 x: 0
38 }
39 };
40
41 export interface ISpeaker {
42 addFaceLandmarks: (faceLandmarks: FaceLandmarks) => void;
43 displayName?: string;
44 getDisplayName: () => string;
45 getFaceLandmarks: () => FaceLandmarks[];
46 getTotalDominantSpeakerTime: () => number;
47 getUserId: () => string;
48 hasLeft: () => boolean;
49 hidden?: boolean;
50 isDominantSpeaker: () => boolean;
51 isLocalStats: () => boolean;
52 isModerator?: boolean;
53 markAsHasLeft: () => boolean;
54 setDisplayName: (newName: string) => void;
55 setDominantSpeaker: (isNowDominantSpeaker: boolean, silence: boolean) => void;
56 setFaceLandmarks: (faceLandmarks: FaceLandmarks[]) => void;
57 }
58
59 export interface ISpeakerStats {
60 [key: string]: ISpeaker;
61 }
62
63 export interface ISpeakerStatsState {
64 criteria: string | null;
65 isOpen: boolean;
66 offsetLeft: number;
67 offsetRight: number;
68 pendingReorder: boolean;
69 showFaceExpressions: boolean;
70 sortedSpeakerStatsIds: Array<string>;
71 stats: ISpeakerStats;
72 timelineBoundary: number | null;
73 timelinePanning: {
74 active: boolean;
75 x: number;
76 };
77 }
78
79 ReducerRegistry.register<ISpeakerStatsState>('features/speaker-stats',
80 (state = INITIAL_STATE, action): ISpeakerStatsState => {
81 switch (action.type) {
82 case INIT_SEARCH:
83 return _updateCriteria(state, action);
84 case UPDATE_STATS:
85 return _updateStats(state, action);
86 case INIT_REORDER_STATS:
87 return _initReorderStats(state);
88 case UPDATE_SORTED_SPEAKER_STATS_IDS:
89 return _updateSortedSpeakerStats(state, action);
90 case RESET_SEARCH_CRITERIA:
91 return _updateCriteria(state, { criteria: null });
92 case TOGGLE_FACE_EXPRESSIONS: {
93 return {
94 ...state,
95 showFaceExpressions: !state.showFaceExpressions
96 };
97 }
98 case ADD_TO_OFFSET: {
99 return {
100 ...state,
101 offsetLeft: state.offsetLeft + action.value,
102 offsetRight: state.offsetRight + action.value
103 };
104 }
105 case ADD_TO_OFFSET_RIGHT: {
106 return {
107 ...state,
108 offsetRight: state.offsetRight + action.value
109 };
110 }
111 case ADD_TO_OFFSET_LEFT: {
112 return {
113 ...state,
114 offsetLeft: state.offsetLeft + action.value
115 };
116 }
117 case SET_TIMELINE_BOUNDARY: {
118 return {
119 ...state,
120 timelineBoundary: action.boundary
121 };
122 }
123 case SET_PANNING: {
124 return {
125 ...state,
126 timelinePanning: action.panning
127 };
128 }
129 }
130
131 return state;
132 });
133
134 /**
135 * Reduces a specific Redux action INIT_SEARCH of the feature
136 * speaker-stats.
137 *
138 * @param {Object} state - The Redux state of the feature speaker-stats.
139 * @param {Action} action - The Redux action INIT_SEARCH to reduce.
140 * @private
141 * @returns {Object} The new state after the reduction of the specified action.
142 */
143 function _updateCriteria(state: ISpeakerStatsState, { criteria }: { criteria: string | null; }) {
144 return _.assign(
145 {},
146 state,
147 { criteria }
148 );
149 }
150
151 /**
152 * Reduces a specific Redux action UPDATE_STATS of the feature speaker-stats.
153 *
154 * @param {Object} state - The Redux state of the feature speaker-stats.
155 * @param {Action} action - The Redux action UPDATE_STATS to reduce.
156 * @private
157 * @returns {Object} - The new state after the reduction of the specified action.
158 */
159 function _updateStats(state: ISpeakerStatsState, { stats }: { stats: any; }) {
160 return {
161 ...state,
162 stats
163 };
164 }
165
166 /**
167 * Reduces a specific Redux action UPDATE_SORTED_SPEAKER_STATS_IDS of the feature speaker-stats.
168 *
169 * @param {Object} state - The Redux state of the feature speaker-stats.
170 * @param {Action} action - The Redux action UPDATE_SORTED_SPEAKER_STATS_IDS to reduce.
171 * @private
172 * @returns {Object} The new state after the reduction of the specified action.
173 */
174 function _updateSortedSpeakerStats(state: ISpeakerStatsState, { participantIds }: { participantIds: Array<string>; }) {
175 return {
176 ...state,
177 sortedSpeakerStatsIds: participantIds,
178 pendingReorder: false
179 };
180 }
181
182 /**
183 * Reduces a specific Redux action INIT_REORDER_STATS of the feature
184 * speaker-stats.
185 *
186 * @param {Object} state - The Redux state of the feature speaker-stats.
187 * @private
188 * @returns {Object} The new state after the reduction of the specified action.
189 */
190 function _initReorderStats(state: ISpeakerStatsState) {
191 return _.assign(
192 {},
193 state,
194 { pendingReorder: true }
195 );
196 }