You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

reducer.ts 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import ReducerRegistry from '../base/redux/ReducerRegistry';
  2. import {
  3. _POTENTIAL_TRANSCRIBER_JOINED,
  4. _TRANSCRIBER_JOINED,
  5. _TRANSCRIBER_LEFT
  6. } from './actionTypes';
  7. /**
  8. * Returns initial state for transcribing feature part of Redux store.
  9. *
  10. * @returns {{
  11. * isTranscribing: boolean,
  12. * transcriberJID: null,
  13. * potentialTranscriberJIDs: Array
  14. * }}
  15. * @private
  16. */
  17. function _getInitialState() {
  18. return {
  19. /**
  20. * Indicates whether there is currently an active transcriber in the
  21. * room.
  22. *
  23. * @type {boolean}
  24. */
  25. isTranscribing: false,
  26. /**
  27. * The JID of the active transcriber.
  28. *
  29. * @type { string }
  30. */
  31. transcriberJID: null,
  32. /**
  33. * A list containing potential JID's of transcriber participants.
  34. *
  35. * @type { Array }
  36. */
  37. potentialTranscriberJIDs: []
  38. };
  39. }
  40. export interface ITranscribingState {
  41. isTranscribing: boolean;
  42. potentialTranscriberJIDs: string[];
  43. transcriberJID?: string | null;
  44. }
  45. /**
  46. * Reduces the Redux actions of the feature features/transcribing.
  47. */
  48. ReducerRegistry.register<ITranscribingState>('features/transcribing',
  49. (state = _getInitialState(), action): ITranscribingState => {
  50. switch (action.type) {
  51. case _TRANSCRIBER_JOINED:
  52. return {
  53. ...state,
  54. isTranscribing: true,
  55. transcriberJID: action.transcriberJID
  56. };
  57. case _TRANSCRIBER_LEFT:
  58. return {
  59. ...state,
  60. isTranscribing: false,
  61. transcriberJID: undefined,
  62. potentialTranscriberJIDs: []
  63. };
  64. case _POTENTIAL_TRANSCRIBER_JOINED:
  65. return {
  66. ...state,
  67. potentialTranscriberJIDs: [ action.transcriberJID, ...state.potentialTranscriberJIDs ]
  68. };
  69. default:
  70. return state;
  71. }
  72. });