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.js 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // @flow
  2. import { CONFERENCE_JOINED, CONFERENCE_LEFT, SET_PASSWORD } from '../base/conference';
  3. import { ReducerRegistry } from '../base/redux';
  4. import {
  5. KNOCKING_PARTICIPANT_ARRIVED_OR_UPDATED,
  6. KNOCKING_PARTICIPANT_LEFT,
  7. SET_KNOCKING_STATE,
  8. SET_LOBBY_MODE_ENABLED,
  9. SET_PASSWORD_JOIN_FAILED
  10. } from './actionTypes';
  11. const DEFAULT_STATE = {
  12. knocking: false,
  13. knockingParticipants: [],
  14. lobbyEnabled: false,
  15. passwordJoinFailed: false
  16. };
  17. /**
  18. * Reduces redux actions which affect the display of notifications.
  19. *
  20. * @param {Object} state - The current redux state.
  21. * @param {Object} action - The redux action to reduce.
  22. * @returns {Object} The next redux state which is the result of reducing the
  23. * specified {@code action}.
  24. */
  25. ReducerRegistry.register('features/lobby', (state = DEFAULT_STATE, action) => {
  26. switch (action.type) {
  27. case CONFERENCE_JOINED:
  28. case CONFERENCE_LEFT:
  29. return {
  30. ...state,
  31. knocking: false,
  32. passwordJoinFailed: false
  33. };
  34. case KNOCKING_PARTICIPANT_ARRIVED_OR_UPDATED:
  35. return _knockingParticipantArrivedOrUpdated(action.participant, state);
  36. case KNOCKING_PARTICIPANT_LEFT:
  37. return {
  38. ...state,
  39. knockingParticipants: state.knockingParticipants.filter(p => p.id !== action.id)
  40. };
  41. case SET_KNOCKING_STATE:
  42. return {
  43. ...state,
  44. knocking: action.knocking,
  45. passwordJoinFailed: false
  46. };
  47. case SET_LOBBY_MODE_ENABLED:
  48. return {
  49. ...state,
  50. lobbyEnabled: action.enabled
  51. };
  52. case SET_PASSWORD:
  53. return {
  54. ...state,
  55. passwordJoinFailed: false
  56. };
  57. case SET_PASSWORD_JOIN_FAILED:
  58. return {
  59. ...state,
  60. passwordJoinFailed: action.failed
  61. };
  62. }
  63. return state;
  64. });
  65. /**
  66. * Stores or updates a knocking participant.
  67. *
  68. * @param {Object} participant - The arrived or updated knocking participant.
  69. * @param {Object} state - The current Redux state of the feature.
  70. * @returns {Object}
  71. */
  72. function _knockingParticipantArrivedOrUpdated(participant, state) {
  73. let existingParticipant = state.knockingParticipants.find(p => p.id === participant.id);
  74. existingParticipant = {
  75. ...existingParticipant,
  76. ...participant
  77. };
  78. return {
  79. ...state,
  80. knockingParticipants: [
  81. ...state.knockingParticipants.filter(p => p.id !== participant.id),
  82. existingParticipant
  83. ]
  84. };
  85. }