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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. // @flow
  2. import { LOCKED_LOCALLY, LOCKED_REMOTELY } from '../../room-lock';
  3. import { CONNECTION_WILL_CONNECT, SET_LOCATION_URL } from '../connection';
  4. import { JitsiConferenceErrors } from '../lib-jitsi-meet';
  5. import { assign, ReducerRegistry, set } from '../redux';
  6. import {
  7. AUTH_STATUS_CHANGED,
  8. CONFERENCE_FAILED,
  9. CONFERENCE_JOINED,
  10. CONFERENCE_LEFT,
  11. CONFERENCE_SUBJECT_CHANGED,
  12. CONFERENCE_TIMESTAMP_CHANGED,
  13. CONFERENCE_WILL_JOIN,
  14. CONFERENCE_WILL_LEAVE,
  15. LOCK_STATE_CHANGED,
  16. P2P_STATUS_CHANGED,
  17. SET_DESKTOP_SHARING_ENABLED,
  18. SET_FOLLOW_ME,
  19. SET_MAX_RECEIVER_VIDEO_QUALITY,
  20. SET_PASSWORD,
  21. SET_PENDING_SUBJECT_CHANGE,
  22. SET_PREFERRED_VIDEO_QUALITY,
  23. SET_ROOM,
  24. SET_SIP_GATEWAY_ENABLED,
  25. SET_START_MUTED_POLICY
  26. } from './actionTypes';
  27. import { VIDEO_QUALITY_LEVELS } from './constants';
  28. import { isRoomValid } from './functions';
  29. const DEFAULT_STATE = {
  30. conference: undefined,
  31. e2eeSupported: undefined,
  32. joining: undefined,
  33. leaving: undefined,
  34. locked: undefined,
  35. maxReceiverVideoQuality: VIDEO_QUALITY_LEVELS.HIGH,
  36. membersOnly: undefined,
  37. password: undefined,
  38. passwordRequired: undefined,
  39. preferredVideoQuality: VIDEO_QUALITY_LEVELS.HIGH
  40. };
  41. /**
  42. * Listen for actions that contain the conference object, so that it can be
  43. * stored for use by other action creators.
  44. */
  45. ReducerRegistry.register(
  46. 'features/base/conference',
  47. (state = DEFAULT_STATE, action) => {
  48. switch (action.type) {
  49. case AUTH_STATUS_CHANGED:
  50. return _authStatusChanged(state, action);
  51. case CONFERENCE_FAILED:
  52. return _conferenceFailed(state, action);
  53. case CONFERENCE_JOINED:
  54. return _conferenceJoined(state, action);
  55. case CONFERENCE_SUBJECT_CHANGED:
  56. return set(state, 'subject', action.subject);
  57. case CONFERENCE_TIMESTAMP_CHANGED:
  58. return set(state, 'conferenceTimestamp', action.conferenceTimestamp);
  59. case CONFERENCE_LEFT:
  60. case CONFERENCE_WILL_LEAVE:
  61. return _conferenceLeftOrWillLeave(state, action);
  62. case CONFERENCE_WILL_JOIN:
  63. return _conferenceWillJoin(state, action);
  64. case CONNECTION_WILL_CONNECT:
  65. return set(state, 'authRequired', undefined);
  66. case LOCK_STATE_CHANGED:
  67. return _lockStateChanged(state, action);
  68. case P2P_STATUS_CHANGED:
  69. return _p2pStatusChanged(state, action);
  70. case SET_DESKTOP_SHARING_ENABLED:
  71. return _setDesktopSharingEnabled(state, action);
  72. case SET_FOLLOW_ME:
  73. return set(state, 'followMeEnabled', action.enabled);
  74. case SET_LOCATION_URL:
  75. return set(state, 'room', undefined);
  76. case SET_MAX_RECEIVER_VIDEO_QUALITY:
  77. return set(
  78. state,
  79. 'maxReceiverVideoQuality',
  80. action.maxReceiverVideoQuality);
  81. case SET_PASSWORD:
  82. return _setPassword(state, action);
  83. case SET_PENDING_SUBJECT_CHANGE:
  84. return set(state, 'pendingSubjectChange', action.subject);
  85. case SET_PREFERRED_VIDEO_QUALITY:
  86. return set(
  87. state,
  88. 'preferredVideoQuality',
  89. action.preferredVideoQuality);
  90. case SET_ROOM:
  91. return _setRoom(state, action);
  92. case SET_SIP_GATEWAY_ENABLED:
  93. return _setSIPGatewayEnabled(state, action);
  94. case SET_START_MUTED_POLICY:
  95. return {
  96. ...state,
  97. startAudioMutedPolicy: action.startAudioMutedPolicy,
  98. startVideoMutedPolicy: action.startVideoMutedPolicy
  99. };
  100. }
  101. return state;
  102. });
  103. /**
  104. * Reduces a specific Redux action AUTH_STATUS_CHANGED of the feature
  105. * base/conference.
  106. *
  107. * @param {Object} state - The Redux state of the feature base/conference.
  108. * @param {Action} action - The Redux action AUTH_STATUS_CHANGED to reduce.
  109. * @private
  110. * @returns {Object} The new state of the feature base/conference after the
  111. * reduction of the specified action.
  112. */
  113. function _authStatusChanged(state, { authEnabled, authLogin }) {
  114. return assign(state, {
  115. authEnabled,
  116. authLogin
  117. });
  118. }
  119. /**
  120. * Reduces a specific Redux action CONFERENCE_FAILED of the feature
  121. * base/conference.
  122. *
  123. * @param {Object} state - The Redux state of the feature base/conference.
  124. * @param {Action} action - The Redux action CONFERENCE_FAILED to reduce.
  125. * @private
  126. * @returns {Object} The new state of the feature base/conference after the
  127. * reduction of the specified action.
  128. */
  129. function _conferenceFailed(state, { conference, error }) {
  130. // The current (similar to getCurrentConference in
  131. // base/conference/functions.js) conference which is joining or joined:
  132. const conference_ = state.conference || state.joining;
  133. if (conference_ && conference_ !== conference) {
  134. return state;
  135. }
  136. let authRequired;
  137. let membersOnly;
  138. let passwordRequired;
  139. switch (error.name) {
  140. case JitsiConferenceErrors.AUTHENTICATION_REQUIRED:
  141. authRequired = conference;
  142. break;
  143. case JitsiConferenceErrors.CONFERENCE_ACCESS_DENIED:
  144. case JitsiConferenceErrors.MEMBERS_ONLY_ERROR:
  145. membersOnly = conference;
  146. break;
  147. case JitsiConferenceErrors.PASSWORD_REQUIRED:
  148. passwordRequired = conference;
  149. break;
  150. }
  151. return assign(state, {
  152. authRequired,
  153. conference: undefined,
  154. e2eeSupported: undefined,
  155. error,
  156. joining: undefined,
  157. leaving: undefined,
  158. /**
  159. * The indicator of how the conference/room is locked. If falsy, the
  160. * conference/room is unlocked; otherwise, it's either
  161. * {@code LOCKED_LOCALLY} or {@code LOCKED_REMOTELY}.
  162. *
  163. * @type {string}
  164. */
  165. locked: passwordRequired ? LOCKED_REMOTELY : undefined,
  166. membersOnly,
  167. password: undefined,
  168. /**
  169. * The JitsiConference instance which requires a password to join.
  170. *
  171. * @type {JitsiConference}
  172. */
  173. passwordRequired
  174. });
  175. }
  176. /**
  177. * Reduces a specific Redux action CONFERENCE_JOINED of the feature
  178. * base/conference.
  179. *
  180. * @param {Object} state - The Redux state of the feature base/conference.
  181. * @param {Action} action - The Redux action CONFERENCE_JOINED to reduce.
  182. * @private
  183. * @returns {Object} The new state of the feature base/conference after the
  184. * reduction of the specified action.
  185. */
  186. function _conferenceJoined(state, { conference }) {
  187. // FIXME The indicator which determines whether a JitsiConference is locked
  188. // i.e. password-protected is private to lib-jitsi-meet. However, the
  189. // library does not fire LOCK_STATE_CHANGED upon joining a JitsiConference
  190. // with a password.
  191. // FIXME Technically JitsiConference.room is a private field.
  192. const locked = conference.room && conference.room.locked ? LOCKED_REMOTELY : undefined;
  193. return assign(state, {
  194. authRequired: undefined,
  195. /**
  196. * The JitsiConference instance represented by the Redux state of the
  197. * feature base/conference.
  198. *
  199. * @type {JitsiConference}
  200. */
  201. conference,
  202. e2eeSupported: conference.isE2EESupported(),
  203. joining: undefined,
  204. membersOnly: undefined,
  205. leaving: undefined,
  206. /**
  207. * The indicator which determines whether the conference is locked.
  208. *
  209. * @type {boolean}
  210. */
  211. locked,
  212. passwordRequired: undefined
  213. });
  214. }
  215. /**
  216. * Reduces a specific redux action {@link CONFERENCE_LEFT} or
  217. * {@link CONFERENCE_WILL_LEAVE} for the feature base/conference.
  218. *
  219. * @param {Object} state - The redux state of the feature base/conference.
  220. * @param {Action} action - The redux action {@code CONFERENCE_LEFT} or
  221. * {@code CONFERENCE_WILL_LEAVE} to reduce.
  222. * @private
  223. * @returns {Object} The next/new state of the feature base/conference after the
  224. * reduction of the specified action.
  225. */
  226. function _conferenceLeftOrWillLeave(state, { conference, type }) {
  227. const nextState = { ...state };
  228. // The redux action CONFERENCE_LEFT is the last time that we should be
  229. // hearing from a JitsiConference instance.
  230. //
  231. // The redux action CONFERENCE_WILL_LEAVE represents the order of the user
  232. // to leave a JitsiConference instance. From the user's perspective, there's
  233. // no going back (with respect to the instance itself). The app will perform
  234. // due clean-up like leaving the associated room, but the instance is no
  235. // longer the focus of the attention of the user and, consequently, the app.
  236. for (const p in state) {
  237. if (state[p] === conference) {
  238. nextState[p] = undefined;
  239. switch (p) {
  240. case 'conference':
  241. case 'passwordRequired':
  242. // XXX Clear/unset locked & password for a conference which has
  243. // been LOCKED_LOCALLY or LOCKED_REMOTELY.
  244. delete nextState.locked;
  245. delete nextState.password;
  246. break;
  247. }
  248. }
  249. }
  250. if (type === CONFERENCE_WILL_LEAVE) {
  251. // A CONFERENCE_WILL_LEAVE is of further consequence only if it is
  252. // expected i.e. if the specified conference is joining or joined.
  253. if (conference === state.joining || conference === state.conference) {
  254. /**
  255. * The JitsiConference instance which is currently in the process of
  256. * being left.
  257. *
  258. * @type {JitsiConference}
  259. */
  260. nextState.leaving = conference;
  261. }
  262. }
  263. return nextState;
  264. }
  265. /**
  266. * Reduces a specific Redux action CONFERENCE_WILL_JOIN of the feature
  267. * base/conference.
  268. *
  269. * @param {Object} state - The Redux state of the feature base/conference.
  270. * @param {Action} action - The Redux action CONFERENCE_WILL_JOIN to reduce.
  271. * @private
  272. * @returns {Object} The new state of the feature base/conference after the
  273. * reduction of the specified action.
  274. */
  275. function _conferenceWillJoin(state, { conference }) {
  276. return assign(state, {
  277. error: undefined,
  278. joining: conference
  279. });
  280. }
  281. /**
  282. * Reduces a specific Redux action LOCK_STATE_CHANGED of the feature
  283. * base/conference.
  284. *
  285. * @param {Object} state - The Redux state of the feature base/conference.
  286. * @param {Action} action - The Redux action LOCK_STATE_CHANGED to reduce.
  287. * @private
  288. * @returns {Object} The new state of the feature base/conference after the
  289. * reduction of the specified action.
  290. */
  291. function _lockStateChanged(state, { conference, locked }) {
  292. if (state.conference !== conference) {
  293. return state;
  294. }
  295. return assign(state, {
  296. locked: locked ? state.locked || LOCKED_REMOTELY : undefined,
  297. password: locked ? state.password : undefined
  298. });
  299. }
  300. /**
  301. * Reduces a specific Redux action P2P_STATUS_CHANGED of the feature
  302. * base/conference.
  303. *
  304. * @param {Object} state - The Redux state of the feature base/conference.
  305. * @param {Action} action - The Redux action P2P_STATUS_CHANGED to reduce.
  306. * @private
  307. * @returns {Object} The new state of the feature base/conference after the
  308. * reduction of the specified action.
  309. */
  310. function _p2pStatusChanged(state, action) {
  311. return set(state, 'p2p', action.p2p);
  312. }
  313. /**
  314. * Reduces a specific Redux action SET_DESKTOP_SHARING_ENABLED of the feature
  315. * base/conference.
  316. *
  317. * @param {Object} state - The Redux state of the feature base/conference.
  318. * @param {Action} action - The Redux action SET_DESKTOP_SHARING_ENABLED to
  319. * reduce.
  320. * @private
  321. * @returns {Object} The new state of the feature base/conference after the
  322. * reduction of the specified action.
  323. */
  324. function _setDesktopSharingEnabled(state, action) {
  325. return set(state, 'desktopSharingEnabled', action.desktopSharingEnabled);
  326. }
  327. /**
  328. * Reduces a specific Redux action SET_PASSWORD of the feature base/conference.
  329. *
  330. * @param {Object} state - The Redux state of the feature base/conference.
  331. * @param {Action} action - The Redux action SET_PASSWORD to reduce.
  332. * @private
  333. * @returns {Object} The new state of the feature base/conference after the
  334. * reduction of the specified action.
  335. */
  336. function _setPassword(state, { conference, method, password }) {
  337. switch (method) {
  338. case conference.join:
  339. return assign(state, {
  340. // 1. The JitsiConference which transitions away from
  341. // passwordRequired MUST remain in the redux state
  342. // features/base/conference until it transitions into
  343. // conference; otherwise, there is a span of time during which
  344. // the redux state does not even know that there is a
  345. // JitsiConference whatsoever.
  346. //
  347. // 2. The redux action setPassword will attempt to join the
  348. // JitsiConference so joining is an appropriate transitional
  349. // redux state.
  350. //
  351. // 3. The redux action setPassword will perform the same check
  352. // before it proceeds with the re-join.
  353. joining: state.conference ? state.joining : conference,
  354. locked: LOCKED_REMOTELY,
  355. /**
  356. * The password with which the conference is to be joined.
  357. *
  358. * @type {string}
  359. */
  360. password
  361. });
  362. case conference.lock:
  363. return assign(state, {
  364. locked: password ? LOCKED_LOCALLY : undefined,
  365. password
  366. });
  367. }
  368. return state;
  369. }
  370. /**
  371. * Reduces a specific Redux action SET_ROOM of the feature base/conference.
  372. *
  373. * @param {Object} state - The Redux state of the feature base/conference.
  374. * @param {Action} action - The Redux action SET_ROOM to reduce.
  375. * @private
  376. * @returns {Object} The new state of the feature base/conference after the
  377. * reduction of the specified action.
  378. */
  379. function _setRoom(state, action) {
  380. let { room } = action;
  381. if (!isRoomValid(room)) {
  382. // Technically, there are multiple values which don't represent valid
  383. // room names. Practically, each of them is as bad as the rest of them
  384. // because we can't use any of them to join a conference.
  385. room = undefined;
  386. }
  387. /**
  388. * The name of the room of the conference (to be) joined.
  389. *
  390. * @type {string}
  391. */
  392. return assign(state, {
  393. error: undefined,
  394. room
  395. });
  396. }
  397. /**
  398. * Reduces a specific Redux action SET_SIP_GATEWAY_ENABLED of the feature
  399. * base/conference.
  400. *
  401. * @param {Object} state - The Redux state of the feature base/conference.
  402. * @param {Action} action - The Redux action SET_SIP_GATEWAY_ENABLED to reduce.
  403. * @private
  404. * @returns {Object} The new state of the feature base/conference after the
  405. * reduction of the specified action.
  406. */
  407. function _setSIPGatewayEnabled(state, action) {
  408. return set(state, 'isSIPGatewayEnabled', action.isSIPGatewayEnabled);
  409. }