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

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