Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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