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

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