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

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