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 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import JitsiMeetJS from '../lib-jitsi-meet';
  2. import {
  3. ReducerRegistry,
  4. setStateProperties,
  5. setStateProperty
  6. } from '../redux';
  7. import {
  8. CONFERENCE_JOINED,
  9. CONFERENCE_LEFT,
  10. CONFERENCE_WILL_LEAVE,
  11. SET_ROOM
  12. } from './actionTypes';
  13. import { isRoomValid } from './functions';
  14. /**
  15. * Listen for actions that contain the conference object, so that it can be
  16. * stored for use by other action creators.
  17. */
  18. ReducerRegistry.register('features/base/conference', (state = {}, action) => {
  19. switch (action.type) {
  20. case CONFERENCE_JOINED:
  21. return _conferenceJoined(state, action);
  22. case CONFERENCE_LEFT:
  23. return _conferenceLeft(state, action);
  24. case CONFERENCE_WILL_LEAVE:
  25. return _conferenceWillLeave(state, action);
  26. case SET_ROOM:
  27. return _setRoom(state, action);
  28. }
  29. return state;
  30. });
  31. /**
  32. * Reduces a specific Redux action CONFERENCE_JOINED of the feature
  33. * base/conference.
  34. *
  35. * @param {Object} state - The Redux state of the feature base/conference.
  36. * @param {Action} action - The Redux action CONFERENCE_JOINED to reduce.
  37. * @private
  38. * @returns {Object} The new state of the feature base/conference after the
  39. * reduction of the specified action.
  40. */
  41. function _conferenceJoined(state, action) {
  42. return (
  43. setStateProperties(state, {
  44. /**
  45. * The JitsiConference instance represented by the Redux state of
  46. * the feature base/conference.
  47. *
  48. * @type {JitsiConference}
  49. */
  50. conference: action.conference,
  51. leaving: undefined
  52. }));
  53. }
  54. /**
  55. * Reduces a specific Redux action CONFERENCE_LEFT of the feature
  56. * base/conference.
  57. *
  58. * @param {Object} state - The Redux state of the feature base/conference.
  59. * @param {Action} action - The Redux action CONFERENCE_LEFT to reduce.
  60. * @private
  61. * @returns {Object} The new state of the feature base/conference after the
  62. * reduction of the specified action.
  63. */
  64. function _conferenceLeft(state, action) {
  65. const conference = action.conference;
  66. if (state.conference !== conference) {
  67. return state;
  68. }
  69. return (
  70. setStateProperties(state, {
  71. conference: undefined,
  72. leaving: undefined
  73. }));
  74. }
  75. /**
  76. * Reduces a specific Redux action CONFERENCE_WILL_LEAVE of the feature
  77. * base/conference.
  78. *
  79. * @param {Object} state - The Redux state of the feature base/conference.
  80. * @param {Action} action - The Redux action CONFERENCE_WILL_LEAVE to reduce.
  81. * @private
  82. * @returns {Object} The new state of the feature base/conference after the
  83. * reduction of the specified action.
  84. */
  85. function _conferenceWillLeave(state, action) {
  86. const conference = action.conference;
  87. if (state.conference !== conference) {
  88. return state;
  89. }
  90. return (
  91. setStateProperties(state, {
  92. /**
  93. * The JitsiConference instance which is currently in the process of
  94. * being left.
  95. *
  96. * @type {JitsiConference}
  97. */
  98. leaving: conference
  99. }));
  100. }
  101. /**
  102. * Reduces a specific Redux action SET_ROOM of the feature base/conference.
  103. *
  104. * @param {Object} state - The Redux state of the feature base/conference.
  105. * @param {Action} action - The Redux action SET_ROOM to reduce.
  106. * @private
  107. * @returns {Object} The new state of the feature base/conference after the
  108. * reduction of the specified action.
  109. */
  110. function _setRoom(state, action) {
  111. let room = action.room;
  112. if (isRoomValid(room)) {
  113. // XXX Lib-jitsi-meet does not accept uppercase letters.
  114. room = room.toLowerCase();
  115. } else {
  116. // Technically, there are multiple values which don't represent valid
  117. // room names. Practically, each of them is as bad as the rest of them
  118. // because we can't use any of them to join a conference.
  119. room = undefined;
  120. }
  121. /**
  122. * The name of the room of the conference (to be) joined.
  123. *
  124. * @type {string}
  125. */
  126. return setStateProperty(state, 'room', room);
  127. }