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.

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