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

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