Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

reducer.js 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  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_PASSWORD,
  20. SET_PENDING_SUBJECT_CHANGE,
  21. SET_ROOM,
  22. SET_SIP_GATEWAY_ENABLED,
  23. SET_START_MUTED_POLICY
  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_TIMESTAMP_CHANGED:
  53. return set(state, 'conferenceTimestamp', action.conferenceTimestamp);
  54. case CONFERENCE_LEFT:
  55. case CONFERENCE_WILL_LEAVE:
  56. return _conferenceLeftOrWillLeave(state, action);
  57. case CONFERENCE_WILL_JOIN:
  58. return _conferenceWillJoin(state, action);
  59. case CONNECTION_WILL_CONNECT:
  60. return set(state, 'authRequired', undefined);
  61. case LOCK_STATE_CHANGED:
  62. return _lockStateChanged(state, action);
  63. case P2P_STATUS_CHANGED:
  64. return _p2pStatusChanged(state, action);
  65. case SET_DESKTOP_SHARING_ENABLED:
  66. return _setDesktopSharingEnabled(state, action);
  67. case SET_FOLLOW_ME:
  68. return set(state, 'followMeEnabled', action.enabled);
  69. case SET_LOCATION_URL:
  70. return set(state, 'room', undefined);
  71. case SET_PASSWORD:
  72. return _setPassword(state, action);
  73. case SET_PENDING_SUBJECT_CHANGE:
  74. return set(state, 'pendingSubjectChange', action.subject);
  75. case SET_ROOM:
  76. return _setRoom(state, action);
  77. case SET_SIP_GATEWAY_ENABLED:
  78. return _setSIPGatewayEnabled(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.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_DESKTOP_SHARING_ENABLED of the feature
  300. * base/conference.
  301. *
  302. * @param {Object} state - The Redux state of the feature base/conference.
  303. * @param {Action} action - The Redux action SET_DESKTOP_SHARING_ENABLED to
  304. * reduce.
  305. * @private
  306. * @returns {Object} The new state of the feature base/conference after the
  307. * reduction of the specified action.
  308. */
  309. function _setDesktopSharingEnabled(state, action) {
  310. return set(state, 'desktopSharingEnabled', action.desktopSharingEnabled);
  311. }
  312. /**
  313. * Reduces a specific Redux action SET_PASSWORD of the feature base/conference.
  314. *
  315. * @param {Object} state - The Redux state of the feature base/conference.
  316. * @param {Action} action - The Redux action SET_PASSWORD to reduce.
  317. * @private
  318. * @returns {Object} The new state of the feature base/conference after the
  319. * reduction of the specified action.
  320. */
  321. function _setPassword(state, { conference, method, password }) {
  322. switch (method) {
  323. case conference.join:
  324. return assign(state, {
  325. // 1. The JitsiConference which transitions away from
  326. // passwordRequired MUST remain in the redux state
  327. // features/base/conference until it transitions into
  328. // conference; otherwise, there is a span of time during which
  329. // the redux state does not even know that there is a
  330. // JitsiConference whatsoever.
  331. //
  332. // 2. The redux action setPassword will attempt to join the
  333. // JitsiConference so joining is an appropriate transitional
  334. // redux state.
  335. //
  336. // 3. The redux action setPassword will perform the same check
  337. // before it proceeds with the re-join.
  338. joining: state.conference ? state.joining : conference,
  339. locked: LOCKED_REMOTELY,
  340. /**
  341. * The password with which the conference is to be joined.
  342. *
  343. * @type {string}
  344. */
  345. password
  346. });
  347. case conference.lock:
  348. return assign(state, {
  349. locked: password ? LOCKED_LOCALLY : undefined,
  350. password
  351. });
  352. }
  353. return state;
  354. }
  355. /**
  356. * Reduces a specific Redux action SET_ROOM of the feature base/conference.
  357. *
  358. * @param {Object} state - The Redux state of the feature base/conference.
  359. * @param {Action} action - The Redux action SET_ROOM to reduce.
  360. * @private
  361. * @returns {Object} The new state of the feature base/conference after the
  362. * reduction of the specified action.
  363. */
  364. function _setRoom(state, action) {
  365. let { room } = action;
  366. if (!isRoomValid(room)) {
  367. // Technically, there are multiple values which don't represent valid
  368. // room names. Practically, each of them is as bad as the rest of them
  369. // because we can't use any of them to join a conference.
  370. room = undefined;
  371. }
  372. /**
  373. * The name of the room of the conference (to be) joined.
  374. *
  375. * @type {string}
  376. */
  377. return assign(state, {
  378. error: undefined,
  379. room
  380. });
  381. }
  382. /**
  383. * Reduces a specific Redux action SET_SIP_GATEWAY_ENABLED of the feature
  384. * base/conference.
  385. *
  386. * @param {Object} state - The Redux state of the feature base/conference.
  387. * @param {Action} action - The Redux action SET_SIP_GATEWAY_ENABLED to reduce.
  388. * @private
  389. * @returns {Object} The new state of the feature base/conference after the
  390. * reduction of the specified action.
  391. */
  392. function _setSIPGatewayEnabled(state, action) {
  393. return set(state, 'isSIPGatewayEnabled', action.isSIPGatewayEnabled);
  394. }