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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. import JitsiMeetJS from '../lib-jitsi-meet';
  2. import {
  3. ReducerRegistry,
  4. setStateProperties,
  5. setStateProperty
  6. } from '../redux';
  7. import {
  8. CONFERENCE_FAILED,
  9. CONFERENCE_JOINED,
  10. CONFERENCE_LEFT,
  11. CONFERENCE_WILL_LEAVE,
  12. SET_PASSWORD,
  13. SET_ROOM
  14. } from './actionTypes';
  15. import { isRoomValid } from './functions';
  16. /**
  17. * Listen for actions that contain the conference object, so that it can be
  18. * stored for use by other action creators.
  19. */
  20. ReducerRegistry.register('features/base/conference', (state = {}, action) => {
  21. switch (action.type) {
  22. case CONFERENCE_FAILED:
  23. return _conferenceFailed(state, action);
  24. case CONFERENCE_JOINED:
  25. return _conferenceJoined(state, action);
  26. case CONFERENCE_LEFT:
  27. return _conferenceLeft(state, action);
  28. case CONFERENCE_WILL_LEAVE:
  29. return _conferenceWillLeave(state, action);
  30. case SET_PASSWORD:
  31. return _setPassword(state, action);
  32. case SET_ROOM:
  33. return _setRoom(state, action);
  34. }
  35. return state;
  36. });
  37. /**
  38. * Reduces a specific Redux action CONFERENCE_FAILED of the feature
  39. * base/conference.
  40. *
  41. * @param {Object} state - The Redux state of the feature base/conference.
  42. * @param {Action} action - The Redux action CONFERENCE_FAILED to reduce.
  43. * @private
  44. * @returns {Object} The new state of the feature base/conference after the
  45. * reduction of the specified action.
  46. */
  47. function _conferenceFailed(state, action) {
  48. const conference = action.conference;
  49. if (state.conference && state.conference !== conference) {
  50. return state;
  51. }
  52. const JitsiConferenceErrors = JitsiMeetJS.errors.conference;
  53. const passwordRequired
  54. = JitsiConferenceErrors.PASSWORD_REQUIRED === action.error
  55. ? conference
  56. : undefined;
  57. return (
  58. setStateProperties(state, {
  59. conference: undefined,
  60. leaving: undefined,
  61. password: undefined,
  62. /**
  63. * The JitsiConference instance which requires a password to join.
  64. *
  65. * @type {JitsiConference}
  66. */
  67. passwordRequired
  68. }));
  69. }
  70. /**
  71. * Reduces a specific Redux action CONFERENCE_JOINED of the feature
  72. * base/conference.
  73. *
  74. * @param {Object} state - The Redux state of the feature base/conference.
  75. * @param {Action} action - The Redux action CONFERENCE_JOINED to reduce.
  76. * @private
  77. * @returns {Object} The new state of the feature base/conference after the
  78. * reduction of the specified action.
  79. */
  80. function _conferenceJoined(state, action) {
  81. return (
  82. setStateProperties(state, {
  83. /**
  84. * The JitsiConference instance represented by the Redux state of
  85. * the feature base/conference.
  86. *
  87. * @type {JitsiConference}
  88. */
  89. conference: action.conference,
  90. leaving: undefined,
  91. passwordRequired: undefined
  92. }));
  93. }
  94. /**
  95. * Reduces a specific Redux action CONFERENCE_LEFT of the feature
  96. * base/conference.
  97. *
  98. * @param {Object} state - The Redux state of the feature base/conference.
  99. * @param {Action} action - The Redux action CONFERENCE_LEFT to reduce.
  100. * @private
  101. * @returns {Object} The new state of the feature base/conference after the
  102. * reduction of the specified action.
  103. */
  104. function _conferenceLeft(state, action) {
  105. const conference = action.conference;
  106. if (state.conference !== conference) {
  107. return state;
  108. }
  109. return (
  110. setStateProperties(state, {
  111. conference: undefined,
  112. leaving: undefined,
  113. password: undefined,
  114. passwordRequired: undefined
  115. }));
  116. }
  117. /**
  118. * Reduces a specific Redux action CONFERENCE_WILL_LEAVE of the feature
  119. * base/conference.
  120. *
  121. * @param {Object} state - The Redux state of the feature base/conference.
  122. * @param {Action} action - The Redux action CONFERENCE_WILL_LEAVE to reduce.
  123. * @private
  124. * @returns {Object} The new state of the feature base/conference after the
  125. * reduction of the specified action.
  126. */
  127. function _conferenceWillLeave(state, action) {
  128. const conference = action.conference;
  129. if (state.conference !== conference) {
  130. return state;
  131. }
  132. return (
  133. setStateProperties(state, {
  134. /**
  135. * The JitsiConference instance which is currently in the process of
  136. * being left.
  137. *
  138. * @type {JitsiConference}
  139. */
  140. leaving: conference,
  141. passwordRequired: undefined
  142. }));
  143. }
  144. /**
  145. * Reduces a specific Redux action SET_PASSWORD of the feature base/conference.
  146. *
  147. * @param {Object} state - The Redux state of the feature base/conference.
  148. * @param {Action} action - The Redux action SET_PASSWORD to reduce.
  149. * @private
  150. * @returns {Object} The new state of the feature base/conference after the
  151. * reduction of the specified action.
  152. */
  153. function _setPassword(state, action) {
  154. const conference = action.conference;
  155. switch (action.method) {
  156. case conference.join:
  157. if (state.passwordRequired === conference) {
  158. return (
  159. setStateProperties(state, {
  160. /**
  161. * The password with which the conference is to be joined.
  162. *
  163. * @type {string}
  164. */
  165. password: action.password,
  166. passwordRequired: undefined
  167. }));
  168. }
  169. break;
  170. }
  171. return state;
  172. }
  173. /**
  174. * Reduces a specific Redux action SET_ROOM of the feature base/conference.
  175. *
  176. * @param {Object} state - The Redux state of the feature base/conference.
  177. * @param {Action} action - The Redux action SET_ROOM to reduce.
  178. * @private
  179. * @returns {Object} The new state of the feature base/conference after the
  180. * reduction of the specified action.
  181. */
  182. function _setRoom(state, action) {
  183. let room = action.room;
  184. if (isRoomValid(room)) {
  185. // XXX Lib-jitsi-meet does not accept uppercase letters.
  186. room = room.toLowerCase();
  187. } else {
  188. // Technically, there are multiple values which don't represent valid
  189. // room names. Practically, each of them is as bad as the rest of them
  190. // because we can't use any of them to join a conference.
  191. room = undefined;
  192. }
  193. /**
  194. * The name of the room of the conference (to be) joined.
  195. *
  196. * @type {string}
  197. */
  198. return setStateProperty(state, 'room', room);
  199. }