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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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. /**
  73. * The indicator of how the conference/room is locked. If falsy, the
  74. * conference/room is unlocked; otherwise, it's either
  75. * {@code LOCKED_LOCALLY| or {@code LOCKED_REMOTELY}.
  76. *
  77. * @type {string}
  78. */
  79. locked: passwordRequired ? LOCKED_REMOTELY : undefined,
  80. password: undefined,
  81. /**
  82. * The JitsiConference instance which requires a password to join.
  83. *
  84. * @type {JitsiConference}
  85. */
  86. passwordRequired
  87. }));
  88. }
  89. /**
  90. * Reduces a specific Redux action CONFERENCE_JOINED of the feature
  91. * base/conference.
  92. *
  93. * @param {Object} state - The Redux state of the feature base/conference.
  94. * @param {Action} action - The Redux action CONFERENCE_JOINED to reduce.
  95. * @private
  96. * @returns {Object} The new state of the feature base/conference after the
  97. * reduction of the specified action.
  98. */
  99. function _conferenceJoined(state, action) {
  100. const conference = action.conference;
  101. // FIXME The indicator which determines whether a JitsiConference is locked
  102. // i.e. password-protected is private to lib-jitsi-meet. However, the
  103. // library does not fire LOCK_STATE_CHANGED upon joining a JitsiConference
  104. // with a password.
  105. const locked = conference.room.locked ? LOCKED_REMOTELY : undefined;
  106. return (
  107. setStateProperties(state, {
  108. /**
  109. * The JitsiConference instance represented by the Redux state of
  110. * the feature base/conference.
  111. *
  112. * @type {JitsiConference}
  113. */
  114. conference,
  115. leaving: undefined,
  116. /**
  117. * The indicator which determines whether the conference is locked.
  118. *
  119. * @type {boolean}
  120. */
  121. locked,
  122. passwordRequired: undefined
  123. }));
  124. }
  125. /**
  126. * Reduces a specific Redux action CONFERENCE_LEFT of the feature
  127. * base/conference.
  128. *
  129. * @param {Object} state - The Redux state of the feature base/conference.
  130. * @param {Action} action - The Redux action CONFERENCE_LEFT to reduce.
  131. * @private
  132. * @returns {Object} The new state of the feature base/conference after the
  133. * reduction of the specified action.
  134. */
  135. function _conferenceLeft(state, action) {
  136. const conference = action.conference;
  137. if (state.conference !== conference) {
  138. return state;
  139. }
  140. return (
  141. setStateProperties(state, {
  142. audioOnly: undefined,
  143. audioOnlyVideoMuted: undefined,
  144. conference: undefined,
  145. leaving: undefined,
  146. locked: undefined,
  147. password: undefined,
  148. passwordRequired: undefined
  149. }));
  150. }
  151. /**
  152. * Reduces a specific Redux action CONFERENCE_WILL_LEAVE of the feature
  153. * base/conference.
  154. *
  155. * @param {Object} state - The Redux state of the feature base/conference.
  156. * @param {Action} action - The Redux action CONFERENCE_WILL_LEAVE to reduce.
  157. * @private
  158. * @returns {Object} The new state of the feature base/conference after the
  159. * reduction of the specified action.
  160. */
  161. function _conferenceWillLeave(state, action) {
  162. const conference = action.conference;
  163. if (state.conference !== conference) {
  164. return state;
  165. }
  166. return (
  167. setStateProperties(state, {
  168. /**
  169. * The JitsiConference instance which is currently in the process of
  170. * being left.
  171. *
  172. * @type {JitsiConference}
  173. */
  174. leaving: conference,
  175. passwordRequired: undefined
  176. }));
  177. }
  178. /**
  179. * Reduces a specific Redux action LOCK_STATE_CHANGED of the feature
  180. * base/conference.
  181. *
  182. * @param {Object} state - The Redux state of the feature base/conference.
  183. * @param {Action} action - The Redux action LOCK_STATE_CHANGED to reduce.
  184. * @private
  185. * @returns {Object} The new state of the feature base/conference after the
  186. * reduction of the specified action.
  187. */
  188. function _lockStateChanged(state, action) {
  189. if (state.conference !== action.conference) {
  190. return state;
  191. }
  192. let locked;
  193. if (action.locked) {
  194. locked = state.locked || LOCKED_REMOTELY;
  195. }
  196. return setStateProperties(state, {
  197. locked,
  198. password: action.locked ? state.password : null
  199. });
  200. }
  201. /**
  202. * Reduces a specific Redux action SET_AUDIO_ONLY of the feature
  203. * base/conference.
  204. *
  205. * @param {Object} state - The Redux state of the feature base/conference.
  206. * @param {Action} action - The Redux action SET_AUDIO_ONLY to reduce.
  207. * @private
  208. * @returns {Object} The new state of the feature base/conference after the
  209. * reduction of the specified action.
  210. */
  211. function _setAudioOnly(state, action) {
  212. return setStateProperty(state, 'audioOnly', action.audioOnly);
  213. }
  214. /**
  215. * Reduces a specific Redux action _SET_AUDIO_ONLY_VIDEO_MUTED of the feature
  216. * base/conference.
  217. *
  218. * @param {Object} state - The Redux state of the feature base/conference.
  219. * @param {Action} action - The Redux action SET_AUDIO_ONLY_VIDEO_MUTED to
  220. * reduce.
  221. * @private
  222. * @returns {Object} The new state of the feature base/conference after the
  223. * reduction of the specified action.
  224. */
  225. function _setAudioOnlyVideoMuted(state, action) {
  226. return setStateProperty(state, 'audioOnlyVideoMuted', action.muted);
  227. }
  228. /**
  229. * Reduces a specific Redux action SET_PASSWORD of the feature base/conference.
  230. *
  231. * @param {Object} state - The Redux state of the feature base/conference.
  232. * @param {Action} action - The Redux action SET_PASSWORD to reduce.
  233. * @private
  234. * @returns {Object} The new state of the feature base/conference after the
  235. * reduction of the specified action.
  236. */
  237. function _setPassword(state, action) {
  238. const conference = action.conference;
  239. switch (action.method) {
  240. case conference.join:
  241. if (state.passwordRequired === conference) {
  242. return (
  243. setStateProperties(state, {
  244. locked: LOCKED_REMOTELY,
  245. /**
  246. * The password with which the conference is to be joined.
  247. *
  248. * @type {string}
  249. */
  250. password: action.password,
  251. passwordRequired: undefined
  252. }));
  253. }
  254. break;
  255. case conference.lock:
  256. return setStateProperties(state, {
  257. locked: action.password ? LOCKED_LOCALLY : undefined,
  258. password: action.password
  259. });
  260. }
  261. return state;
  262. }
  263. /**
  264. * Reduces a specific Redux action SET_ROOM of the feature base/conference.
  265. *
  266. * @param {Object} state - The Redux state of the feature base/conference.
  267. * @param {Action} action - The Redux action SET_ROOM to reduce.
  268. * @private
  269. * @returns {Object} The new state of the feature base/conference after the
  270. * reduction of the specified action.
  271. */
  272. function _setRoom(state, action) {
  273. let room = action.room;
  274. if (!isRoomValid(room)) {
  275. // Technically, there are multiple values which don't represent valid
  276. // room names. Practically, each of them is as bad as the rest of them
  277. // because we can't use any of them to join a conference.
  278. room = undefined;
  279. }
  280. /**
  281. * The name of the room of the conference (to be) joined.
  282. *
  283. * @type {string}
  284. */
  285. return setStateProperty(state, 'room', room);
  286. }