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

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