Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

reducer.js 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. return _setRoom(state, action);
  56. }
  57. return state;
  58. });
  59. /**
  60. * Reduces a specific Redux action SET_ROOM of the feature base/conference.
  61. *
  62. * @param {Object} state - The Redux state of the feature base/conference.
  63. * @param {Action} action - The Redux action SET_ROOM to reduce.
  64. * @private
  65. * @returns {Object} The new state of the feature base/conference after the
  66. * reduction of the specified action.
  67. */
  68. function _setRoom(state, action) {
  69. let room = action.room;
  70. if (isRoomValid(room)) {
  71. // XXX Lib-jitsi-meet does not accept uppercase letters.
  72. room = room.toLowerCase();
  73. } else {
  74. // Technically, there are multiple values which don't represent valid
  75. // room names. Practically, each of them is as bad as the rest of them
  76. // because we can't use any of them to join a conference.
  77. room = INITIAL_STATE.room;
  78. }
  79. return setStateProperty(state, 'room', room);
  80. }