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

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