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

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