Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

reducer.js 2.7KB

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