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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { ReducerRegistry, setStateProperty } from '../redux';
  2. import {
  3. CONFERENCE_JOINED,
  4. CONFERENCE_LEFT,
  5. CONFERENCE_WILL_LEAVE,
  6. SET_ROOM
  7. } from './actionTypes';
  8. import { isRoomValid } from './functions';
  9. const INITIAL_STATE = {
  10. jitsiConference: null,
  11. /**
  12. * Instance of JitsiConference that is currently in 'leaving' state.
  13. */
  14. leavingJitsiConference: null,
  15. /**
  16. * The name of the room of the conference (to be) joined (i.e.
  17. * {@link #jitsiConference}).
  18. *
  19. * @type {string}
  20. */
  21. room: null
  22. };
  23. /**
  24. * Listen for actions that contain the conference object, so that it can be
  25. * stored for use by other action creators.
  26. */
  27. ReducerRegistry.register('features/base/conference',
  28. (state = INITIAL_STATE, action) => {
  29. switch (action.type) {
  30. case CONFERENCE_JOINED:
  31. return (
  32. setStateProperty(
  33. state,
  34. 'jitsiConference',
  35. action.conference.jitsiConference));
  36. case CONFERENCE_LEFT:
  37. if (state.jitsiConference === action.conference.jitsiConference) {
  38. return {
  39. ...state,
  40. jitsiConference: null,
  41. leavingJitsiConference: state.leavingJitsiConference
  42. === action.conference.jitsiConference
  43. ? null
  44. : state.leavingJitsiConference
  45. };
  46. }
  47. break;
  48. case CONFERENCE_WILL_LEAVE:
  49. return (
  50. setStateProperty(
  51. state,
  52. 'leavingJitsiConference',
  53. action.conference.jitsiConference));
  54. case SET_ROOM: {
  55. let room = action.room;
  56. // Technically, there're multiple values which don't represent
  57. // valid room names. Practically, each of them is as bad as the rest
  58. // of them because we can't use any of them to join a conference.
  59. isRoomValid(room) || (room = INITIAL_STATE.room);
  60. return setStateProperty(state, 'room', room);
  61. }
  62. }
  63. return state;
  64. });