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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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_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_JOIN:
  30. return _conferenceWillJoin(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_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, { conference, error }) {
  57. if (state.conference && state.conference !== conference) {
  58. return state;
  59. }
  60. const passwordRequired
  61. = JitsiConferenceErrors.PASSWORD_REQUIRED === error
  62. ? conference
  63. : undefined;
  64. return assign(state, {
  65. conference: undefined,
  66. joining: undefined,
  67. leaving: undefined,
  68. /**
  69. * The indicator of how the conference/room is locked. If falsy, the
  70. * conference/room is unlocked; otherwise, it's either
  71. * {@code LOCKED_LOCALLY} or {@code LOCKED_REMOTELY}.
  72. *
  73. * @type {string}
  74. */
  75. locked: passwordRequired ? LOCKED_REMOTELY : undefined,
  76. password: undefined,
  77. /**
  78. * The JitsiConference instance which requires a password to join.
  79. *
  80. * @type {JitsiConference}
  81. */
  82. passwordRequired
  83. });
  84. }
  85. /**
  86. * Reduces a specific Redux action CONFERENCE_JOINED of the feature
  87. * base/conference.
  88. *
  89. * @param {Object} state - The Redux state of the feature base/conference.
  90. * @param {Action} action - The Redux action CONFERENCE_JOINED to reduce.
  91. * @private
  92. * @returns {Object} The new state of the feature base/conference after the
  93. * reduction of the specified action.
  94. */
  95. function _conferenceJoined(state, { conference }) {
  96. // FIXME The indicator which determines whether a JitsiConference is locked
  97. // i.e. password-protected is private to lib-jitsi-meet. However, the
  98. // library does not fire LOCK_STATE_CHANGED upon joining a JitsiConference
  99. // with a password.
  100. const locked = conference.room.locked ? LOCKED_REMOTELY : undefined;
  101. return assign(state, {
  102. /**
  103. * The JitsiConference instance represented by the Redux state of the
  104. * feature base/conference.
  105. *
  106. * @type {JitsiConference}
  107. */
  108. conference,
  109. joining: undefined,
  110. leaving: undefined,
  111. /**
  112. * The indicator which determines whether the conference is locked.
  113. *
  114. * @type {boolean}
  115. */
  116. locked,
  117. passwordRequired: undefined
  118. });
  119. }
  120. /**
  121. * Reduces a specific Redux action CONFERENCE_LEFT of the feature
  122. * base/conference.
  123. *
  124. * @param {Object} state - The Redux state of the feature base/conference.
  125. * @param {Action} action - The Redux action CONFERENCE_LEFT to reduce.
  126. * @private
  127. * @returns {Object} The new state of the feature base/conference after the
  128. * reduction of the specified action.
  129. */
  130. function _conferenceLeft(state, { conference }) {
  131. if (state.conference !== conference) {
  132. return state;
  133. }
  134. return assign(state, {
  135. conference: undefined,
  136. joining: undefined,
  137. leaving: undefined,
  138. locked: undefined,
  139. password: undefined,
  140. passwordRequired: undefined
  141. });
  142. }
  143. /**
  144. * Reduces a specific Redux action CONFERENCE_WILL_JOIN 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_JOIN 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 _conferenceWillJoin(state, { conference }) {
  154. return set(state, 'joining', conference);
  155. }
  156. /**
  157. * Reduces a specific Redux action CONFERENCE_WILL_LEAVE 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_LEAVE 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 _conferenceWillLeave(state, { conference }) {
  167. if (state.conference !== conference) {
  168. return state;
  169. }
  170. return assign(state, {
  171. joining: undefined,
  172. /**
  173. * The JitsiConference instance which is currently in the process of
  174. * being left.
  175. *
  176. * @type {JitsiConference}
  177. */
  178. leaving: conference,
  179. passwordRequired: undefined
  180. });
  181. }
  182. /**
  183. * Reduces a specific Redux action LOCK_STATE_CHANGED of the feature
  184. * base/conference.
  185. *
  186. * @param {Object} state - The Redux state of the feature base/conference.
  187. * @param {Action} action - The Redux action LOCK_STATE_CHANGED to reduce.
  188. * @private
  189. * @returns {Object} The new state of the feature base/conference after the
  190. * reduction of the specified action.
  191. */
  192. function _lockStateChanged(state, { conference, locked }) {
  193. if (state.conference !== conference) {
  194. return state;
  195. }
  196. return assign(state, {
  197. locked: locked ? state.locked || LOCKED_REMOTELY : undefined,
  198. password: locked ? state.password : undefined
  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 set(state, 'audioOnly', action.audioOnly);
  213. }
  214. /**
  215. * Reduces a specific Redux action SET_LARGE_VIDEO_HD_STATUS 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_LARGE_VIDEO_HD_STATUS 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 _setLargeVideoHDStatus(state, action) {
  226. return set(state, 'isLargeVideoHD', action.isLargeVideoHD);
  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, { conference, method, password }) {
  238. switch (method) {
  239. case conference.join:
  240. if (state.passwordRequired === conference) {
  241. return assign(state, {
  242. locked: LOCKED_REMOTELY,
  243. /**
  244. * The password with which the conference is to be joined.
  245. *
  246. * @type {string}
  247. */
  248. password,
  249. passwordRequired: undefined
  250. });
  251. }
  252. break;
  253. case conference.lock:
  254. return assign(state, {
  255. locked: password ? LOCKED_LOCALLY : undefined,
  256. password
  257. });
  258. }
  259. return state;
  260. }
  261. /**
  262. * Reduces a specific Redux action SET_ROOM of the feature base/conference.
  263. *
  264. * @param {Object} state - The Redux state of the feature base/conference.
  265. * @param {Action} action - The Redux action SET_ROOM to reduce.
  266. * @private
  267. * @returns {Object} The new state of the feature base/conference after the
  268. * reduction of the specified action.
  269. */
  270. function _setRoom(state, action) {
  271. let room = action.room;
  272. if (!isRoomValid(room)) {
  273. // Technically, there are multiple values which don't represent valid
  274. // room names. Practically, each of them is as bad as the rest of them
  275. // because we can't use any of them to join a conference.
  276. room = undefined;
  277. }
  278. /**
  279. * The name of the room of the conference (to be) joined.
  280. *
  281. * @type {string}
  282. */
  283. return set(state, 'room', room);
  284. }